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

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