예제 #1
0
 function accept()
 {
     if (!$this->_inner->valid()) {
         return false;
     }
     $file = $this->key();
     foreach ($this->_inner->current() as $key => $value) {
         if (strpos($key, $this->_tasksNs . ':') !== 0) {
             continue;
         }
         $class = \Pyrus\Task\Common::getTask($key);
         if (!class_exists($class, true)) {
             continue;
         }
         if ($class::TYPE == 'script') {
             return true;
         }
     }
     return false;
 }
예제 #2
0
파일: File.php 프로젝트: peopleplan/Pyrus
 function __get($var)
 {
     $ret = array();
     $task = str_replace('-', ' ', $var);
     $task = str_replace(' ', '/', ucwords($task));
     $task = str_replace('/', '_', $task);
     $c = \Pyrus\Task\Common::getTask($var);
     if (isset($this[$this->tasksNs . $var])) {
         $inf = $this[$this->tasksNs . $var];
         if (isset($inf[0])) {
             $ret = array();
             foreach ($inf as $info) {
                 $ret[] = new $c($this->pkg, \Pyrus\Validate::NORMAL, $info, $this['attribs'], null);
             }
         } else {
             $ret = array(new $c($this->pkg, \Pyrus\Validate::NORMAL, $inf, $this['attribs'], null));
         }
     }
     return new \Pyrus\Task\MultipleProxy($this->pkg, $ret, $this['attribs'], $var);
 }
예제 #3
0
파일: Base.php 프로젝트: peopleplan/Pyrus
 function getTask($file, $name)
 {
     if (is_string($file)) {
         $fileAttribs = $this->files[$file];
     } elseif (is_array($file)) {
         $fileAttribs = $file;
     }
     $taskclass = \Pyrus\Task\Common::getTask($name);
     return new $taskclass($this, \Pyrus\Task\Common::PACKAGE, $fileAttribs, $fileAttribs['attribs'], null);
 }
예제 #4
0
 function current()
 {
     $xml = parent::current();
     if (isset($xml[0])) {
         $tasks = array();
         $task = str_replace(array($this->_tasksNs . ':', '-'), array('', ' '), parent::key());
         $task = str_replace(' ', '/', ucwords($task));
         $task = str_replace('/', '_', $task);
         $task = '\\Pyrus\\Task\\' . $task;
         foreach ($xml as $info) {
             $attribs = array();
             if (isset($xml['attribs'])) {
                 $attribs = $xml['attribs'];
             }
             $tasks[] = new $task($this->_parent, $this->_installphase, $info, $attribs, $this->lastversion);
         }
         $attribs = isset($this->_inner['attribs']) ? array($this->_inner['attribs']) : $this->_inner;
         // use proxy for multiple tasks
         return new \Pyrus\Task\MultipleProxy($this->_parent, $tasks, $attribs, $this->key());
     }
     $attribs = array();
     if (isset($xml['attribs'])) {
         $attribs = $xml['attribs'];
     }
     $task = \Pyrus\Task\Common::getTask(parent::key());
     if ($task === false) {
         throw new \RuntimeException('Unknown task `' . parent::key() . '` specified.');
     }
     return new $task($this->_parent, $this->_installphase, $xml, $attribs, $this->lastversion);
 }
예제 #5
0
파일: Validator.php 프로젝트: helgi/Pyrus
 /**
  * @param \Pyrus\PackageFile\v2
  * @param int
  */
 function validate(\Pyrus\PackageInterface $pf, $state = \Pyrus\Validate::NORMAL)
 {
     $this->errors = new \PEAR2\MultiErrors();
     if (!$pf->schemaOK) {
         // this package.xml was created from scratch, not loaded from an existing
         // package.xml
         $dom = new \DOMDocument();
         libxml_use_internal_errors(true);
         libxml_clear_errors();
         $dom->loadXML($pf);
         $a = $pf->toArray();
         if ($a['package']['attribs']['version'] == '2.1') {
             $schema = \Pyrus\Main::getDataPath() . '/package-2.1.xsd';
         } else {
             $schema = \Pyrus\Main::getDataPath() . '/package-2.0.xsd';
         }
         // libxml can't process these from within a phar (pity)
         if (strpos($schema, 'phar://') === 0) {
             if (!file_exists($temp = \Pyrus\Config::current()->temp_dir . DIRECTORY_SEPARATOR . 'schema')) {
                 mkdir($temp, 0755, true);
             }
             $tmpschema = $temp . DIRECTORY_SEPARATOR . basename($schema);
             copy($schema, $tmpschema);
             $dom->schemaValidate($tmpschema);
         } else {
             $dom->schemaValidate($schema);
         }
         $causes = array();
         foreach (libxml_get_errors() as $error) {
             $this->errors->E_ERROR[] = new \Pyrus\PackageFile\Exception("Line " . $error->line . ': ' . $error->message);
         }
         if (count($this->errors)) {
             throw new \Pyrus\PackageFile\Exception('Invalid package.xml, does' . ' not validate against schema', $this->errors);
         }
     }
     $this->_pf = $pf;
     $this->_curState = $state;
     $this->_packageInfo = $this->_pf->toArray();
     $this->_packageInfo = $this->_packageInfo['package'];
     if (!isset($this->_packageInfo) || !is_array($this->_packageInfo)) {
         return false;
     }
     $myversion = self::VERSION;
     if ($myversion === '@PACKAGE_VERSION@') {
         // we're running from CVS, assume we're 2.0.0
         $myversion = '2.0.0';
     }
     $test = $this->_packageInfo;
     if (isset($test['dependencies']) && isset($test['dependencies']['required']) && isset($test['dependencies']['required']['pearinstaller']) && isset($test['dependencies']['required']['pearinstaller']['min']) && version_compare($myversion, $test['dependencies']['required']['pearinstaller']['min'], '<')) {
         $this->errors->E_ERROR[] = new \Pyrus\PackageFile\Exception('This package.xml requires PEAR version ' . $test['dependencies']['required']['pearinstaller']['min'] . ' to parse properly, we are version ' . $myversion);
     }
     $fail = false;
     foreach ($pf->contents as $file) {
         // leverage the hidden iterators to do our validation
         $name = $file->dir . $file->name;
         if ($name[0] == '.' && $name[1] == '/') {
             // name is something like "./doc/whatever.txt"
             $this->errors->E_ERROR[] = new \Pyrus\Package\Exception('File "' . $name . '" cannot begin with "."');
             continue;
         }
         if (!$this->_validateRole($file->role)) {
             if (isset($this->_packageInfo['usesrole'])) {
                 $roles = $this->_packageInfo['usesrole'];
                 if (!isset($roles[0])) {
                     $roles = array($roles);
                 }
                 foreach ($roles as $role) {
                     if ($role['role'] = $file->role) {
                         if (isset($role['uri'])) {
                             $package = $role['uri'];
                         } else {
                             $package = \Pyrus\Config::parsedPackageNameToString(array('package' => $role['package'], 'channel' => $role['channel']), true);
                         }
                         $msg = 'This package contains role "' . $file->role . '" and requires package "' . $package . '" to be used';
                         $this->errors->E_WARNING[] = new \Pyrus\PackageFile\Exception($msg);
                     }
                 }
             }
             $this->errors->E_ERROR[] = new \Pyrus\PackageFile\Exception('File "' . $name . '" has invalid role "' . $file->role . '", should be one of ' . implode(', ', \Pyrus\Installer\Role::getValidRoles($this->_pf->getPackageType())));
         }
         if (count($file->tasks) && $this->_curState != \Pyrus\Validate::DOWNLOADING) {
             // has tasks
             $save = $file->getArrayCopy();
             foreach ($file->tasks as $task => $value) {
                 if ($tagClass = \Pyrus\Task\Common::getTask($task)) {
                     if (!is_array($value) || !isset($value[0])) {
                         $value = array($value);
                     }
                     foreach ($value as $v) {
                         try {
                             $ret = $tagClass::validateXml($this->_pf, $v, $save['attribs'], $file->name);
                         } catch (\Pyrus\Task\Exception $e) {
                             $this->errors->E_ERROR[] = new \Pyrus\PackageFile\Exception('Invalid task $task', $e);
                         }
                     }
                 } else {
                     if (isset($this->_packageInfo['usestask'])) {
                         $roles = $this->_packageInfo['usestask'];
                         if (!isset($roles[0])) {
                             $roles = array($roles);
                         }
                         foreach ($roles as $role) {
                             if ($role['task'] = $task) {
                                 if (isset($role['uri'])) {
                                     $package = $role['uri'];
                                 } else {
                                     $package = \Pyrus\Config::parsedPackageNameToString(array('package' => $role['package'], 'channel' => $role['channel']), true);
                                 }
                                 $msg = 'This package contains task "' . str_replace($this->_pf->getTasksNs() . ':', '', $task) . '" and requires package "' . $package . '" to be used';
                                 $this->errors->E_WARNING[] = new \Pyrus\PackageFile\Exception($msg);
                             }
                         }
                     }
                     $this->errors->E_ERROR[] = new \Pyrus\PackageFile\Exception('Unknown task "' . $task . '" passed in file <file name="' . $name . '">');
                 }
             }
         }
     }
     $this->_validateRelease();
     if (count($this->errors->E_ERROR)) {
         throw new \Pyrus\PackageFile\Exception('Invalid package.xml', $this->errors);
     }
     try {
         $validator = \Pyrus\Config::current()->channelregistry[$this->_pf->channel]->getValidationObject($this->_pf->name);
     } catch (\Pyrus\Config\Exception $e) {
         throw new \Pyrus\PackageFile\Exception('Unable to process channel-specific configuration for channel ' . $this->_pf->getChannel(), $e);
     } catch (\Exception $e) {
         $valpack = \Pyrus\Config::current()->channelregistry[$this->_pf->channel]->getValidationPackage();
         $this->errors->E_ERROR[] = new \Pyrus\PackageFile\Exception('Unknown channel ' . $this->_pf->channel);
         $this->errors->E_ERROR[] = new \Pyrus\PackageFile\Exception('package "' . $this->_pf->channel . '/' . $this->_pf->name . '" cannot be properly validated without validation package "' . $this->_pf->channel . '/' . $valpack['name'] . '-' . $valpack['version'] . '"');
     }
     try {
         $validator->setPackageFile($this->_pf);
         $validator->setChannel(\Pyrus\Config::current()->channelregistry[$this->_pf->channel]);
         $validator->validate($state);
         // merge in errors from channel-specific validation
         $this->errors[] = $validator->getFailures();
     } catch (\Exception $e) {
         $this->errors->E_ERROR[] = $e;
     }
     if (count($this->errors->E_ERROR)) {
         throw new \Pyrus\PackageFile\Exception('Invalid package.xml', $this->errors);
     }
     if ($state == \Pyrus\Validate::PACKAGING) {
         if ($this->_pf->type == 'bundle') {
             if (!$this->_analyzeBundledPackages()) {
                 throw new \Pyrus\PackageFile\Exception('Invalid package.xml', $this->errors);
             }
         } else {
             if (!$this->_analyzePhpFiles()) {
                 throw new \Pyrus\PackageFile\Exception('Invalid package.xml', $this->errors);
             }
         }
     }
     return $state;
 }
예제 #6
0
파일: Unixeol.php 프로젝트: helgi/Pyrus
 /**
  * Initialize a task instance with the parameters
  * @param array raw, parsed xml
  * @param array attributes from the <file> tag containing this task
  * @param string|null last installed version of this package
  */
 function __construct($pkg, $phase, $xml, $attribs, $lastversion)
 {
     parent::__construct($pkg, $phase, $xml, $attribs, $lastversion);
 }
예제 #7
0
 /**
  * Initialize a task instance with the parameters
  * @param array raw, parsed xml
  * @param array attributes from the <file> tag containing this task
  * @param string|null last installed version of this package, if any (useful for upgrades)
  */
 function __construct($pkg, $phase, $xml, $attribs, $lastversion)
 {
     parent::__construct($pkg, $phase, $xml, $attribs, $lastversion);
     $this->scriptClass = str_replace(array('/', '.php'), array('_', ''), $attribs['name']) . '_postinstall';
     $this->_filename = $attribs['name'];
 }