home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / CodeGen / ExtensionParser.php < prev    next >
Encoding:
PHP Script  |  2006-04-07  |  8.1 KB  |  312 lines

  1. <?php
  2. /**
  3.  * Parser for XML based extension desription files
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   Tools and Utilities
  14.  * @package    CodeGen
  15.  * @author     Hartmut Holzgraefe <hartmut@php.net>
  16.  * @copyright  2005 Hartmut Holzgraefe
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: ExtensionParser.php,v 1.10 2006/02/02 22:14:57 hholzgra Exp $
  19.  * @link       http://pear.php.net/package/CodeGen
  20.  */
  21.  
  22.  
  23. /**
  24.  * includes
  25.  */
  26. require_once "CodeGen/XmlParser.php";
  27. require_once "CodeGen/Tools/Indent.php";
  28.  
  29. /**
  30.  * Parser for XML based extension desription files
  31.  *
  32.  * @category   Tools and Utilities
  33.  * @package    CodeGen
  34.  * @author     Hartmut Holzgraefe <hartmut@php.net>
  35.  * @copyright  2005 Hartmut Holzgraefe
  36.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  37.  * @version    Release: @package_version@
  38.  * @link       http://pear.php.net/package/CodeGen
  39.  */
  40. abstract class CodeGen_ExtensionParser 
  41.     extends CodeGen_XmlParser
  42. {
  43.     /**
  44.      * The extension to parse specs into
  45.      *
  46.      * @access private
  47.      * @var    object
  48.      */
  49.     protected $extension;
  50.     
  51.     /** 
  52.      * Constructor
  53.      *
  54.      * @access public
  55.      * @param  object the extension to parse specs into
  56.      */
  57.     function __construct($extension) 
  58.     {
  59.         parent::__construct();
  60.         $this->extension = $extension;
  61.     }
  62.     
  63.     /**
  64.      * Handle <extension>
  65.      *
  66.      * @access private
  67.      * @param  array    attribute/value pairs
  68.      * @return bool     success status
  69.      */
  70.     function tagstart_extension($attr)
  71.     {
  72.         $err = $this->checkAttributes($attr, array("name", "prefix", "version"));
  73.         if (PEAR::isError($err)) {
  74.             return $err;
  75.         }
  76.                                       
  77.         if (!isset($attr["name"])) {
  78.             return PEAR::raiseError("needed attribute 'name' for <extension> not given");
  79.         }
  80.         $err = $this->extension->setName(trim($attr["name"]));
  81.         if (PEAR::isError($err)) {
  82.             return $err;
  83.         }
  84.  
  85.         if (isset($attr["prefix"])) {
  86.             $err = $this->extension->setPrefix(trim($attr["prefix"]));
  87.             if (PEAR::isError($err)) {
  88.                 return $err;
  89.             }
  90.         }
  91.  
  92.         if (isset($attr["version"])) {
  93.             $err = $this->extension->setVersion($attr["version"]);
  94.             if (PEAR::isError($err)) {
  95.                 return $err;
  96.             }
  97.         } else {
  98.             error_log("Warning: no 'version' attribute given for <extension>, assuming ".$this->extension->version()."\n".
  99.                       "         this may lead to compile errors if your spec file was created for an older version");
  100.         }
  101.  
  102.         return true;
  103.     }
  104.     
  105.     /**
  106.      * Handle <extension><name>
  107.      *
  108.      * @access private
  109.      * @param  array    attribute/value pairs
  110.      * @return bool     success status
  111.      */
  112.     function tagstart_extension_name($attr)
  113.     {
  114.         return PEAR::raiseError("extension <name> tag is no longer supported, use <extension>s 'name=...' attribute instead");
  115.     }
  116.     
  117.     
  118.     /**
  119.      * Handle <extension></summary>
  120.      *
  121.      * @access private
  122.      * @param  array    attribute/value pairs
  123.      * @param  array    tag data content
  124.      * @return bool     success status
  125.      */
  126.     function tagend_extension_summary($attr, $data)
  127.     {
  128.         return $this->extension->setSummary(CodeGen_Tools_Indent::linetrim($data));
  129.     }
  130.     
  131.     /**
  132.      * Handle <extension></description>
  133.      *
  134.      * @access private
  135.      * @param  array    attribute/value pairs
  136.      * @param  array    tag data content
  137.      * @return bool     success status
  138.      */
  139.     function tagend_extension_description($attr, $data)
  140.     {
  141.         return $this->extension->setDescription(CodeGen_Tools_Indent::linetrim($data));
  142.     }
  143.  
  144.         
  145.  
  146.  
  147.     
  148.     function tagstart_maintainer($attr)
  149.     {
  150.         $this->pushHelper(new CodeGen_Maintainer);
  151.         return true;
  152.     }
  153.     
  154.     function tagend_maintainer_user($attr, $data)
  155.     {
  156.         return $this->helper->setUser(trim($data));
  157.     }
  158.     
  159.     function tagend_maintainer_name($attr, $data)
  160.     {
  161.         return $this->helper->setName(trim($data));
  162.     }
  163.  
  164.     function tagend_maintainer_email($attr, $data)
  165.     {
  166.         return $this->helper->setEmail(trim($data));
  167.     }
  168.  
  169.     function tagend_maintainer_role($attr, $data)
  170.     {
  171.         return $this->helper->setRole(trim($data));
  172.     }
  173.  
  174.     function tagend_maintainer($attr, $data)
  175.     {
  176.         $err = $this->extension->addAuthor($this->helper);
  177.         $this->popHelper();
  178.         return $err;
  179.     }
  180.  
  181.     function tagend_maintainers($attr, $data) 
  182.     {
  183.         return true;
  184.     }
  185.  
  186.     function tagstart_extension_release($attr)
  187.     {
  188.         $this->pushHelper(new CodeGen_Release);
  189.         return true;
  190.     }
  191.  
  192.     function tagend_release_version($attr, $data)
  193.     {
  194.         return $this->helper->setVersion(trim($data));
  195.     }
  196.  
  197.     function tagend_release_date($attr, $data)
  198.     {
  199.         return $this->helper->setDate(trim($data));
  200.     }
  201.  
  202.     function tagend_release_state($attr, $data)
  203.     {
  204.         return $this->helper->setState(trim($data));
  205.     }
  206.  
  207.     function tagend_release_notes($attr, $data)
  208.     {
  209.         return $this->helper->setNotes(CodeGen_Tools_Indent::linetrim($data));
  210.     }
  211.  
  212.     function tagend_extension_release($attr, $data)
  213.     {
  214.         $err = $this->extension->setRelease($this->helper);
  215.         $this->popHelper(new CodeGen_Release);
  216.         return $err;
  217.     }
  218.  
  219.     function tagstart_extension_changelog($attr, $data) 
  220.     {
  221.         $this->verbatim();
  222.     }
  223.  
  224.     function tagend_extension_changelog($attr, $data) 
  225.     {
  226.         return $this->extension->setChangelog(CodeGen_Tools_Indent::linetrim($data));
  227.     }
  228.  
  229.         
  230.     function tagend_license($attr, $data)
  231.     {
  232.         $license = CodeGen_License::factory(trim($data));
  233.         
  234.         if (PEAR::isError($license)) {
  235.             return $err;
  236.         }
  237.         
  238.         return $this->extension->setLicense($license);
  239.     }
  240.  
  241.     function tagend_extension_code($attr, $data) {
  242.         $role     = isset($attr["role"])     ? $attr["role"]     : "code";
  243.         $position = isset($attr["position"]) ? $attr["position"] : "bottom";
  244.  
  245.         if (isset($attr["src"])) {
  246.             return $this->extension->addCode($role, $position, CodeGen_Tools_Indent::linetrim(file_get_contents($attr["src"])));
  247.         } else {
  248.             return $this->extension->addCode($role, $position, CodeGen_Tools_Indent::linetrim($data));
  249.         }
  250.     }
  251.  
  252.  
  253.     function tagstart_deps($attr)
  254.     {
  255.         if (isset($attr["platform"])) {
  256.             $err = $this->extension->setPlatform($attr["platform"]);
  257.             if (PEAR::isError($err)) {
  258.                 return $err;
  259.             }
  260.         }
  261.  
  262.         if (isset($attr["language"])) {
  263.             $err = $this->extension->setLanguage($attr["language"]);
  264.             if (PEAR::isError($err)) {
  265.                 return $err;
  266.             }
  267.         }
  268.  
  269.     }
  270.  
  271.     function tagstart_deps_file($attr) 
  272.     {
  273.         if (!isset($attr['name'])) {
  274.             return PEAR::raiseError("name attribut for file missing");
  275.         }
  276.  
  277.         return $this->extension->addSourceFile($attr['name']);
  278.     }
  279.         
  280.     function tagstart_deps_lib($attr)
  281.     {
  282.         $this->extension->libs[$attr['name']] = $attr;
  283.         if (isset($attr['platform'])) {
  284.             $platform = new CodeGen_Tools_Platform($attr["platform"]);
  285.         } else {
  286.             $platform = new CodeGen_Tools_Platform("all");
  287.         }
  288.  
  289.         if (PEAR::isError($platform)) {
  290.             return $platform;
  291.         }
  292.  
  293.         $this->extension->libs[$attr['name']]['platform'] = $platform;
  294.         return true;
  295.     }
  296.  
  297.     function tagstart_deps_header($attr)
  298.     {
  299.         $this->extension->headers[$attr['name']] = $attr; 
  300.     }
  301. }
  302.  
  303.  
  304. /*
  305.  * Local variables:
  306.  * tab-width: 4
  307.  * c-basic-offset: 4
  308.  * indent-tabs-mode:nil
  309.  * End:
  310.  */
  311. ?>
  312.