/** * Creates and returns a new Exception instance. * * @param string $message The message itself * @param string $key The key for I18N * @return Faett_Core_Exceptions_ChannelNotRESTEnabledException */ public static function create($message, $key = '') { // create a new message $e = new Faett_Core_Exceptions_NoPackageListException($message); // set the message key $e->_setKey($key); // return the message return $e; }
/** * (non-PHPdoc) * @see lib/Faett/Core/Interfaces/Faett_Core_Interfaces_Service#listPackages($channelName) */ public function listPackages($channelName) { // store the default channel $savechannel = $this->_config->get('default_channel'); // check if the cannel already exists if ($this->channelExists($channelName)) { // if yes, set it as the default channel $this->_config->set('default_channel', $channelName); } else { // initialize the options and the parameters $opts = array(); $params = array($channelName); // try to discover channel $this->channelDiscover($opts, $params); // check if the cannel already exists if (!$this->channelExists($channelName)) { throw Faett_Core_Exceptions_UnknownChannelException::create($channelName, '201.error.channel-does-not-exists'); } } // load the channel itself from the PEAR registry $chan = $this->_registry->getChannel($channelName); // initialize a REST command for checking the channel's state $cmd = new PEAR_Command_Remote($this->_ui, $this->_config); // check the channel's state $e = $cmd->_checkChannelForStatus($channelName, $chan); if (PEAR::isError($e)) { // if an error occurs, reset to the default channel $this->_config->set('default_channel', $savechannel); // continue with the next channel throw Faett_Core_Exceptions_UnknownChannelStateException::create($e->getMessage()); } // get the channel's base URL $base = $chan->getBaseURL('REST1.0', $this->_config->get('preferred_mirror')); // check if the channel's server is REST enabled $restSupport = $chan->supportsREST($this->_config->get('preferred_mirror')); // check if the channel is REST enabled if ($restSupport && $base) { // load the channel data and the channel's packages $rest = $this->_config->getREST('1.0', array()); $packages = $rest->listPackages($base); } else { // if not, reset to the default channel $this->_config->set('default_channel', $savechannel); // continue with the next channel throw Faett_Core_Exceptions_ChannelNotRESTEnabledException::create($channelName, '201.error.channel-no-rest'); } // check if the channel's packages was loaded successfully if (PEAR::isError($packages)) { // if not, reset to the default channel $this->_config->set('default_channel', $savechannel); // continue with the next channel throw Faett_Core_Exceptions_NoPackageListException::create($packages->getMessage(), '201.error.no-package-list'); } // set the default channel again $this->_config->set('default_channel', $savechannel); // return the packages return $packages; }