PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file Validator.php

Documentation is available at Validator.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 5                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at the following url:           |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Greg Beaver <cellog@php.net>                                 |
  17. // |                                                                      |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Validator.php,v 1.85 2006/02/08 01:21:47 cellog Exp $
  21. /**
  22.  * Private validation class used by PEAR_PackageFile_v2 - do not use directly, its
  23.  * sole purpose is to split up the PEAR/PackageFile/v2.php file to make it smaller
  24.  * @author Greg Beaver <cellog@php.net>
  25.  * @access private
  26.  */
  27. class PEAR_PackageFile_v2_Validator
  28. {
  29.     /**
  30.      * @var array 
  31.      */
  32.     var $_packageInfo;
  33.     /**
  34.      * @var PEAR_PackageFile_v2 
  35.      */
  36.     var $_pf;
  37.     /**
  38.      * @var PEAR_ErrorStack 
  39.      */
  40.     var $_stack;
  41.     /**
  42.      * @var int 
  43.      */
  44.     var $_isValid = 0;
  45.     /**
  46.      * @var int 
  47.      */
  48.     var $_filesValid = 0;
  49.     /**
  50.      * @var int 
  51.      */
  52.     var $_curState = 0;
  53.     /**
  54.      * @param PEAR_PackageFile_v2 
  55.      * @param int 
  56.      */
  57.     function validate(&$pf$state = PEAR_VALIDATE_NORMAL)
  58.     {
  59.         $this->_pf &$pf;
  60.         $this->_curState $state;
  61.         $this->_packageInfo $this->_pf->getArray();
  62.         $this->_isValid $this->_pf->_isValid;
  63.         $this->_filesValid $this->_pf->_filesValid;
  64.         $this->_stack &$pf->_stack;
  65.         $this->_stack->getErrors(true);
  66.         if (($this->_isValid $state== $state{
  67.             return true;
  68.         }
  69.         if (!isset($this->_packageInfo|| !is_array($this->_packageInfo)) {
  70.             return false;
  71.         }
  72.         if (!isset($this->_packageInfo['attribs']['version']||
  73.               $this->_packageInfo['attribs']['version'!= '2.0'{
  74.             $this->_noPackageVersion();
  75.         }
  76.         $structure =
  77.         array(
  78.             'name',
  79.             'channel|uri',
  80.             '*extends'// can't be multiple, but this works fine
  81.             'summary',
  82.             'description',
  83.             '+lead'// these all need content checks
  84.             '*developer',
  85.             '*contributor',
  86.             '*helper',
  87.             'date',
  88.             '*time',
  89.             'version',
  90.             'stability',
  91.             'license->?uri->?filesource',
  92.             'notes',
  93.             'contents'//special validation needed
  94.             '*compatible',
  95.             'dependencies'//special validation needed
  96.             '*usesrole',
  97.             '*usestask'// reserve these for 1.4.0a1 to implement
  98.                          // this will allow a package.xml to gracefully say it
  99.                          // needs a certain package installed in order to implement a role or task
  100.             '*providesextension',
  101.             '*srcpackage|*srcuri',
  102.             '+phprelease|+extsrcrelease|+extbinrelease|bundle'//special validation needed
  103.             '*changelog',
  104.         );
  105.         $test $this->_packageInfo;
  106.         // ignore post-installation array fields
  107.         if (array_key_exists('filelist'$test)) {
  108.             unset($test['filelist']);
  109.         }
  110.         if (array_key_exists('_lastmodified'$test)) {
  111.             unset($test['_lastmodified']);
  112.         }
  113.         if (array_key_exists('#binarypackage'$test)) {
  114.             unset($test['#binarypackage']);
  115.         }
  116.         if (array_key_exists('old'$test)) {
  117.             unset($test['old']);
  118.         }
  119.         if (array_key_exists('_lastversion'$test)) {
  120.             unset($test['_lastversion']);
  121.         }
  122.         if (!$this->_stupidSchemaValidate($structure,
  123.                                           $test'<package>')) {
  124.             return false;
  125.         }
  126.         if (empty($this->_packageInfo['name'])) {
  127.             $this->_tagCannotBeEmpty('name');
  128.         }
  129.         if (isset($this->_packageInfo['uri'])) {
  130.             $test 'uri';
  131.         else {
  132.             $test 'channel';
  133.         }
  134.         if (empty($this->_packageInfo[$test])) {
  135.             $this->_tagCannotBeEmpty($test);
  136.         }
  137.         if (is_array($this->_packageInfo['license']&&
  138.               (!isset($this->_packageInfo['license']['_content']||
  139.               empty($this->_packageInfo['license']['_content']))) {
  140.             $this->_tagCannotBeEmpty('license');
  141.         elseif (empty($this->_packageInfo['license'])) {
  142.             $this->_tagCannotBeEmpty('license');
  143.         }
  144.         if (empty($this->_packageInfo['summary'])) {
  145.             $this->_tagCannotBeEmpty('summary');
  146.         }
  147.         if (empty($this->_packageInfo['description'])) {
  148.             $this->_tagCannotBeEmpty('description');
  149.         }
  150.         if (empty($this->_packageInfo['date'])) {
  151.             $this->_tagCannotBeEmpty('date');
  152.         }
  153.         if (empty($this->_packageInfo['notes'])) {
  154.             $this->_tagCannotBeEmpty('notes');
  155.         }
  156.         if (isset($this->_packageInfo['time']&& empty($this->_packageInfo['time'])) {
  157.             $this->_tagCannotBeEmpty('time');
  158.         }
  159.         if (isset($this->_packageInfo['dependencies'])) {
  160.             $this->_validateDependencies();
  161.         }
  162.         if (isset($this->_packageInfo['compatible'])) {
  163.             $this->_validateCompatible();
  164.         }
  165.         if (!isset($this->_packageInfo['bundle'])) {
  166.             if (!isset($this->_packageInfo['contents']['dir'])) {
  167.                 $this->_filelistMustContainDir('contents');
  168.                 return false;
  169.             }
  170.             if (isset($this->_packageInfo['contents']['file'])) {
  171.                 $this->_filelistCannotContainFile('contents');
  172.                 return false;
  173.             }
  174.         }
  175.         $this->_validateMaintainers();
  176.         $this->_validateStabilityVersion();
  177.         $fail = false;
  178.         if (array_key_exists('usesrole'$this->_packageInfo)) {
  179.             $roles $this->_packageInfo['usesrole'];
  180.             if (!is_array($roles|| !isset($roles[0])) {
  181.                 $roles = array($roles);
  182.             }
  183.             foreach ($roles as $role{
  184.                 if (!isset($role['role'])) {
  185.                     $this->_usesroletaskMustHaveRoleTask('usesrole''role');
  186.                     $fail = true;
  187.                 else {
  188.                     if (!isset($role['channel'])) {
  189.                         if (!isset($role['uri'])) {
  190.                             $this->_usesroletaskMustHaveChannelOrUri($role['role']'usesrole');
  191.                             $fail = true;
  192.                         }
  193.                     elseif (!isset($role['package'])) {
  194.                         $this->_usesroletaskMustHavePackage($role['role']'usesrole');
  195.                         $fail = true;
  196.                     }
  197.                 }
  198.             }
  199.         }
  200.         if (array_key_exists('usestask'$this->_packageInfo)) {
  201.             $roles $this->_packageInfo['usestask'];
  202.             if (!is_array($roles|| !isset($roles[0])) {
  203.                 $roles = array($roles);
  204.             }
  205.             foreach ($roles as $role{
  206.                 if (!isset($role['task'])) {
  207.                     $this->_usesroletaskMustHaveRoleTask('usestask''task');
  208.                     $fail = true;
  209.                 else {
  210.                     if (!isset($role['channel'])) {
  211.                         if (!isset($role['uri'])) {
  212.                             $this->_usesroletaskMustHaveChannelOrUri($role['task']'usestask');
  213.                             $fail = true;
  214.                         }
  215.                     elseif (!isset($role['package'])) {
  216.                         $this->_usesroletaskMustHavePackage($role['task']'usestask');
  217.                         $fail = true;
  218.                     }
  219.                 }
  220.             }
  221.         }
  222.         if ($fail{
  223.             return false;
  224.         }
  225.         $this->_validateFilelist();
  226.         $this->_validateRelease();
  227.         if (!$this->_stack->hasErrors()) {
  228.             $chan $this->_pf->_registry->getChannel($this->_pf->getChannel()true);
  229.             if (!$chan{
  230.                 $this->_unknownChannel($this->_pf->getChannel());
  231.             else {
  232.                 $valpack $chan->getValidationPackage();
  233.                 // for channel validator packages, always use the default PEAR validator.
  234.                 // otherwise, they can't be installed or packaged
  235.                 $validator $chan->getValidationObject($this->_pf->getPackage());
  236.                 if (!$validator{
  237.                     $this->_stack->push(__FUNCTION__'error',
  238.                         array_merge(
  239.                             array('channel' => $chan->getName(),
  240.                                   'package' => $this->_pf->getPackage()),
  241.                               $valpack
  242.                             ),
  243.                         'package "%channel%/%package%" cannot be properly validated without ' .
  244.                         'validation package "%channel%/%name%-%version%"');
  245.                     return $this->_isValid = 0;
  246.                 }
  247.                 $validator->setPackageFile($this->_pf);
  248.                 $validator->validate($state);
  249.                 $failures $validator->getFailures();
  250.                 foreach ($failures['errors'as $error{
  251.                     $this->_stack->push(__FUNCTION__'error'$error,
  252.                         'Channel validator error: field "%field%" - %reason%');
  253.                 }
  254.                 foreach ($failures['warnings'as $warning{
  255.                     $this->_stack->push(__FUNCTION__'warning'$warning,
  256.                         'Channel validator warning: field "%field%" - %reason%');
  257.                 }
  258.             }
  259.         }
  260.         $this->_pf->_isValid = $this->_isValid !$this->_stack->hasErrors('error');
  261.         if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$this->_filesValid{
  262.             if ($this->_pf->getPackageType(== 'bundle'{
  263.                 if ($this->_analyzeBundledPackages()) {
  264.                     $this->_filesValid $this->_pf->_filesValid = true;
  265.                 else {
  266.                     $this->_pf->_isValid = $this->_isValid = 0;
  267.                 }
  268.             else {
  269.                 if (!$this->_analyzePhpFiles()) {
  270.                     $this->_pf->_isValid = $this->_isValid = 0;
  271.                 else {
  272.                     $this->_filesValid $this->_pf->_filesValid = true;
  273.                 }
  274.             }
  275.         }
  276.         if ($this->_isValid{
  277.             return $this->_pf->_isValid = $this->_isValid $state;
  278.         }
  279.         return $this->_pf->_isValid = $this->_isValid = 0;
  280.     }
  281.  
  282.     function _stupidSchemaValidate($structure$xml$root)
  283.     {
  284.         if (!is_array($xml)) {
  285.             $xml = array();
  286.         }
  287.         $keys array_keys($xml);
  288.         reset($keys);
  289.         $key current($keys);
  290.         while ($key == 'attribs' || $key == '_contents'{
  291.             $key next($keys);
  292.         }
  293.         $unfoundtags $optionaltags = array();
  294.         $ret = true;
  295.         $mismatch = false;
  296.         foreach ($structure as $struc{
  297.             if ($key{
  298.                 $tag $xml[$key];
  299.             }
  300.             $test $this->_processStructure($struc);
  301.             if (isset($test['choices'])) {
  302.                 $loose = true;
  303.                 foreach ($test['choices'as $choice{
  304.                     if ($key == $choice['tag']{
  305.                         $key next($keys);
  306.                         while ($key == 'attribs' || $key == '_contents'{
  307.                             $key next($keys);
  308.                         }
  309.                         $unfoundtags $optionaltags = array();
  310.                         $mismatch = false;
  311.                         if ($key && $key != $choice['tag'&& isset($choice['multiple'])) {
  312.                             $unfoundtags[$choice['tag'];
  313.                             $optionaltags[$choice['tag'];
  314.                             if ($key{
  315.                                 $mismatch = true;
  316.                             }
  317.                         }
  318.                         $ret &= $this->_processAttribs($choice$tag$root);
  319.                         continue 2;
  320.                     else {
  321.                         $unfoundtags[$choice['tag'];
  322.                         $mismatch = true;
  323.                     }
  324.                     if (!isset($choice['multiple']|| $choice['multiple'!= '*'{
  325.                         $loose = false;
  326.                     else {
  327.                         $optionaltags[$choice['tag'];
  328.                     }
  329.                 }
  330.                 if (!$loose{
  331.                     $this->_invalidTagOrder($unfoundtags$key$root);
  332.                     return false;
  333.                 }
  334.             else {
  335.                 if ($key != $test['tag']{
  336.                     if (isset($test['multiple']&& $test['multiple'!= '*'{
  337.                         $unfoundtags[$test['tag'];
  338.                         $this->_invalidTagOrder($unfoundtags$key$root);
  339.                         return false;
  340.                     else {
  341.                         if ($key{
  342.                             $mismatch = true;
  343.                         }
  344.                         $unfoundtags[$test['tag'];
  345.                         $optionaltags[$test['tag'];
  346.                     }
  347.                     if (!isset($test['multiple'])) {
  348.                         $this->_invalidTagOrder($unfoundtags$key$root);
  349.                         return false;
  350.                     }
  351.                     continue;
  352.                 else {
  353.                     $unfoundtags $optionaltags = array();
  354.                     $mismatch = false;
  355.                 }
  356.                 $key next($keys);
  357.                 while ($key == 'attribs' || $key == '_contents'{
  358.                     $key next($keys);
  359.                 }
  360.                 if ($key && $key != $test['tag'&& isset($test['multiple'])) {
  361.                     $unfoundtags[$test['tag'];
  362.                     $optionaltags[$test['tag'];
  363.                     $mismatch = true;
  364.                 }
  365.                 $ret &= $this->_processAttribs($test$tag$root);
  366.                 continue;
  367.             }
  368.         }
  369.         if (!$mismatch && count($optionaltags)) {
  370.             // don't error out on any optional tags
  371.             $unfoundtags array_diff($unfoundtags$optionaltags);
  372.         }
  373.         if (count($unfoundtags)) {
  374.             $this->_invalidTagOrder($unfoundtags$key$root);
  375.         elseif ($key{
  376.             // unknown tags
  377.             $this->_invalidTagOrder('*no tags allowed here*'$key$root);
  378.             while ($key next($keys)) {
  379.                 $this->_invalidTagOrder('*no tags allowed here*'$key$root);
  380.             }
  381.         }
  382.         return $ret;
  383.     }
  384.  
  385.     function _processAttribs($choice$tag$context)
  386.     {
  387.         if (isset($choice['attribs'])) {
  388.             if (!is_array($tag)) {
  389.                 $tag = array($tag);
  390.             }
  391.             $tags $tag;
  392.             if (!isset($tags[0])) {
  393.                 $tags = array($tags);
  394.             }
  395.             $ret = true;
  396.             foreach ($tags as $i => $tag{
  397.                 if (!is_array($tag|| !isset($tag['attribs'])) {
  398.                     foreach ($choice['attribs'as $attrib{
  399.                         if ($attrib{0!= '?'{
  400.                             $ret &= $this->_tagHasNoAttribs($choice['tag'],
  401.                                 $context);
  402.                             continue 2;
  403.                         }
  404.                     }
  405.                 }
  406.                 foreach ($choice['attribs'as $attrib{
  407.                     if ($attrib{0!= '?'{
  408.                         if (!isset($tag['attribs'][$attrib])) {
  409.                             $ret &= $this->_tagMissingAttribute($choice['tag'],
  410.                                 $attrib$context);
  411.                         }
  412.                     }
  413.                 }
  414.             }
  415.             return $ret;
  416.         }
  417.         return true;
  418.     }
  419.  
  420.     function _processStructure($key)
  421.     {
  422.         $ret = array();
  423.         if (count($pieces explode('|'$key)) > 1{
  424.             foreach ($pieces as $piece{
  425.                 $ret['choices'][$this->_processStructure($piece);
  426.             }
  427.             return $ret;
  428.         }
  429.         $multi $key{0};
  430.         if ($multi == '+' || $multi == '*'{
  431.             $ret['multiple'$key{0};
  432.             $key substr($key1);
  433.         }
  434.         if (count($attrs explode('->'$key)) > 1{
  435.             $ret['tag'array_shift($attrs);
  436.             $ret['attribs'$attrs;
  437.         else {
  438.             $ret['tag'$key;
  439.         }
  440.         return $ret;
  441.     }
  442.  
  443.     function _validateStabilityVersion()
  444.     {
  445.         $structure = array('release''api');
  446.         $a $this->_stupidSchemaValidate($structure$this->_packageInfo['version']'<version>');
  447.         $a &= $this->_stupidSchemaValidate($structure$this->_packageInfo['stability']'<stability>');
  448.         if ($a{
  449.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  450.                   $this->_packageInfo['version']['release'])) {
  451.                 $this->_invalidVersion('release'$this->_packageInfo['version']['release']);
  452.             }
  453.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  454.                   $this->_packageInfo['version']['api'])) {
  455.                 $this->_invalidVersion('api'$this->_packageInfo['version']['api']);
  456.             }
  457.             if (!in_array($this->_packageInfo['stability']['release'],
  458.                   array('snapshot''devel''alpha''beta''stable'))) {
  459.                 $this->_invalidState('release'$this->_packageinfo['stability']['release']);
  460.             }
  461.             if (!in_array($this->_packageInfo['stability']['api'],
  462.                   array('devel''alpha''beta''stable'))) {
  463.                 $this->_invalidState('api'$this->_packageinfo['stability']['api']);
  464.             }
  465.         }
  466.     }
  467.  
  468.     function _validateMaintainers()
  469.     {
  470.         $structure =
  471.             array(
  472.                 'name',
  473.                 'user',
  474.                 'email',
  475.                 'active',
  476.             );
  477.         foreach (array('lead''developer''contributor''helper'as $type{
  478.             if (!isset($this->_packageInfo[$type])) {
  479.                 continue;
  480.             }
  481.             if (isset($this->_packageInfo[$type][0])) {
  482.                 foreach ($this->_packageInfo[$typeas $lead{
  483.                     $this->_stupidSchemaValidate($structure$lead'<' $type '>');
  484.                 }
  485.             else {
  486.                 $this->_stupidSchemaValidate($structure$this->_packageInfo[$type],
  487.                     '<' $type '>');
  488.             }
  489.         }
  490.     }
  491.  
  492.     function _validatePhpDep($dep$installcondition = false)
  493.     {
  494.         $structure = array(
  495.             'min',
  496.             '*max',
  497.             '*exclude',
  498.         );
  499.         $type $installcondition '<installcondition><php>' '<dependencies><required><php>';
  500.         $this->_stupidSchemaValidate($structure$dep$type);
  501.         if (isset($dep['min'])) {
  502.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
  503.                   $dep['min'])) {
  504.                 $this->_invalidVersion($type '<min>'$dep['min']);
  505.             }
  506.         }
  507.         if (isset($dep['max'])) {
  508.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
  509.                   $dep['max'])) {
  510.                 $this->_invalidVersion($type '<max>'$dep['max']);
  511.             }
  512.         }
  513.     }
  514.  
  515.     function _validatePearinstallerDep($dep)
  516.     {
  517.         $structure = array(
  518.             'min',
  519.             '*max',
  520.             '*recommended',
  521.             '*exclude',
  522.         );
  523.         $this->_stupidSchemaValidate($structure$dep'<dependencies><required><pearinstaller>');
  524.         if (isset($dep['min'])) {
  525.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  526.                   $dep['min'])) {
  527.                 $this->_invalidVersion('<dependencies><required><pearinstaller><min>',
  528.                     $dep['min']);
  529.             }
  530.         }
  531.         if (isset($dep['max'])) {
  532.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  533.                   $dep['max'])) {
  534.                 $this->_invalidVersion('<dependencies><required><pearinstaller><max>',
  535.                     $dep['max']);
  536.             }
  537.         }
  538.         if (isset($dep['recommended'])) {
  539.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  540.                   $dep['recommended'])) {
  541.                 $this->_invalidVersion('<dependencies><required><pearinstaller><recommended>',
  542.                     $dep['recommended']);
  543.             }
  544.         }
  545.         if (isset($dep['exclude'])) {
  546.             if (!is_array($dep['exclude'])) {
  547.                 $dep['exclude'= array($dep['exclude']);
  548.             }
  549.             foreach ($dep['exclude'as $exclude{
  550.                 if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  551.                       $exclude)) {
  552.                     $this->_invalidVersion('<dependencies><required><pearinstaller><exclude>',
  553.                         $exclude);
  554.                 }
  555.             }
  556.         }
  557.     }
  558.  
  559.     function _validatePackageDep($dep$group$type '<package>')
  560.     {
  561.         if (isset($dep['uri'])) {
  562.             if (isset($dep['conflicts'])) {
  563.                 $structure = array(
  564.                     'name',
  565.                     'uri',
  566.                     'conflicts',
  567.                     '*providesextension',
  568.                 );
  569.             else {
  570.                 $structure = array(
  571.                     'name',
  572.                     'uri',
  573.                     '*providesextension',
  574.                 );
  575.             }
  576.         else {
  577.             if (isset($dep['conflicts'])) {
  578.                 $structure = array(
  579.                     'name',
  580.                     'channel',
  581.                     '*min',
  582.                     '*max',
  583.                     '*exclude',
  584.                     'conflicts',
  585.                     '*providesextension',
  586.                 );
  587.             else {
  588.                 $structure = array(
  589.                     'name',
  590.                     'channel',
  591.                     '*min',
  592.                     '*max',
  593.                     '*recommended',
  594.                     '*exclude',
  595.                     '*nodefault',
  596.                     '*providesextension',
  597.                 );
  598.             }
  599.         }
  600.         if (isset($dep['name'])) {
  601.             $type .= '<name>' $dep['name''</name>';
  602.         }
  603.         $this->_stupidSchemaValidate($structure$dep'<dependencies>' $group $type);
  604.         if (isset($dep['uri']&& (isset($dep['min']|| isset($dep['max']||
  605.               isset($dep['recommended']|| isset($dep['exclude']))) {
  606.             $this->_uriDepsCannotHaveVersioning('<dependencies>' $group $type);
  607.         }
  608.         if (isset($dep['channel']&& strtolower($dep['channel']== '__uri'{
  609.             $this->_DepchannelCannotBeUri('<dependencies>' $group $type);
  610.         }
  611.         if (isset($dep['min'])) {
  612.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  613.                   $dep['min'])) {
  614.                 $this->_invalidVersion('<dependencies>' $group $type '<min>'$dep['min']);
  615.             }
  616.         }
  617.         if (isset($dep['max'])) {
  618.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  619.                   $dep['max'])) {
  620.                 $this->_invalidVersion('<dependencies>' $group $type '<max>'$dep['max']);
  621.             }
  622.         }
  623.         if (isset($dep['recommended'])) {
  624.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  625.                   $dep['recommended'])) {
  626.                 $this->_invalidVersion('<dependencies>' $group $type '<recommended>',
  627.                     $dep['recommended']);
  628.             }
  629.         }
  630.         if (isset($dep['exclude'])) {
  631.             if (!is_array($dep['exclude'])) {
  632.                 $dep['exclude'= array($dep['exclude']);
  633.             }
  634.             foreach ($dep['exclude'as $exclude{
  635.                 if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  636.                       $exclude)) {
  637.                     $this->_invalidVersion('<dependencies>' $group $type '<exclude>',
  638.                         $exclude);
  639.                 }
  640.             }
  641.         }
  642.     }
  643.  
  644.     function _validateSubpackageDep($dep$group)
  645.     {
  646.         $this->_validatePackageDep($dep$group'<subpackage>');
  647.         if (isset($dep['providesextension'])) {
  648.             $this->_subpackageCannotProvideExtension(@$dep['name']);
  649.         }
  650.         if (isset($dep['conflicts'])) {
  651.             $this->_subpackagesCannotConflict(@$dep['name']);
  652.         }
  653.     }
  654.  
  655.     function _validateExtensionDep($dep$group = false$installcondition = false)
  656.     {
  657.         if (isset($dep['conflicts'])) {
  658.             $structure = array(
  659.                 'name',
  660.                 '*min',
  661.                 '*max',
  662.                 '*exclude',
  663.                 'conflicts',
  664.             );
  665.         else {
  666.             $structure = array(
  667.                 'name',
  668.                 '*min',
  669.                 '*max',
  670.                 '*recommended',
  671.                 '*exclude',
  672.             );
  673.         }
  674.         if ($installcondition{
  675.             $type '<installcondition><extension>';
  676.         else {
  677.             $type '<dependencies>' $group '<extension>';
  678.         }
  679.         if (isset($dep['name'])) {
  680.             $type .= '<name>' $dep['name''</name>';
  681.         }
  682.         $this->_stupidSchemaValidate($structure$dep$type);
  683.         if (isset($dep['min'])) {
  684.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  685.                   $dep['min'])) {
  686.                 $this->_invalidVersion(substr($type1'<min'$dep['min']);
  687.             }
  688.         }
  689.         if (isset($dep['max'])) {
  690.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  691.                   $dep['max'])) {
  692.                 $this->_invalidVersion(substr($type1'<max'$dep['max']);
  693.             }
  694.         }
  695.         if (isset($dep['recommended'])) {
  696.             if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  697.                   $dep['recommended'])) {
  698.                 $this->_invalidVersion(substr($type1'<recommended'$dep['recommended']);
  699.             }
  700.         }
  701.         if (isset($dep['exclude'])) {
  702.             if (!is_array($dep['exclude'])) {
  703.                 $dep['exclude'= array($dep['exclude']);
  704.             }
  705.             foreach ($dep['exclude'as $exclude{
  706.                 if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  707.                       $exclude)) {
  708.                     $this->_invalidVersion(substr($type1'<exclude'$exclude);
  709.                 }
  710.             }
  711.         }
  712.     }
  713.  
  714.     function _validateOsDep($dep$installcondition = false)
  715.     {
  716.         $structure = array(
  717.             'name',
  718.             '*conflicts',
  719.         );
  720.         $type $installcondition '<installcondition><os>' '<dependencies><required><os>';
  721.         if ($this->_stupidSchemaValidate($structure$dep$type)) {
  722.             if ($dep['name'== '*'{
  723.                 if (array_key_exists('conflicts'$dep)) {
  724.                     $this->_cannotConflictWithAllOs($type);
  725.                 }
  726.             }
  727.         }
  728.     }
  729.  
  730.     function _validateArchDep($dep$installcondition = false)
  731.     {
  732.         $structure = array(
  733.             'pattern',
  734.             '*conflicts',
  735.         );
  736.         $type $installcondition '<installcondition><arch>' '<dependencies><required><arch>';
  737.         $this->_stupidSchemaValidate($structure$dep$type);
  738.     }
  739.  
  740.     function _validateInstallConditions($cond$release)
  741.     {
  742.         $structure = array(
  743.             '*php',
  744.             '*extension',
  745.             '*os',
  746.             '*arch',
  747.         );
  748.         if (!$this->_stupidSchemaValidate($structure,
  749.               $cond$release)) {
  750.             return false;
  751.         }
  752.         foreach (array('php''extension''os''arch'as $type{
  753.             if (isset($cond[$type])) {
  754.                 $iter $cond[$type];
  755.                 if (!is_array($iter|| !isset($iter[0])) {
  756.                     $iter = array($iter);
  757.                 }
  758.                 foreach ($iter as $package{
  759.                     if ($type == 'extension'{
  760.                         $this->{"_validate{$type}Dep"}($packagefalsetrue);
  761.                     else {
  762.                         $this->{"_validate{$type}Dep"}($packagetrue);
  763.                     }
  764.                 }
  765.             }
  766.         }
  767.     }
  768.  
  769.     function _validateDependencies()
  770.     {
  771.         $structure = array(
  772.             'required',
  773.             '*optional',
  774.             '*group->name->hint'
  775.         );
  776.         if (!$this->_stupidSchemaValidate($structure,
  777.               $this->_packageInfo['dependencies']'<dependencies>')) {
  778.             return false;
  779.         }
  780.         foreach (array('required''optional'as $simpledep{
  781.             if (isset($this->_packageInfo['dependencies'][$simpledep])) {
  782.                 if ($simpledep == 'optional'{
  783.                     $structure = array(
  784.                         '*package',
  785.                         '*subpackage',
  786.                         '*extension',
  787.                     );
  788.                 else {
  789.                     $structure = array(
  790.                         'php',
  791.                         'pearinstaller',
  792.                         '*package',
  793.                         '*subpackage',
  794.                         '*extension',
  795.                         '*os',
  796.                         '*arch',
  797.                     );
  798.                 }
  799.                 if ($this->_stupidSchemaValidate($structure,
  800.                       $this->_packageInfo['dependencies'][$simpledep],
  801.                       "<dependencies><$simpledep>")) {
  802.                     foreach (array('package''subpackage''extension'as $type{
  803.                         if (isset($this->_packageInfo['dependencies'][$simpledep][$type])) {
  804.                             $iter $this->_packageInfo['dependencies'][$simpledep][$type];
  805.                             if (!isset($iter[0])) {
  806.                                 $iter = array($iter);
  807.                             }
  808.                             foreach ($iter as $package{
  809.                                 if ($type != 'extension'{
  810.                                     if (isset($package['uri'])) {
  811.                                         if (isset($package['channel'])) {
  812.                                             $this->_UrlOrChannel($type,
  813.                                                 $package['name']);
  814.                                         }
  815.                                     else {
  816.                                         if (!isset($package['channel'])) {
  817.                                             $this->_NoChannel($type$package['name']);
  818.                                         }
  819.                                     }
  820.                                 }
  821.                                 $this->{"_validate{$type}Dep"}($package"<$simpledep>");
  822.                             }
  823.                         }
  824.                     }
  825.                     if ($simpledep == 'optional'{
  826.                         continue;
  827.                     }
  828.                     foreach (array('php''pearinstaller''os''arch'as $type{
  829.                         if (isset($this->_packageInfo['dependencies'][$simpledep][$type])) {
  830.                             $iter $this->_packageInfo['dependencies'][$simpledep][$type];
  831.                             if (!isset($iter[0])) {
  832.                                 $iter = array($iter);
  833.                             }
  834.                             foreach ($iter as $package{
  835.                                 $this->{"_validate{$type}Dep"}($package);
  836.                             }
  837.                         }
  838.                     }
  839.                 }
  840.             }
  841.         }
  842.         if (isset($this->_packageInfo['dependencies']['group'])) {
  843.             $groups $this->_packageInfo['dependencies']['group'];
  844.             if (!isset($groups[0])) {
  845.                 $groups = array($groups);
  846.             }
  847.             $structure = array(
  848.                 '*package',
  849.                 '*subpackage',
  850.                 '*extension',
  851.             );
  852.             foreach ($groups as $group{
  853.                 if ($this->_stupidSchemaValidate($structure$group'<group>')) {
  854.                     if (!PEAR_Validate::validGroupName($group['attribs']['name'])) {
  855.                         $this->_invalidDepGroupName($group['attribs']['name']);
  856.                     }
  857.                     foreach (array('package''subpackage''extension'as $type{
  858.                         if (isset($group[$type])) {
  859.                             $iter $group[$type];
  860.                             if (!isset($iter[0])) {
  861.                                 $iter = array($iter);
  862.                             }
  863.                             foreach ($iter as $package{
  864.                                 if ($type != 'extension'{
  865.                                     if (isset($package['uri'])) {
  866.                                         if (isset($package['channel'])) {
  867.                                             $this->_UrlOrChannelGroup($type,
  868.                                                 $package['name'],
  869.                                                 $group['name']);
  870.                                         }
  871.                                     else {
  872.                                         if (!isset($package['channel'])) {
  873.                                             $this->_NoChannelGroup($type,
  874.                                                 $package['name'],
  875.                                                 $group['name']);
  876.                                         }
  877.                                     }
  878.                                 }
  879.                                 $this->{"_validate{$type}Dep"}($package'<group name="' .
  880.                                     $group['attribs']['name''">');
  881.                             }
  882.                         }
  883.                     }
  884.                 }
  885.             }
  886.         }
  887.     }
  888.  
  889.     function _validateCompatible()
  890.     {
  891.         $compat $this->_packageInfo['compatible'];
  892.         if (!isset($compat[0])) {
  893.             $compat = array($compat);
  894.         }
  895.         $required = array('name''channel''min''max''*exclude');
  896.         foreach ($compat as $package{
  897.             $type '<compatible>';
  898.             if (is_array($package&& array_key_exists('name'$package)) {
  899.                 $type .= '<name>' $package['name''</name>';
  900.             }
  901.             $this->_stupidSchemaValidate($required$package$type);
  902.             if (is_array($package&& array_key_exists('min'$package)) {
  903.                 if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  904.                       $package['min'])) {
  905.                     $this->_invalidVersion(substr($type1'<min'$package['min']);
  906.                 }
  907.             }
  908.             if (is_array($package&& array_key_exists('max'$package)) {
  909.                 if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  910.                       $package['max'])) {
  911.                     $this->_invalidVersion(substr($type1'<max'$package['max']);
  912.                 }
  913.             }
  914.             if (is_array($package&& array_key_exists('exclude'$package)) {
  915.                 if (!is_array($package['exclude'])) {
  916.                     $package['exclude'= array($package['exclude']);
  917.                 }
  918.                 foreach ($package['exclude'as $exclude{
  919.                     if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
  920.                           $exclude)) {
  921.                         $this->_invalidVersion(substr($type1'<exclude'$exclude);
  922.                     }
  923.                 }
  924.             }
  925.         }
  926.     }
  927.  
  928.     function _validateBundle($list)
  929.     {
  930.         if (!is_array($list|| !isset($list['bundledpackage'])) {
  931.             return $this->_NoBundledPackages();
  932.         }
  933.         if (!is_array($list['bundledpackage']|| !isset($list['bundledpackage'][0])) {
  934.             return $this->_AtLeast2BundledPackages();
  935.         }
  936.         foreach ($list['bundledpackage'as $package{
  937.             if (!is_string($package)) {
  938.                 $this->_bundledPackagesMustBeFilename();
  939.             }
  940.         }
  941.     }
  942.  
  943.     function _validateFilelist($list = false$allowignore = false$dirs '')
  944.     {
  945.         $iscontents = false;
  946.         if (!$list{
  947.             $iscontents = true;
  948.             $list $this->_packageInfo['contents'];
  949.             if (isset($this->_packageInfo['bundle'])) {
  950.                 return $this->_validateBundle($list);
  951.             }
  952.         }
  953.         if ($allowignore{
  954.             $struc = array(
  955.                 '*install->name->as',
  956.                 '*ignore->name'
  957.             );
  958.         else {
  959.             $struc = array(
  960.                 '*dir->name->?baseinstalldir',
  961.                 '*file->name->role->?baseinstalldir->?md5sum'
  962.             );
  963.             if (isset($list['dir']&& isset($list['file'])) {
  964.                 // stave off validation errors without requiring a set order.
  965.                 $_old $list;
  966.                 if (isset($list['attribs'])) {
  967.                     $list = array('attribs' => $_old['attribs']);
  968.                 }
  969.                 $list['dir'$_old['dir'];
  970.                 $list['file'$_old['file'];
  971.             }
  972.         }
  973.         if (!isset($list['attribs']|| !isset($list['attribs']['name'])) {
  974.             $unknown $allowignore '<filelist>' '<dir name="*unknown*">';
  975.             $dirname $iscontents '<contents>' $unknown;
  976.         else {
  977.             $dirname '<dir name="' $list['attribs']['name''">';
  978.         }
  979.         $res $this->_stupidSchemaValidate($struc$list$dirname);
  980.         if ($allowignore && $res{
  981.             $this->_pf->getFilelist();
  982.             $fcontents $this->_pf->getContents();
  983.             $filelist = array();
  984.             if (!isset($fcontents['dir']['file'][0])) {
  985.                 $fcontents['dir']['file'= array($fcontents['dir']['file']);
  986.             }
  987.             foreach ($fcontents['dir']['file'as $file{
  988.                 $filelist[$file['attribs']['name']] = true;
  989.             }
  990.             if (isset($list['install'])) {
  991.                 if (!isset($list['install'][0])) {
  992.                     $list['install'= array($list['install']);
  993.                 }
  994.                 foreach ($list['install'as $file{
  995.                     if (!isset($filelist[$file['attribs']['name']])) {
  996.                         $this->_notInContents($file['attribs']['name']'install');
  997.                     }
  998.                 }
  999.             }
  1000.             if (isset($list['ignore'])) {
  1001.                 if (!isset($list['ignore'][0])) {
  1002.                     $list['ignore'= array($list['ignore']);
  1003.                 }
  1004.                 foreach ($list['ignore'as $file{
  1005.                     if (!isset($filelist[$file['attribs']['name']])) {
  1006.                         $this->_notInContents($file['attribs']['name']'ignore');
  1007.                     }
  1008.                 }
  1009.             }
  1010.         }
  1011.         if (!$allowignore && isset($list['file'])) {
  1012.             if (!isset($list['file'][0])) {
  1013.                 // single file
  1014.                 $list['file'= array($list['file']);
  1015.             }
  1016.             foreach ($list['file'as $i => $file)
  1017.             {
  1018.                 if (isset($file['attribs']&& isset($file['attribs']['name']&&
  1019.                       $file['attribs']['name']{0== '.' &&
  1020.                         $file['attribs']['name']{1== '/'{
  1021.                     // name is something like "./doc/whatever.txt"
  1022.                     $this->_invalidFileName($file['attribs']['name']);
  1023.                 }
  1024.                 if (isset($file['attribs']&& isset($file['attribs']['role'])) {
  1025.                     if (!$this->_validateRole($file['attribs']['role'])) {
  1026.                         if (isset($this->_packageInfo['usesrole'])) {
  1027.                             $roles $this->_packageInfo['usesrole'];
  1028.                             if (!isset($roles[0])) {
  1029.                                 $roles = array($roles);
  1030.                             }
  1031.                             foreach ($roles as $role{
  1032.                                 if ($role['role'$file['attribs']['role']{
  1033.                                     $msg 'This package contains role "%role%" and requires ' .
  1034.                                         'package "%package%" to be used';
  1035.                                     if (isset($role['uri'])) {
  1036.                                         $params = array('role' => $role['role'],
  1037.                                             'package' => $role['uri']);
  1038.                                     else {
  1039.                                         $params = array('role' => $role['role'],
  1040.                                             'package' => $this->_pf->_registry->
  1041.                                             parsedPackageNameToString(array('package' =>
  1042.                                                 $role['package']'channel' => $role['channel']),
  1043.                                                 true));
  1044.                                     }
  1045.                                     $this->_stack->push('_mustInstallRole''error'$params$msg);
  1046.                                 }
  1047.                             }
  1048.                         }
  1049.                         $this->_invalidFileRole($file['attribs']['name'],
  1050.                             $dirname$file['attribs']['role']);
  1051.                     }
  1052.                 }
  1053.                 if (!isset($file['attribs'])) {
  1054.                     continue;
  1055.                 }
  1056.                 $save $file['attribs'];
  1057.                 if ($dirs{
  1058.                     $save['name'$dirs '/' $save['name'];
  1059.                 }
  1060.                 unset($file['attribs']);
  1061.                 if (count($file&& $this->_curState != PEAR_VALIDATE_DOWNLOADING// has tasks
  1062.                     foreach ($file as $task => $value{
  1063.                         if ($tagClass $this->_pf->getTask($task)) {
  1064.                             if (!is_array($value|| !isset($value[0])) {
  1065.                                 $value = array($value);
  1066.                             }
  1067.                             foreach ($value as $v{
  1068.                                 $ret call_user_func(array($tagClass'validateXml'),
  1069.                                     $this->_pf$v$this->_pf->_config$save);
  1070.                                 if (is_array($ret)) {
  1071.                                     $this->_invalidTask($task$ret@$save['name']);
  1072.                                 }
  1073.                             }
  1074.                         else {
  1075.                             if (isset($this->_packageInfo['usestask'])) {
  1076.                                 $roles $this->_packageInfo['usestask'];
  1077.                                 if (!isset($roles[0])) {
  1078.                                     $roles = array($roles);
  1079.                                 }
  1080.                                 foreach ($roles as $role{
  1081.                                     if ($role['task'$task{
  1082.                                         $msg 'This package contains task "%task%" and requires ' .
  1083.                                             'package "%package%" to be used';
  1084.                                         if (isset($role['uri'])) {
  1085.                                             $params = array('task' => $role['task'],
  1086.                                                 'package' => $role['uri']);
  1087.                                         else {
  1088.                                             $params = array('task' => $role['task'],
  1089.                                                 'package' => $this->_pf->_registry->
  1090.                                                 parsedPackageNameToString(array('package' =>
  1091.                                                     $role['package']'channel' => $role['channel']),
  1092.                                                     true));
  1093.                                         }
  1094.                                         $this->_stack->push('_mustInstallTask''error',
  1095.                                             $params$msg);
  1096.                                     }
  1097.                                 }
  1098.                             }
  1099.                             $this->_unknownTask($task$save['name']);
  1100.                         }
  1101.                     }
  1102.                 }
  1103.             }
  1104.         }
  1105.         if (isset($list['ignore'])) {
  1106.             if (!$allowignore{
  1107.                 $this->_ignoreNotAllowed('ignore');
  1108.             }
  1109.         }
  1110.         if (isset($list['install'])) {
  1111.             if (!$allowignore{
  1112.                 $this->_ignoreNotAllowed('install');
  1113.             }
  1114.         }
  1115.         if (isset($list['file'])) {
  1116.             if ($allowignore{
  1117.                 $this->_fileNotAllowed('file');
  1118.             }
  1119.         }
  1120.         if (isset($list['dir'])) {
  1121.             if ($allowignore{
  1122.                 $this->_fileNotAllowed('dir');
  1123.             else {
  1124.                 if (!isset($list['dir'][0])) {
  1125.                     $list['dir'= array($list['dir']);
  1126.                 }
  1127.                 foreach ($list['dir'as $dir{
  1128.                     if (isset($dir['attribs']&& isset($dir['attribs']['name'])) {
  1129.                         if ($dir['attribs']['name'== '/' ||
  1130.                               !isset($this->_packageInfo['contents']['dir']['dir'])) {
  1131.                             // always use nothing if the filelist has already been flattened
  1132.                             $newdirs '';
  1133.                         elseif ($dirs == ''{
  1134.                             $newdirs $dir['attribs']['name'];
  1135.                         else {
  1136.                             $newdirs $dirs '/' $dir['attribs']['name'];
  1137.                         }
  1138.                     else {
  1139.                         $newdirs $dirs;
  1140.                     }
  1141.                     $this->_validateFilelist($dir$allowignore$newdirs);
  1142.                 }
  1143.             }
  1144.         }
  1145.     }
  1146.  
  1147.     function _validateRelease()
  1148.     {
  1149.         if (isset($this->_packageInfo['phprelease'])) {
  1150.             $release 'phprelease';
  1151.             if (isset($this->_packageInfo['providesextension'])) {
  1152.                 $this->_cannotProvideExtension($release);
  1153.             }
  1154.             if (isset($this->_packageInfo['srcpackage']|| isset($this->_packageInfo['srcuri'])) {
  1155.                 $this->_cannotHaveSrcpackage($release);
  1156.             }
  1157.             $releases $this->_packageInfo['phprelease'];
  1158.             if (!is_array($releases)) {
  1159.                 return true;
  1160.             }
  1161.             if (!isset($releases[0])) {
  1162.                 $releases = array($releases);
  1163.             }
  1164.             foreach ($releases as $rel{
  1165.                 $this->_stupidSchemaValidate(array(
  1166.                     '*installconditions',
  1167.                     '*filelist',
  1168.                 )$rel'<phprelease>');
  1169.             }
  1170.         }
  1171.         if (isset($this->_packageInfo['extsrcrelease'])) {
  1172.             $release 'extsrcrelease';
  1173.             if (!isset($this->_packageInfo['providesextension'])) {
  1174.                 $this->_mustProvideExtension($release);
  1175.             }
  1176.             if (isset($this->_packageInfo['srcpackage']|| isset($this->_packageInfo['srcuri'])) {
  1177.                 $this->_cannotHaveSrcpackage($release);
  1178.             }
  1179.             $releases $this->_packageInfo['extsrcrelease'];
  1180.             if (!is_array($releases)) {
  1181.                 return true;
  1182.             }
  1183.             if (!isset($releases[0])) {
  1184.                 $releases = array($releases);
  1185.             }
  1186.             foreach ($releases as $rel{
  1187.                 $this->_stupidSchemaValidate(array(
  1188.                     '*installconditions',
  1189.                     '*configureoption->name->prompt->?default',
  1190.                     '*binarypackage',
  1191.                     '*filelist',
  1192.                 )$rel'<extsrcrelease>');
  1193.                 if (isset($rel['binarypackage'])) {
  1194.                     if (!is_array($rel['binarypackage']|| !isset($rel['binarypackage'][0])) {
  1195.                         $rel['binarypackage'= array($rel['binarypackage']);
  1196.                     }
  1197.                     foreach ($rel['binarypackage'as $bin{
  1198.                         if (!is_string($bin)) {
  1199.                             $this->_binaryPackageMustBePackagename();
  1200.                         }
  1201.                     }
  1202.                 }
  1203.             }
  1204.         }
  1205.         if (isset($this->_packageInfo['extbinrelease'])) {
  1206.             $release 'extbinrelease';
  1207.             if (!isset($this->_packageInfo['providesextension'])) {
  1208.                 $this->_mustProvideExtension($release);
  1209.             }
  1210.             if (isset($this->_packageInfo['channel']&&
  1211.                   !isset($this->_packageInfo['srcpackage'])) {
  1212.                 $this->_mustSrcPackage($release);
  1213.             }
  1214.             if (isset($this->_packageInfo['uri']&& !isset($this->_packageInfo['srcuri'])) {
  1215.                 $this->_mustSrcuri($release);
  1216.             }
  1217.             $releases $this->_packageInfo['extbinrelease'];
  1218.             if (!is_array($releases)) {
  1219.                 return true;
  1220.             }
  1221.             if (!isset($releases[0])) {
  1222.                 $releases = array($releases);
  1223.             }
  1224.             foreach ($releases as $rel{
  1225.                 $this->_stupidSchemaValidate(array(
  1226.                     '*installconditions',
  1227.                     '*filelist',
  1228.                 )$rel'<extbinrelease>');
  1229.             }
  1230.         }
  1231.         if (isset($this->_packageInfo['bundle'])) {
  1232.             $release 'bundle';
  1233.             if (isset($this->_packageInfo['providesextension'])) {
  1234.                 $this->_cannotProvideExtension($release);
  1235.             }
  1236.             if (isset($this->_packageInfo['srcpackage']|| isset($this->_packageInfo['srcuri'])) {
  1237.                 $this->_cannotHaveSrcpackage($release);
  1238.             }
  1239.             $releases $this->_packageInfo['bundle'];
  1240.             if (!is_array($releases|| !isset($releases[0])) {
  1241.                 $releases = array($releases);
  1242.             }
  1243.             foreach ($releases as $rel{
  1244.                 $this->_stupidSchemaValidate(array(
  1245.                     '*installconditions',
  1246.                     '*filelist',
  1247.                 )$rel'<bundle>');
  1248.             }
  1249.         }
  1250.         foreach ($releases as $rel{
  1251.             if (is_array($rel&& array_key_exists('installconditions'$rel)) {
  1252.                 $this->_validateInstallConditions($rel['installconditions'],
  1253.                     "<$release><installconditions>");
  1254.             }
  1255.             if (is_array($rel&& array_key_exists('filelist'$rel)) {
  1256.                 if ($rel['filelist']{
  1257.                     
  1258.                     $this->_validateFilelist($rel['filelist']true);
  1259.                 }
  1260.             }
  1261.         }
  1262.     }
  1263.  
  1264.     /**
  1265.      * This is here to allow role extension through plugins
  1266.      * @param string 
  1267.      */
  1268.     function _validateRole($role)
  1269.     {
  1270.         return in_array($rolePEAR_Installer_Role::getValidRoles($this->_pf->getPackageType()));
  1271.     }
  1272.  
  1273.     function _invalidTagOrder($oktags$actual$root)
  1274.     {
  1275.         $this->_stack->push(__FUNCTION__'error',
  1276.             array('oktags' => $oktags'actual' => $actual'root' => $root),
  1277.             'Invalid tag order in %root%, found <%actual%> expected one of "%oktags%"');
  1278.     }
  1279.  
  1280.     function _ignoreNotAllowed($type)
  1281.     {
  1282.         $this->_stack->push(__FUNCTION__'error'array('type' => $type),
  1283.             '<%type%> is not allowed inside global <contents>, only inside ' .
  1284.             '<phprelease>/<extbinrelease>, use <dir> and <file> only');
  1285.     }
  1286.  
  1287.     function _fileNotAllowed($type)
  1288.     {
  1289.         $this->_stack->push(__FUNCTION__'error'array('type' => $type),
  1290.             '<%type%> is not allowed inside release <filelist>, only inside ' .
  1291.             '<contents>, use <ignore> and <install> only');
  1292.     }
  1293.  
  1294.     function _tagMissingAttribute($tag$attr$context)
  1295.     {
  1296.         $this->_stack->push(__FUNCTION__'error'array('tag' => $tag,
  1297.             'attribute' => $attr'context' => $context),
  1298.             'tag <%tag%> in context "%context%" has no attribute "%attribute%"');
  1299.     }
  1300.  
  1301.     function _tagHasNoAttribs($tag$context)
  1302.     {
  1303.         $this->_stack->push(__FUNCTION__'error'array('tag' => $tag,
  1304.             'context' => $context),
  1305.             'tag <%tag%> has no attributes in context "%context%"');
  1306.     }
  1307.  
  1308.     function _invalidInternalStructure()
  1309.     {
  1310.         $this->_stack->push(__FUNCTION__'exception'array(),
  1311.             'internal array was not generated by compatible parser, or extreme parser error, cannot continue');
  1312.     }
  1313.  
  1314.     function _invalidFileRole($file$dir$role)
  1315.     {
  1316.         $this->_stack->push(__FUNCTION__'error'array(
  1317.             'file' => $file'dir' => $dir'role' => $role,
  1318.             'roles' => PEAR_Installer_Role::getValidRoles($this->_pf->getPackageType())),
  1319.             'File "%file%" in directory "%dir%" has invalid role "%role%", should be one of %roles%');
  1320.     }
  1321.  
  1322.     function _invalidFileName($file$dir)
  1323.     {
  1324.         $this->_stack->push(__FUNCTION__'error'array(
  1325.             'file' => $file),
  1326.             'File "%file%" cannot begin with "."');
  1327.     }
  1328.  
  1329.     function _filelistCannotContainFile($filelist)
  1330.     {
  1331.         $this->_stack->push(__FUNCTION__'error'array('tag' => $filelist),
  1332.             '<%tag%> can only contain <dir>, contains <file>.  Use ' .
  1333.             '<dir name="/"> as the first dir element');
  1334.     }
  1335.  
  1336.     function _filelistMustContainDir($filelist)
  1337.     {
  1338.         $this->_stack->push(__FUNCTION__'error'array('tag' => $filelist),
  1339.             '<%tag%> must contain <dir>.  Use <dir name="/"> as the ' .
  1340.             'first dir element');
  1341.     }
  1342.  
  1343.     function _tagCannotBeEmpty($tag)
  1344.     {
  1345.         $this->_stack->push(__FUNCTION__'error'array('tag' => $tag),
  1346.             '<%tag%> cannot be empty (<%tag%/>)');
  1347.     }
  1348.  
  1349.     function _UrlOrChannel($type$name)
  1350.     {
  1351.         $this->_stack->push(__FUNCTION__'error'array('type' => $type,
  1352.             'name' => $name),
  1353.             'Required dependency <%type%> "%name%" can have either url OR ' .
  1354.             'channel attributes, and not both');
  1355.     }
  1356.  
  1357.     function _NoChannel($type$name)
  1358.     {
  1359.         $this->_stack->push(__FUNCTION__'error'array('type' => $type,
  1360.             'name' => $name),
  1361.             'Required dependency <%type%> "%name%" must have either url OR ' .
  1362.             'channel attributes');
  1363.     }
  1364.  
  1365.     function _UrlOrChannelGroup($type$name$group)
  1366.     {
  1367.         $this->_stack->push(__FUNCTION__'error'array('type' => $type,
  1368.             'name' => $name'group' => $group),
  1369.             'Group "%group%" dependency <%type%> "%name%" can have either url OR ' .
  1370.             'channel attributes, and not both');
  1371.     }
  1372.  
  1373.     function _NoChannelGroup($type$name$group)
  1374.     {
  1375.         $this->_stack->push(__FUNCTION__'error'array('type' => $type,
  1376.             'name' => $name'group' => $group),
  1377.             'Group "%group%" dependency <%type%> "%name%" must have either url OR ' .
  1378.             'channel attributes');
  1379.     }
  1380.  
  1381.     function _unknownChannel($channel)
  1382.     {
  1383.         $this->_stack->push(__FUNCTION__'error'array('channel' => $channel),
  1384.             'Unknown channel "%channel%"');
  1385.     }
  1386.  
  1387.     function _noPackageVersion()
  1388.     {
  1389.         $this->_stack->push(__FUNCTION__'error'array(),
  1390.             'package.xml <package> tag has no version attribute, or version is not 2.0');
  1391.     }
  1392.  
  1393.     function _NoBundledPackages()
  1394.     {
  1395.         $this->_stack->push(__FUNCTION__'error'array(),
  1396.             'No <bundledpackage> tag was found in <contents>, required for bundle packages');
  1397.     }
  1398.  
  1399.     function _AtLeast2BundledPackages()
  1400.     {
  1401.         $this->_stack->push(__FUNCTION__'error'array(),
  1402.             'At least 2 packages must be bundled in a bundle package');
  1403.     }
  1404.  
  1405.     function _ChannelOrUri($name)
  1406.     {
  1407.         $this->_stack->push(__FUNCTION__'error'array('name' => $name),
  1408.             'Bundled package "%name%" can have either a uri or a channel, not both');
  1409.     }
  1410.  
  1411.     function _noChildTag($child$tag)
  1412.     {
  1413.         $this->_stack->push(__FUNCTION__'error'array('child' => $child'tag' => $tag),
  1414.             'Tag <%tag%> is missing child tag <%child%>');
  1415.     }
  1416.  
  1417.     function _invalidVersion($type$value)
  1418.     {
  1419.         $this->_stack->push(__FUNCTION__'error'array('type' => $type'value' => $value),
  1420.             'Version type <%type%> is not a valid version (%value%)');
  1421.     }
  1422.  
  1423.     function _invalidState($type$value)
  1424.     {
  1425.         $states = array('stable''beta''alpha''devel');
  1426.         if ($type != 'api'{
  1427.             $states['snapshot';
  1428.         }
  1429.         if (strtolower($value== 'rc'{
  1430.             $this->_stack->push(__FUNCTION__'error',
  1431.                 array('version' => $this->_packageInfo['version']['release']),
  1432.                 'RC is not a state, it is a version postfix, try %version%RC1, stability beta');
  1433.         }
  1434.         $this->_stack->push(__FUNCTION__'error'array('type' => $type'value' => $value,
  1435.             'types' => $states),
  1436.             'Stability type <%type%> is not a valid stability (%value%), must be one of ' .
  1437.             '%types%');
  1438.     }
  1439.  
  1440.     function _invalidTask($task$ret$file)
  1441.     {
  1442.         switch ($ret[0]{
  1443.             case PEAR_TASK_ERROR_MISSING_ATTRIB :
  1444.                 $info = array('attrib' => $ret[1]'task' => $task'file' => $file);
  1445.                 $msg 'task <%task%> is missing attribute "%attrib%" in file %file%';
  1446.             break;
  1447.             case PEAR_TASK_ERROR_NOATTRIBS :
  1448.                 $info = array('task' => $task'file' => $file);
  1449.                 $msg 'task <%task%> has no attributes in file %file%';
  1450.             break;
  1451.             case PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE :
  1452.                 $info = array('attrib' => $ret[1]'values' => $ret[3],
  1453.                     'was' => $ret[2]'task' => $task'file' => $file);
  1454.                 $msg 'task <%task%> attribute "%attrib%" has the wrong value "%was%" '.
  1455.                     'in file %file%, expecting one of "%values%"';
  1456.             break;
  1457.             case PEAR_TASK_ERROR_INVALID :
  1458.                 $info = array('reason' => $ret[1]'task' => $task'file' => $file);
  1459.                 $msg 'task <%task%> in file %file% is invalid because of "%reason%"';
  1460.             break;
  1461.         }
  1462.         $this->_stack->push(__FUNCTION__'error'$info$msg);
  1463.     }
  1464.  
  1465.     function _unknownTask($task$file)
  1466.     {
  1467.         $this->_stack->push(__FUNCTION__'error'array('task' => $task'file' => $file),
  1468.             'Unknown task "%task%" passed in file <file name="%file%">');
  1469.     }
  1470.  
  1471.     function _subpackageCannotProvideExtension($name)
  1472.     {
  1473.         $this->_stack->push(__FUNCTION__'error'array('name' => $name),
  1474.             'Subpackage dependency "%name%" cannot use <providesextension>, ' .
  1475.             'only package dependencies can use this tag');
  1476.     }
  1477.  
  1478.     function _subpackagesCannotConflict($name)
  1479.     {
  1480.         $this->_stack->push(__FUNCTION__'error'array('name' => $name),
  1481.             'Subpackage dependency "%name%" cannot use <conflicts/>, ' .
  1482.             'only package dependencies can use this tag');
  1483.     }
  1484.  
  1485.     function _cannotProvideExtension($release)
  1486.     {
  1487.         $this->_stack->push(__FUNCTION__'error'array('release' => $release),
  1488.             '<%release%> packages cannot use <providesextension>, only extbinrelease and extsrcrelease can provide a PHP extension');
  1489.     }
  1490.  
  1491.     function _mustProvideExtension($release)
  1492.     {
  1493.         $this->_stack->push(__FUNCTION__'error'array('release' => $release),
  1494.             '<%release%> packages must use <providesextension> to indicate which PHP extension is provided');
  1495.     }
  1496.  
  1497.     function _cannotHaveSrcpackage($release)
  1498.     {
  1499.         $this->_stack->push(__FUNCTION__'error'array('release' => $release),
  1500.             '<%release%> packages cannot specify a source code package, only extension binaries may use the <srcpackage> tag');
  1501.     }
  1502.  
  1503.     function _mustSrcPackage($release)
  1504.     {
  1505.         $this->_stack->push(__FUNCTION__'error'array('release' => $release),
  1506.             '<extbinrelease> packages must specify a source code package with <srcpackage>');
  1507.     }
  1508.  
  1509.     function _mustSrcuri($release)
  1510.     {
  1511.         $this->_stack->push(__FUNCTION__'error'array('release' => $release),
  1512.             '<extbinrelease> packages must specify a source code package with <srcuri>');
  1513.     }
  1514.  
  1515.     function _uriDepsCannotHaveVersioning($type)
  1516.     {
  1517.         $this->_stack->push(__FUNCTION__'error'array('type' => $type),
  1518.             '%type%: dependencies with a <uri> tag cannot have any versioning information');
  1519.     }
  1520.  
  1521.     function _conflictingDepsCannotHaveVersioning($type)
  1522.     {
  1523.         $this->_stack->push(__FUNCTION__'error'array('type' => $type),
  1524.             '%type%: conflicting dependencies cannot have versioning info, use <exclude> to ' .
  1525.             'exclude specific versions of a dependency');
  1526.     }
  1527.  
  1528.     function _DepchannelCannotBeUri($type)
  1529.     {
  1530.         $this->_stack->push(__FUNCTION__'error'array('type' => $type),
  1531.             '%type%: channel cannot be __uri, this is a pseudo-channel reserved for uri ' .
  1532.             'dependencies only');
  1533.     }
  1534.  
  1535.     function _bundledPackagesMustBeFilename()
  1536.     {
  1537.         $this->_stack->push(__FUNCTION__'error'array(),
  1538.             '<bundledpackage> tags must contain only the filename of a package release ' .
  1539.             'in the bundle');
  1540.     }
  1541.  
  1542.     function _binaryPackageMustBePackagename()
  1543.     {
  1544.         $this->_stack->push(__FUNCTION__'error'array(),
  1545.             '<binarypackage> tags must contain the name of a package that is ' .
  1546.             'a compiled version of this extsrc package');
  1547.     }
  1548.  
  1549.     function _fileNotFound($file)
  1550.     {
  1551.         $this->_stack->push(__FUNCTION__'error'array('file' => $file),
  1552.             'File "%file%" in package.xml does not exist');
  1553.     }
  1554.  
  1555.     function _notInContents($file$tag)
  1556.     {
  1557.         $this->_stack->push(__FUNCTION__'error'array('file' => $file'tag' => $tag),
  1558.             '<%tag% name="%file%"> is invalid, file is not in <contents>');
  1559.     }
  1560.  
  1561.     function _cannotValidateNoPathSet()
  1562.     {
  1563.         $this->_stack->push(__FUNCTION__'error'array(),
  1564.             'Cannot validate files, no path to package file is set (use setPackageFile())');
  1565.     }
  1566.  
  1567.     function _usesroletaskMustHaveChannelOrUri($role$tag)
  1568.     {
  1569.         $this->_stack->push(__FUNCTION__'error'array('role' => $role'tag' => $tag),
  1570.             '<%tag%> must contain either <uri>, or <channel> and <package>');
  1571.     }
  1572.  
  1573.     function _usesroletaskMustHavePackage($role$tag)
  1574.     {
  1575.         $this->_stack->push(__FUNCTION__'error'array('role' => $role'tag' => $tag),
  1576.             '<%tag%> must contain <package>');
  1577.     }
  1578.  
  1579.     function _usesroletaskMustHaveRoleTask($tag$type)
  1580.     {
  1581.         $this->_stack->push(__FUNCTION__'error'array('tag' => $tag'type' => $type),
  1582.             '<%tag%> must contain <%type%> defining the %type% to be used');
  1583.     }
  1584.  
  1585.     function _cannotConflictWithAllOs($type)
  1586.     {
  1587.         $this->_stack->push(__FUNCTION__'error'array('tag' => $tag),
  1588.             '%tag% cannot conflict with all OSes');
  1589.     }
  1590.  
  1591.     function _invalidDepGroupName($name)
  1592.     {
  1593.         $this->_stack->push(__FUNCTION__'error'array('group' => $name),
  1594.             'Invalid dependency group name "%name%"');
  1595.     }
  1596.  
  1597.     function _analyzeBundledPackages()
  1598.     {
  1599.         if (!$this->_isValid{
  1600.             return false;
  1601.         }
  1602.         if (!$this->_pf->getPackageType(== 'bundle'{
  1603.             return false;
  1604.         }
  1605.         if (!isset($this->_pf->_packageFile)) {
  1606.             return false;
  1607.         }
  1608.         $dir_prefix dirname($this->_pf->_packageFile);
  1609.         $log = isset($this->_pf->_logger? array(&$this->_pf->_logger'log':
  1610.             array('PEAR_Common''log');
  1611.         $info $this->_pf->getContents();
  1612.         $info $info['bundledpackage'];
  1613.         if (!is_array($info)) {
  1614.             $info = array($info);
  1615.         }
  1616.         $pkg &new PEAR_PackageFile($this->_pf->_config);
  1617.         foreach ($info as $package{
  1618.             if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $package)) {
  1619.                 $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $package);
  1620.                 $this->_isValid = 0;
  1621.                 continue;
  1622.             }
  1623.             call_user_func_array($logarray(1"Analyzing bundled package $package"));
  1624.             PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  1625.             $ret $pkg->fromAnyFile($dir_prefix . DIRECTORY_SEPARATOR . $package,
  1626.                 PEAR_VALIDATE_NORMAL);
  1627.             PEAR::popErrorHandling();
  1628.             if (PEAR::isError($ret)) {
  1629.                 call_user_func_array($logarray(0"ERROR: package $package is not a valid " .
  1630.                     'package'));
  1631.                 $inf $ret->getUserInfo();
  1632.                 if (is_array($inf)) {
  1633.                     foreach ($inf as $err{
  1634.                         call_user_func_array($logarray(1$err['message']));
  1635.                     }
  1636.                 }
  1637.                 return false;
  1638.             }
  1639.         }
  1640.         return true;
  1641.     }
  1642.  
  1643.     function _analyzePhpFiles()
  1644.     {
  1645.         if (!$this->_isValid{
  1646.             return false;
  1647.         }
  1648.         if (!isset($this->_pf->_packageFile)) {
  1649.             $this->_cannotValidateNoPathSet();
  1650.             return false;
  1651.         }
  1652.         $dir_prefix dirname($this->_pf->_packageFile);
  1653.         $common = new PEAR_Common;
  1654.         $log = isset($this->_pf->_logger? array(&$this->_pf->_logger'log':
  1655.             array(&$common'log');
  1656.         $info $this->_pf->getContents();
  1657.         $info $info['dir']['file'];
  1658.         if (isset($info['attribs'])) {
  1659.             $info = array($info);
  1660.         }
  1661.         $provides = array();
  1662.         foreach ($info as $fa{
  1663.             $fa $fa['attribs'];
  1664.             $file $fa['name'];
  1665.             if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $file)) {
  1666.                 $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $file);
  1667.                 $this->_isValid = 0;
  1668.                 continue;
  1669.             }
  1670.             if (in_array($fa['role']PEAR_Installer_Role::getPhpRoles()) && $dir_prefix{
  1671.                 call_user_func_array($logarray(1"Analyzing $file"));
  1672.                 $srcinfo $this->analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);
  1673.                 if ($srcinfo{
  1674.                     $provides array_merge($provides$this->_buildProvidesArray($srcinfo));
  1675.                 }
  1676.             }
  1677.         }
  1678.         $this->_packageName = $pn $this->_pf->getPackage();
  1679.         $pnl strlen($pn);
  1680.         foreach ($provides as $key => $what{
  1681.             if (isset($what['explicit']|| !$what{
  1682.                 // skip conformance checks if the provides entry is
  1683.                 // specified in the package.xml file
  1684.                 continue;
  1685.             }
  1686.             extract($what);
  1687.             if ($type == 'class'{
  1688.                 if (!strncasecmp($name$pn$pnl)) {
  1689.                     continue;
  1690.                 }
  1691.                 $this->_stack->push(__FUNCTION__'warning',
  1692.                     array('file' => $file'type' => $type'name' => $name'package' => $pn),
  1693.                     'in %file%: %type% "%name%" not prefixed with package name "%package%"');
  1694.             elseif ($type == 'function'{
  1695.                 if (strstr($name'::'|| !strncasecmp($name$pn$pnl)) {
  1696.                     continue;
  1697.                 }
  1698.                 $this->_stack->push(__FUNCTION__'warning',
  1699.                     array('file' => $file'type' => $type'name' => $name'package' => $pn),
  1700.                     'in %file%: %type% "%name%" not prefixed with package name "%package%"');
  1701.             }
  1702.         }
  1703.         return $this->_isValid;
  1704.     }
  1705.  
  1706.     /**
  1707.      * Analyze the source code of the given PHP file
  1708.      *
  1709.      * @param  string Filename of the PHP file
  1710.      * @param  boolean whether to analyze $file as the file contents
  1711.      * @return mixed 
  1712.      */
  1713.     function analyzeSourceCode($file$string = false)
  1714.     {
  1715.         if (!function_exists("token_get_all")) {
  1716.             $this->_stack->push(__FUNCTION__'error'array('file' => $file),
  1717.                 'Parser error: token_get_all() function must exist to analyze source code');
  1718.             return false;
  1719.         }
  1720.         if (!defined('T_DOC_COMMENT')) {
  1721.             define('T_DOC_COMMENT'T_COMMENT);
  1722.         }
  1723.         if (!defined('T_INTERFACE')) {
  1724.             define('T_INTERFACE'-1);
  1725.         }
  1726.         if (!defined('T_IMPLEMENTS')) {
  1727.             define('T_IMPLEMENTS'-1);
  1728.         }
  1729.         if ($string{
  1730.             $contents $file;
  1731.         else {
  1732.             if (!$fp @fopen($file"r")) {
  1733.                 return false;
  1734.             }
  1735.             if (function_exists('file_get_contents')) {
  1736.                 fclose($fp);
  1737.                 $contents file_get_contents($file);
  1738.             else {
  1739.                 $contents @fread($fpfilesize($file));
  1740.                 fclose($fp);
  1741.             }
  1742.         }
  1743.         $tokens token_get_all($contents);
  1744. /*
  1745.         for ($i = 0; $i < sizeof($tokens); $i++) {
  1746.             @list($token, $data) = $tokens[$i];
  1747.             if (is_string($token)) {
  1748.                 var_dump($token);
  1749.             } else {
  1750.                 print token_name($token) . ' ';
  1751.                 var_dump(rtrim($data));
  1752.             }
  1753.         }
  1754. */
  1755.         $look_for = 0;
  1756.         $paren_level = 0;
  1757.         $bracket_level = 0;
  1758.         $brace_level = 0;
  1759.         $lastphpdoc '';
  1760.         $current_class '';
  1761.         $current_interface '';
  1762.         $current_class_level = -1;
  1763.         $current_function '';
  1764.         $current_function_level = -1;
  1765.         $declared_classes = array();
  1766.         $declared_interfaces = array();
  1767.         $declared_functions = array();
  1768.         $declared_methods = array();
  1769.         $used_classes = array();
  1770.         $used_functions = array();
  1771.         $extends = array();
  1772.         $implements = array();
  1773.         $nodeps = array();
  1774.         $inquote = false;
  1775.         $interface = false;
  1776.         for ($i = 0; $i sizeof($tokens)$i++{
  1777.             if (is_array($tokens[$i])) {
  1778.                 list($token$data$tokens[$i];
  1779.             else {
  1780.                 $token $tokens[$i];
  1781.                 $data '';
  1782.             }
  1783.             if ($inquote{
  1784.                 if ($token != '"' && $token != T_END_HEREDOC{
  1785.                     continue;
  1786.                 else {
  1787.                     $inquote = false;
  1788.                     continue;
  1789.                 }
  1790.             }
  1791.             switch ($token{
  1792.                 case T_WHITESPACE :
  1793.                     continue;
  1794.                 case ';':
  1795.                     if ($interface{
  1796.                         $current_function '';
  1797.                         $current_function_level = -1;
  1798.                     }
  1799.                     break;
  1800.                 case '"':
  1801.                 case T_START_HEREDOC:
  1802.                     $inquote = true;
  1803.                     break;
  1804.                 case T_CURLY_OPEN:
  1805.                 case T_DOLLAR_OPEN_CURLY_BRACES:
  1806.                 case '{'$brace_level++; continue 2;
  1807.                 case '}':
  1808.                     $brace_level--;
  1809.                     if ($current_class_level == $brace_level{
  1810.                         $current_class '';
  1811.                         $current_class_level = -1;
  1812.                     }
  1813.                     if ($current_function_level == $brace_level{
  1814.                         $current_function '';
  1815.                         $current_function_level = -1;
  1816.                     }
  1817.                     continue 2;
  1818.                 case '['$bracket_level++; continue 2;
  1819.                 case ']'$bracket_level--; continue 2;
  1820.                 case '('$paren_level++;   continue 2;
  1821.                 case ')'$paren_level--;   continue 2;
  1822.                 case T_INTERFACE:
  1823.                     $interface = true;
  1824.                 case T_CLASS:
  1825.                     if (($current_class_level != -1|| ($current_function_level != -1)) {
  1826.                         $this->_stack->push(__FUNCTION__'error'array('file' => $file),
  1827.                         'Parser error: invalid PHP found in file "%file%"');
  1828.                         return false;
  1829.                     }
  1830.                 case T_FUNCTION:
  1831.                 case T_NEW:
  1832.                 case T_EXTENDS:
  1833.                 case T_IMPLEMENTS:
  1834.                     $look_for $token;
  1835.                     continue 2;
  1836.                 case T_STRING:
  1837.                     if (version_compare(zend_version()'2.0''<')) {
  1838.                         if (in_array(strtolower($data),
  1839.                             array('public''private''protected''abstract',
  1840.                                   'interface''implements''throw'
  1841.                                  )) {
  1842.                             $this->_stack->push(__FUNCTION__'warning'array(
  1843.                                 'file' => $file),
  1844.                                 'Error, PHP5 token encountered in %file%,' .
  1845.                                 ' analysis should be in PHP5');
  1846.                         }
  1847.                     }
  1848.                     if ($look_for == T_CLASS{
  1849.                         $current_class $data;
  1850.                         $current_class_level $brace_level;
  1851.                         $declared_classes[$current_class;
  1852.                     elseif ($look_for == T_INTERFACE{
  1853.                         $current_interface $data;
  1854.                         $current_class_level $brace_level;
  1855.                         $declared_interfaces[$current_interface;
  1856.                     elseif ($look_for == T_IMPLEMENTS{
  1857.                         $implements[$current_class$data;
  1858.                     elseif ($look_for == T_EXTENDS{
  1859.                         $extends[$current_class$data;
  1860.                     elseif ($look_for == T_FUNCTION{
  1861.                         if ($current_class{
  1862.                             $current_function = "$current_class::$data";
  1863.                             $declared_methods[$current_class][$data;
  1864.                         elseif ($current_interface{
  1865.                             $current_function = "$current_interface::$data";
  1866.                             $declared_methods[$current_interface][$data;
  1867.                         else {
  1868.                             $current_function $data;
  1869.                             $declared_functions[$current_function;
  1870.                         }
  1871.                         $current_function_level $brace_level;
  1872.                         $m = array();
  1873.                     elseif ($look_for == T_NEW{
  1874.                         $used_classes[$data= true;
  1875.                     }
  1876.                     $look_for = 0;
  1877.                     continue 2;
  1878.                 case T_VARIABLE:
  1879.                     $look_for = 0;
  1880.                     continue 2;
  1881.                 case T_DOC_COMMENT:
  1882.                 case T_COMMENT:
  1883.                     if (preg_match('!^/\*\*\s!'$data)) {
  1884.                         $lastphpdoc $data;
  1885.                         if (preg_match_all('/@nodep\s+(\S+)/'$lastphpdoc$m)) {
  1886.                             $nodeps array_merge($nodeps$m[1]);
  1887.                         }
  1888.                     }
  1889.                     continue 2;
  1890.                 case T_DOUBLE_COLON:
  1891.                     if (!($tokens[$i - 1][0== T_WHITESPACE || $tokens[$i - 1][0== T_STRING)) {
  1892.                         $this->_stack->push(__FUNCTION__'warning'array('file' => $file),
  1893.                             'Parser error: invalid PHP found in file "%file%"');
  1894.                         return false;
  1895.                     }
  1896.                     $class $tokens[$i - 1][1];
  1897.                     if (strtolower($class!= 'parent'{
  1898.                         $used_classes[$class= true;
  1899.                     }
  1900.                     continue 2;
  1901.             }
  1902.         }
  1903.         return array(
  1904.             "source_file" => $file,
  1905.             "declared_classes" => $declared_classes,
  1906.             "declared_interfaces" => $declared_interfaces,
  1907.             "declared_methods" => $declared_methods,
  1908.             "declared_functions" => $declared_functions,
  1909.             "used_classes" => array_diff(array_keys($used_classes)$nodeps),
  1910.             "inheritance" => $extends,
  1911.             "implements" => $implements,
  1912.             );
  1913.     }
  1914.  
  1915.     /**
  1916.      * Build a "provides" array from data returned by
  1917.      * analyzeSourceCode().  The format of the built array is like
  1918.      * this:
  1919.      *
  1920.      *  array(
  1921.      *    'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'),
  1922.      *    ...
  1923.      *  )
  1924.      *
  1925.      *
  1926.      * @param array $srcinfo array with information about a source file
  1927.      *  as returned by the analyzeSourceCode() method.
  1928.      *
  1929.      * @return void 
  1930.      *
  1931.      * @access private
  1932.      *
  1933.      */
  1934.     function _buildProvidesArray($srcinfo)
  1935.     {
  1936.         if (!$this->_isValid{
  1937.             return array();
  1938.         }
  1939.         $providesret = array();
  1940.         $file basename($srcinfo['source_file']);
  1941.         $pn $this->_pf->getPackage();
  1942.         $pnl strlen($pn);
  1943.         foreach ($srcinfo['declared_classes'as $class{
  1944.             $key = "class;$class";
  1945.             if (isset($providesret[$key])) {
  1946.                 continue;
  1947.             }
  1948.             $providesret[$key=
  1949.                 array('file'=> $file'type' => 'class''name' => $class);
  1950.             if (isset($srcinfo['inheritance'][$class])) {
  1951.                 $providesret[$key]['extends'=
  1952.                     $srcinfo['inheritance'][$class];
  1953.             }
  1954.         }
  1955.         foreach ($srcinfo['declared_methods'as $class => $methods{
  1956.             foreach ($methods as $method{
  1957.                 $function = "$class::$method";
  1958.                 $key = "function;$function";
  1959.                 if ($method{0== '_' || !strcasecmp($method$class||
  1960.                     isset($providesret[$key])) {
  1961.                     continue;
  1962.                 }
  1963.                 $providesret[$key=
  1964.                     array('file'=> $file'type' => 'function''name' => $function);
  1965.             }
  1966.         }
  1967.  
  1968.         foreach ($srcinfo['declared_functions'as $function{
  1969.             $key = "function;$function";
  1970.             if ($function{0== '_' || isset($providesret[$key])) {
  1971.                 continue;
  1972.             }
  1973.             if (!strstr($function'::'&& strncasecmp($function$pn$pnl)) {
  1974.                 $warnings["in1 " $file . ": function \"$function\" not prefixed with package name \"$pn\"";
  1975.             }
  1976.             $providesret[$key=
  1977.                 array('file'=> $file'type' => 'function''name' => $function);
  1978.         }
  1979.         return $providesret;
  1980.     }
  1981. }
  1982. ?>

Documentation generated on Mon, 11 Mar 2019 14:37:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.