/**
  * vérifie les propriétes du document, leur présence et leur validité
  * à surcharger eventuellement dans les classes descendantes, pour tenir compte des spécifités de chaque type de document
  * @return boolean  true= tout est ok
  * @access private
  */
 function _validateProperties()
 {
     $errors =& PEAR_ErrorStack::singleton('OpenWeb_Backend_DocbookParse');
     $errors->getErrors(true);
     $errors->pushCallback(array(&$this, '_repackageErrorStack'));
     $res = $this->infos->verify();
     $errors->popCallback();
     if ($this->errors->hasErrors()) {
         return false;
     }
     $classement =& $this->infos->classement;
     if ($this->type->isintro) {
         foreach ($classement as $crit => $entries) {
             foreach ($entries as $nom => $rub) {
                 if ($nom == $this->infos->repertoire) {
                     unset($classement[$crit][$nom]);
                 }
             }
         }
     }
     $errors =& PEAR_ErrorStack::singleton('OpenWeb_Backend_ReferenceManager');
     $errors->pushCallback(array(&$this, '_repackageErrorStack'));
     $this->ref->checkClassements($classement);
     $errors->popCallback();
     if ($this->errors->hasErrors()) {
         return false;
     }
     $errors =& PEAR_ErrorStack::singleton('OpenWeb_Backend_DocumentType');
     $errors->pushCallback(array(&$this, '_repackageErrorStack'));
     $this->type->check($this->infos);
     $errors->popCallback();
     return $this->errors->hasErrors();
 }
 /**
  * vérifie qu'un objet DocInfos correspond à ce type de document
  * @param object $docinfos
  * @return boolean true si le document correspond au type
  */
 function check($docinfos)
 {
     $res = array();
     if (!$this->id) {
         return false;
     }
     /* On vérifie que l'accroche est correcte */
     if ($this->accroche && $docinfos->accroche == '') {
         $this->errors->push(OW_NO_ABSTRACT, 'error');
     }
     /* Nombre total de classements dans $docinfos */
     $nb = 0;
     /* On compte le nombre d'entrées dans $docinfos pour chaque critère
        qui se trouve dans $this->max ou $this->min. On calcule au passage
        également le nombre total d'entrées. */
     $compte = array();
     foreach (array_unique(array_merge(array_keys($this->max), array_keys($this->min))) as $critere) {
         $nb += $compte[$critere] = isset($docinfos->classement[$critere]) ? count($docinfos->classement[$critere]) : 0;
     }
     /* On vérifie que le nombre de classement pour chaque critère est dans
        le bon intervalle */
     foreach (array_keys($this->max) as $critere) {
         /* Il n'y a pas de maximum si $this->max[$critere] est négatif */
         if ($this->max[$critere] >= 0 && $compte[$critere] > $this->max[$critere]) {
             $this->errors->push(OW_TOO_MANY_SUBJECTS, 'error', array('criterion' => $critere, 'limit' => $this->max[$critere]));
         }
     }
     foreach (array_keys($this->min) as $critere) {
         if ($compte[$critere] < $this->min[$critere]) {
             $this->errors->push(OW_TOO_FEW_SUBJECTS, 'error', array('criterion' => $critere, 'limit' => $this->min[$critere]));
         }
     }
     /* Le nombre total de classements est-il compris entre les
        deux valeurs imposées ? */
     if ($nb > $this->total_max) {
         $this->errors->push(OW_TOO_MANY_SUBJECTS, 'error', array('limit' => $this->total_max));
     }
     if ($nb < $this->total_min) {
         $this->errors->push(OW_TOO_FEW_SUBJECTS, 'error', array('limit' => $this->total_min));
     }
     return !$this->errors->hasErrors();
 }
Example #3
0
 /**
  * @param PEAR_PackageFile_v2
  * @param int
  */
 function validate(&$pf, $state = PEAR_VALIDATE_NORMAL)
 {
     $this->_pf =& $pf;
     $this->_curState = $state;
     $this->_packageInfo = $this->_pf->getArray();
     $this->_isValid = $this->_pf->_isValid;
     $this->_filesValid = $this->_pf->_filesValid;
     $this->_stack =& $pf->_stack;
     $this->_stack->getErrors(true);
     if (($this->_isValid & $state) == $state) {
         return true;
     }
     if (!isset($this->_packageInfo) || !is_array($this->_packageInfo)) {
         return false;
     }
     if (!isset($this->_packageInfo['attribs']['version']) || $this->_packageInfo['attribs']['version'] != '2.0' && $this->_packageInfo['attribs']['version'] != '2.1') {
         $this->_noPackageVersion();
     }
     $structure = array('name', 'channel|uri', '*extends', 'summary', 'description', '+lead', '*developer', '*contributor', '*helper', 'date', '*time', 'version', 'stability', 'license->?uri->?filesource', 'notes', 'contents', '*compatible', 'dependencies', '*usesrole', '*usestask', '*providesextension', '*srcpackage|*srcuri', '+phprelease|+extsrcrelease|+extbinrelease|' . '+zendextsrcrelease|+zendextbinrelease|bundle', '*changelog');
     $test = $this->_packageInfo;
     if (isset($test['dependencies']) && isset($test['dependencies']['required']) && isset($test['dependencies']['required']['pearinstaller']) && isset($test['dependencies']['required']['pearinstaller']['min']) && version_compare('1.8.0', $test['dependencies']['required']['pearinstaller']['min'], '<')) {
         $this->_pearVersionTooLow($test['dependencies']['required']['pearinstaller']['min']);
         return false;
     }
     // ignore post-installation array fields
     if (array_key_exists('filelist', $test)) {
         unset($test['filelist']);
     }
     if (array_key_exists('_lastmodified', $test)) {
         unset($test['_lastmodified']);
     }
     if (array_key_exists('#binarypackage', $test)) {
         unset($test['#binarypackage']);
     }
     if (array_key_exists('old', $test)) {
         unset($test['old']);
     }
     if (array_key_exists('_lastversion', $test)) {
         unset($test['_lastversion']);
     }
     if (!$this->_stupidSchemaValidate($structure, $test, '<package>')) {
         return false;
     }
     if (empty($this->_packageInfo['name'])) {
         $this->_tagCannotBeEmpty('name');
     }
     $test = isset($this->_packageInfo['uri']) ? 'uri' : 'channel';
     if (empty($this->_packageInfo[$test])) {
         $this->_tagCannotBeEmpty($test);
     }
     if (is_array($this->_packageInfo['license']) && (!isset($this->_packageInfo['license']['_content']) || empty($this->_packageInfo['license']['_content']))) {
         $this->_tagCannotBeEmpty('license');
     } elseif (empty($this->_packageInfo['license'])) {
         $this->_tagCannotBeEmpty('license');
     }
     if (empty($this->_packageInfo['summary'])) {
         $this->_tagCannotBeEmpty('summary');
     }
     if (empty($this->_packageInfo['description'])) {
         $this->_tagCannotBeEmpty('description');
     }
     if (empty($this->_packageInfo['date'])) {
         $this->_tagCannotBeEmpty('date');
     }
     if (empty($this->_packageInfo['notes'])) {
         $this->_tagCannotBeEmpty('notes');
     }
     if (isset($this->_packageInfo['time']) && empty($this->_packageInfo['time'])) {
         $this->_tagCannotBeEmpty('time');
     }
     if (isset($this->_packageInfo['dependencies'])) {
         $this->_validateDependencies();
     }
     if (isset($this->_packageInfo['compatible'])) {
         $this->_validateCompatible();
     }
     if (!isset($this->_packageInfo['bundle'])) {
         if (empty($this->_packageInfo['contents'])) {
             $this->_tagCannotBeEmpty('contents');
         }
         if (!isset($this->_packageInfo['contents']['dir'])) {
             $this->_filelistMustContainDir('contents');
             return false;
         }
         if (isset($this->_packageInfo['contents']['file'])) {
             $this->_filelistCannotContainFile('contents');
             return false;
         }
     }
     $this->_validateMaintainers();
     $this->_validateStabilityVersion();
     $fail = false;
     if (array_key_exists('usesrole', $this->_packageInfo)) {
         $roles = $this->_packageInfo['usesrole'];
         if (!is_array($roles) || !isset($roles[0])) {
             $roles = array($roles);
         }
         foreach ($roles as $role) {
             if (!isset($role['role'])) {
                 $this->_usesroletaskMustHaveRoleTask('usesrole', 'role');
                 $fail = true;
             } else {
                 if (!isset($role['channel'])) {
                     if (!isset($role['uri'])) {
                         $this->_usesroletaskMustHaveChannelOrUri($role['role'], 'usesrole');
                         $fail = true;
                     }
                 } elseif (!isset($role['package'])) {
                     $this->_usesroletaskMustHavePackage($role['role'], 'usesrole');
                     $fail = true;
                 }
             }
         }
     }
     if (array_key_exists('usestask', $this->_packageInfo)) {
         $roles = $this->_packageInfo['usestask'];
         if (!is_array($roles) || !isset($roles[0])) {
             $roles = array($roles);
         }
         foreach ($roles as $role) {
             if (!isset($role['task'])) {
                 $this->_usesroletaskMustHaveRoleTask('usestask', 'task');
                 $fail = true;
             } else {
                 if (!isset($role['channel'])) {
                     if (!isset($role['uri'])) {
                         $this->_usesroletaskMustHaveChannelOrUri($role['task'], 'usestask');
                         $fail = true;
                     }
                 } elseif (!isset($role['package'])) {
                     $this->_usesroletaskMustHavePackage($role['task'], 'usestask');
                     $fail = true;
                 }
             }
         }
     }
     if ($fail) {
         return false;
     }
     $list = $this->_packageInfo['contents'];
     if (isset($list['dir']) && is_array($list['dir']) && isset($list['dir'][0])) {
         $this->_multipleToplevelDirNotAllowed();
         return $this->_isValid = 0;
     }
     $this->_validateFilelist();
     $this->_validateRelease();
     if (!$this->_stack->hasErrors()) {
         $chan = $this->_pf->_registry->getChannel($this->_pf->getChannel(), true);
         if (PEAR::isError($chan)) {
             $this->_unknownChannel($this->_pf->getChannel());
         } else {
             $valpack = $chan->getValidationPackage();
             // for channel validator packages, always use the default PEAR validator.
             // otherwise, they can't be installed or packaged
             $validator = $chan->getValidationObject($this->_pf->getPackage());
             if (!$validator) {
                 $this->_stack->push(__FUNCTION__, 'error', array_merge(array('channel' => $chan->getName(), 'package' => $this->_pf->getPackage()), $valpack), 'package "%channel%/%package%" cannot be properly validated without ' . 'validation package "%channel%/%name%-%version%"');
                 return $this->_isValid = 0;
             }
             $validator->setPackageFile($this->_pf);
             $validator->validate($state);
             $failures = $validator->getFailures();
             foreach ($failures['errors'] as $error) {
                 $this->_stack->push(__FUNCTION__, 'error', $error, 'Channel validator error: field "%field%" - %reason%');
             }
             foreach ($failures['warnings'] as $warning) {
                 $this->_stack->push(__FUNCTION__, 'warning', $warning, 'Channel validator warning: field "%field%" - %reason%');
             }
         }
     }
     $this->_pf->_isValid = $this->_isValid = !$this->_stack->hasErrors('error');
     if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$this->_filesValid) {
         if ($this->_pf->getPackageType() == 'bundle') {
             if ($this->_analyzeBundledPackages()) {
                 $this->_filesValid = $this->_pf->_filesValid = true;
             } else {
                 $this->_pf->_isValid = $this->_isValid = 0;
             }
         } else {
             if (!$this->_analyzePhpFiles()) {
                 $this->_pf->_isValid = $this->_isValid = 0;
             } else {
                 $this->_filesValid = $this->_pf->_filesValid = true;
             }
         }
     }
     if ($this->_isValid) {
         return $this->_pf->_isValid = $this->_isValid = $state;
     }
     return $this->_pf->_isValid = $this->_isValid = 0;
 }