コード例 #1
0
ファイル: Pear1.php プロジェクト: helgi/Pyrus
 public function add(\Pyrus\ChannelInterface $channel, $update = false, $lastmodified = false)
 {
     if ($this->readonly) {
         throw new Exception('Cannot add channel, registry is read-only');
     }
     if (!is_writable($this->_channelPath)) {
         throw new Exception('Cannot add channel ' . $channel->name . ', channel registry path is not writable');
     }
     $this->lazyInit();
     $channel->validate();
     $exists = $this->exists($channel->name);
     if ($exists && 1 !== $exists) {
         if (!$update) {
             throw new Exception('Cannot add channel ' . $channel->name . ', channel already exists, use update to change');
         }
         $checker = $this->get($channel->name);
         if ($channel->alias != $checker->alias) {
             if (file_exists($this->channelAliasFileName($checker->alias))) {
                 @unlink($this->channelAliasFileName($checker->alias));
             }
         }
     } elseif ($update) {
         throw new Exception('Error: channel ' . $channel->name . ' is unknown');
     }
     if ($channel->alias != $channel->name) {
         if (file_exists($this->channelAliasFileName($channel->alias)) && $this->channelFromAlias($channel->alias) != $channel->name) {
             $channel->alias = $channel->name;
         }
         $fp = @fopen($this->channelAliasFileName($channel->alias), 'w');
         if (!$fp) {
             throw new Exception('Cannot add/update channel ' . $channel->name . ', unable to open PEAR1 channel alias file');
         }
         fwrite($fp, $channel->name);
         fclose($fp);
     }
     $fp = @fopen($this->channelFileName($channel->name), 'wb');
     if (!$fp) {
         throw new Exception('Cannot add/update channel ' . $channel->name . ', unable to open PEAR1 channel registry file');
     }
     $info = (string) $channel;
     $parser = new \Pyrus\XMLParser();
     $info = $parser->parseString($info);
     $info = $info['channel'];
     if ($lastmodified) {
         $info['_lastmodified'] = $lastmodified;
     } else {
         $info['_lastmodified'] = date('r');
     }
     fwrite($fp, serialize($info));
     fclose($fp);
     return true;
 }
コード例 #2
0
ファイル: v1.php プロジェクト: peopleplan/Pyrus
 /**
  * Validate the xml against the channel schema.
  *
  */
 function validate()
 {
     if (!isset($this->_xml)) {
         $this->__toString();
     }
     $a = new \Pyrus\XMLParser();
     $schema = \Pyrus\Main::getDataPath() . '/channel-1.0.xsd';
     try {
         $a->parseString($this->_xml, $schema);
         return true;
     } catch (\Exception $e) {
         throw new \Pyrus\Channel\Exception('Invalid channel.xml', $e);
     }
 }
コード例 #3
0
 /**
  * get the packages in a category
  *
  * @param string $category name of category
  * 
  * @return array
  */
 public function packagesInCategory($category)
 {
     $packages = array();
     $file = $this->_restDir . 'c/' . urlencode($category) . '/packages.xml';
     if (file_exists($file)) {
         $parser = new \Pyrus\XMLParser();
         try {
             $content = file_get_contents($file);
             $content = $parser->parseString($content);
             if (isset($content['l']['p']['_content'])) {
                 $packages[] = $content['l']['p']['_content'];
             } else {
                 foreach ($content['l']['p'] as $package) {
                     $packages[] = $package['_content'];
                 }
             }
         } catch (\Exception $e) {
             // unable to parse, assume empty.
         }
     }
     foreach ($this->_packages as $p => $c) {
         if ($c === $category && !in_array($p, $packages)) {
             $packages[] = $p;
         }
     }
     return $packages;
 }