/** * Validate the xml against the channel schema. * */ function validate() { if (!isset($this->_xml)) { $this->__toString(); } $a = new \PEAR2\Pyrus\XMLParser(); $schema = \PEAR2\Pyrus\Main::getDataPath() . '/channel-1.0.xsd'; // for running out of svn if (!file_exists($schema)) { $schema = dirname(dirname(dirname(dirname(__DIR__)))) . '/data/channel-1.0.xsd'; } try { $a->parseString($this->_xml, $schema); return true; } catch (\Exception $e) { throw new \PEAR2\Pyrus\Channel\Exception('Invalid channel.xml', $e); } }
public function add(\PEAR2\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 \PEAR2\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; }