Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Command_Channels Class Reference
Inheritance diagram for PEAR_Command_Channels:
Collaboration diagram for PEAR_Command_Channels:

Public Member Functions

 __construct (&$ui, &$config)
 _sortChannels ($a, $b)
 doAdd ($command, $options, $params)
 doAlias ($command, $options, $params)
 doDelete ($command, $options, $params)
 doDiscover ($command, $options, $params)
 doInfo ($command, $options, $params)
 doList ($command, $options, $params)
 doLogin ($command, $options, $params)
 doLogout ($command, $options, $params)
 doUpdate ($command, $options, $params)
 doUpdateAll ($command, $options, $params)
& getDownloader ()
Public Member Functions inherited from PEAR_Command_Common
 getCommands ()
 getGetoptArgs ($command, &$short_args, &$long_args)
 getHelp ($command)
 getHelpArgs ($command)
 getOptions ($command)
 getShortcuts ()
 run ($command, $options, $params)
Public Member Functions inherited from PEAR
 __call ($method, $arguments)
 __construct ($error_class=null)
 _checkDelExpect ($error_code)
 _PEAR ()
 delExpect ($error_code)
 expectError ($code=' *')
 PEAR ($error_class=null)
 popExpect ()

Data Fields

 $commands
Data Fields inherited from PEAR_Command_Common
 $_deps_rel_trans
 $_deps_type_trans
 $_registry
 $config
 $ui
Data Fields inherited from PEAR
 $_debug = false
 $_default_error_handler = ''
 $_default_error_mode = null
 $_default_error_options = null
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Additional Inherited Members

Static Public Member Functions inherited from PEAR
static __callStatic ($method, $arguments)
static getSourceDateEpoch ()
static & getStaticProperty ($class, $var)
static isError ($data, $code=null)
static loadExtension ($ext)
static registerShutdownFunc ($func, $args=array())
static staticPopErrorHandling ()
static staticPushErrorHandling ($mode, $options=null)
Static Protected Member Functions inherited from PEAR
static _popErrorHandling ($object)
static _pushErrorHandling ($object, $mode, $options=null)
static _raiseError ($object, $message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
static _setErrorHandling ( $object, $mode=null, $options=null)
static _throwError ($object, $message=null, $code=null, $userinfo=null)
Static Protected Attributes inherited from PEAR
static $bivalentMethods

Detailed Description

Definition at line 38 of file Channels.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( & $ui,
& $config )

PEAR_Command_Registry constructor.

@access public

Reimplemented from PEAR_Command_Common.

Reimplemented in PEAR_Command_Auth.

Definition at line 169 of file Channels.php.

170 {
171 parent::__construct($ui, $config);
172 }

References PEAR_Command_Common\$config, and PEAR_Command_Common\$ui.

Member Function Documentation

◆ _sortChannels()

_sortChannels ( $a,
$b )

Definition at line 174 of file Channels.php.

175 {
176 return strnatcasecmp($a->getName(), $b->getName());
177 }

◆ doAdd()

doAdd ( $command,
$options,
$params )

Definition at line 408 of file Channels.php.

409 {
410 if (count($params) !== 1) {
411 return $this->raiseError('channel-add: no channel file specified');
412 }
413
414 if (strpos($params[0], '://')) {
415 $downloader = &$this->getDownloader();
416 $tmpdir = $this->config->get('temp_dir');
417 if (!file_exists($tmpdir)) {
418 require_once 'System.php';
420 $err = System::mkdir(array('-p', $tmpdir));
422 if (PEAR::isError($err)) {
423 return $this->raiseError('channel-add: temp_dir does not exist: "' .
424 $tmpdir .
425 '" - You can change this location with "pear config-set temp_dir"');
426 }
427 }
428
429 if (!is_writable($tmpdir)) {
430 return $this->raiseError('channel-add: temp_dir is not writable: "' .
431 $tmpdir .
432 '" - You can change this location with "pear config-set temp_dir"');
433 }
434
436 $loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir, null, false);
438 if (PEAR::isError($loc)) {
439 return $this->raiseError('channel-add: Cannot open "' . $params[0] .
440 '" (' . $loc->getMessage() . ')');
441 }
442
443 list($loc, $lastmodified) = $loc;
444 $contents = implode('', file($loc));
445 } else {
446 $lastmodified = $fp = false;
447 if (file_exists($params[0])) {
448 $fp = fopen($params[0], 'r');
449 }
450
451 if (!$fp) {
452 return $this->raiseError('channel-add: cannot open "' . $params[0] . '"');
453 }
454
455 $contents = '';
456 while (!feof($fp)) {
457 $contents .= fread($fp, 1024);
458 }
459 fclose($fp);
460 }
461
462 if (!class_exists('PEAR_ChannelFile')) {
463 require_once 'PEAR/ChannelFile.php';
464 }
465
466 $channel = new PEAR_ChannelFile;
468 $result = $channel->fromXmlString($contents);
470 if (!$result) {
471 $exit = false;
472 if (count($errors = $channel->getErrors(true))) {
473 foreach ($errors as $error) {
474 $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));
475 if (!$exit) {
476 $exit = $error['level'] == 'error' ? true : false;
477 }
478 }
479 if ($exit) {
480 return $this->raiseError('channel-add: invalid channel.xml file');
481 }
482 }
483 }
484
485 $reg = &$this->config->getRegistry();
486 if ($reg->channelExists($channel->getName())) {
487 return $this->raiseError('channel-add: Channel "' . $channel->getName() .
488 '" exists, use channel-update to update entry', PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS);
489 }
490
491 $ret = $reg->addChannel($channel, $lastmodified);
492 if (PEAR::isError($ret)) {
493 return $ret;
494 }
495
496 if (!$ret) {
497 return $this->raiseError('channel-add: adding Channel "' . $channel->getName() .
498 '" to registry failed');
499 }
500
501 $this->config->setChannels($reg->listChannels());
502 $this->config->writeConfigFile();
503 $this->ui->outputData('Adding Channel "' . $channel->getName() . '" succeeded', $command);
504 }
const PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS
Definition Channels.php:24
const PEAR_ERROR_RETURN
Definition PEAR.php:24
$result
static staticPopErrorHandling()
Definition PEAR.php:654
static staticPushErrorHandling($mode, $options=null)
Definition PEAR.php:619
if( $raw) foreach($opts as $opt) if( $store_system_config) if($store_user_config) $command
Definition pearcmd.php:322

References $command, $options, $result, getDownloader(), PEAR\isError(), PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS, PEAR_ERROR_RETURN, PEAR\staticPopErrorHandling(), and PEAR\staticPushErrorHandling().

Referenced by doDiscover().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doAlias()

doAlias ( $command,
$options,
$params )

Definition at line 671 of file Channels.php.

672 {
673 if (count($params) === 1) {
674 return $this->raiseError('No channel alias specified');
675 }
676
677 if (count($params) !== 2 || (!empty($params[1]) && $params[1][0] == '-')) {
678 return $this->raiseError(
679 'Invalid format, correct is: channel-alias channel alias');
680 }
681
682 $reg = &$this->config->getRegistry();
683 if (!$reg->channelExists($params[0], true)) {
684 $extra = '';
685 if ($reg->isAlias($params[0])) {
686 $extra = ' (use "channel-alias ' . $reg->channelName($params[0]) . ' ' .
687 strtolower($params[1]) . '")';
688 }
689
690 return $this->raiseError('"' . $params[0] . '" is not a valid channel' . $extra);
691 }
692
693 if ($reg->isAlias($params[1])) {
694 return $this->raiseError('Channel "' . $reg->channelName($params[1]) . '" is ' .
695 'already aliased to "' . strtolower($params[1]) . '", cannot re-alias');
696 }
697
698 $chan = $reg->getChannel($params[0]);
699 if (PEAR::isError($chan)) {
700 return $this->raiseError('Corrupt registry? Error retrieving channel "' . $params[0] .
701 '" information (' . $chan->getMessage() . ')');
702 }
703
704 // make it a local alias
705 if (!$chan->setAlias(strtolower($params[1]), true)) {
706 return $this->raiseError('Alias "' . strtolower($params[1]) .
707 '" is not a valid channel alias');
708 }
709
710 $reg->updateChannel($chan);
711 $this->ui->outputData('Channel "' . $chan->getName() . '" aliased successfully to "' .
712 strtolower($params[1]) . '"');
713 }

References $command, $options, and PEAR\isError().

Here is the call graph for this function:

◆ doDelete()

doDelete ( $command,
$options,
$params )

Definition at line 363 of file Channels.php.

364 {
365 if (count($params) !== 1) {
366 return $this->raiseError('channel-delete: no channel specified');
367 }
368
369 $reg = &$this->config->getRegistry();
370 if (!$reg->channelExists($params[0])) {
371 return $this->raiseError('channel-delete: channel "' . $params[0] . '" does not exist');
372 }
373
374 $channel = $reg->channelName($params[0]);
375 if ($channel == 'pear.php.net') {
376 return $this->raiseError('Cannot delete the pear.php.net channel');
377 }
378
379 if ($channel == 'pecl.php.net') {
380 return $this->raiseError('Cannot delete the pecl.php.net channel');
381 }
382
383 if ($channel == 'doc.php.net') {
384 return $this->raiseError('Cannot delete the doc.php.net channel');
385 }
386
387 if ($channel == '__uri') {
388 return $this->raiseError('Cannot delete the __uri pseudo-channel');
389 }
390
391 if (PEAR::isError($err = $reg->listPackages($channel))) {
392 return $err;
393 }
394
395 if (count($err)) {
396 return $this->raiseError('Channel "' . $channel .
397 '" has installed packages, cannot delete');
398 }
399
400 if (!$reg->deleteChannel($channel)) {
401 return $this->raiseError('Channel "' . $channel . '" deletion failed');
402 } else {
403 $this->config->deleteChannel($channel);
404 $this->ui->outputData('Channel "' . $channel . '" deleted', $command);
405 }
406 }

References $command, $options, and PEAR\isError().

Here is the call graph for this function:

◆ doDiscover()

doDiscover ( $command,
$options,
$params )

The channel-discover command

Parameters
string$commandcommand name
array$optionsoption_name => value
array$paramslist of additional parameters. $params[0] should contain a string with either:
  • <channel name> or
  • <username>:<password><channel name>
Returns
null|PEAR_Error

Definition at line 726 of file Channels.php.

727 {
728 if (count($params) !== 1) {
729 return $this->raiseError("No channel server specified");
730 }
731
732 // Look for the possible input format "<username>:<password>@<channel>"
733 if (preg_match('/^(.+):(.+)@(.+)\\z/', $params[0], $matches)) {
734 $username = $matches[1];
735 $password = $matches[2];
736 $channel = $matches[3];
737 } else {
738 $channel = $params[0];
739 }
740
741 $reg = &$this->config->getRegistry();
742 if ($reg->channelExists($channel)) {
743 if (!$reg->isAlias($channel)) {
744 return $this->raiseError("Channel \"$channel\" is already initialized", PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS);
745 }
746
747 return $this->raiseError("A channel alias named \"$channel\" " .
748 'already exists, aliasing channel "' . $reg->channelName($channel)
749 . '"');
750 }
751
752 $this->pushErrorHandling(PEAR_ERROR_RETURN);
753 $err = $this->doAdd($command, $options, array('http://' . $channel . '/channel.xml'));
754 $this->popErrorHandling();
755 if (PEAR::isError($err)) {
756 if ($err->getCode() === PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS) {
757 return $this->raiseError("Discovery of channel \"$channel\" failed (" .
758 $err->getMessage() . ')');
759 }
760 // Attempt fetch via https
761 $this->ui->outputData("Discovering channel $channel over http:// failed with message: " . $err->getMessage());
762 $this->ui->outputData("Trying to discover channel $channel over https:// instead");
763 $this->pushErrorHandling(PEAR_ERROR_RETURN);
764 $err = $this->doAdd($command, $options, array('https://' . $channel . '/channel.xml'));
765 $this->popErrorHandling();
766 if (PEAR::isError($err)) {
767 return $this->raiseError("Discovery of channel \"$channel\" failed (" .
768 $err->getMessage() . ')');
769 }
770 }
771
772 // Store username/password if they were given
773 // Arguably we should do a logintest on the channel here, but since
774 // that's awkward on a REST-based channel (even "pear login" doesn't
775 // do it for those), and XML-RPC is deprecated, it's fairly pointless.
776 if (isset($username)) {
777 $this->config->set('username', $username, 'user', $channel);
778 $this->config->set('password', $password, 'user', $channel);
779 $this->config->store();
780 $this->ui->outputData("Stored login for channel \"$channel\" using username \"$username\"", $command);
781 }
782
783 $this->ui->outputData("Discovery of channel \"$channel\" succeeded", $command);
784 }
doAdd($command, $options, $params)
Definition Channels.php:408
$options
Definition pearcmd.php:145

References $command, $options, doAdd(), PEAR\isError(), PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS, and PEAR_ERROR_RETURN.

Here is the call graph for this function:

◆ doInfo()

doInfo ( $command,
$options,
$params )

Definition at line 226 of file Channels.php.

227 {
228 if (count($params) !== 1) {
229 return $this->raiseError("No channel specified");
230 }
231
232 $reg = &$this->config->getRegistry();
233 $channel = strtolower($params[0]);
234 if ($reg->channelExists($channel)) {
235 $chan = $reg->getChannel($channel);
236 if (PEAR::isError($chan)) {
237 return $this->raiseError($chan);
238 }
239 } else {
240 if (strpos($channel, '://')) {
241 $downloader = &$this->getDownloader();
242 $tmpdir = $this->config->get('temp_dir');
244 $loc = $downloader->downloadHttp($channel, $this->ui, $tmpdir);
246 if (PEAR::isError($loc)) {
247 return $this->raiseError('Cannot open "' . $channel .
248 '" (' . $loc->getMessage() . ')');
249 } else {
250 $contents = implode('', file($loc));
251 }
252 } else {
253 if (!file_exists($params[0])) {
254 return $this->raiseError('Unknown channel "' . $channel . '"');
255 }
256
257 $fp = fopen($params[0], 'r');
258 if (!$fp) {
259 return $this->raiseError('Cannot open "' . $params[0] . '"');
260 }
261
262 $contents = '';
263 while (!feof($fp)) {
264 $contents .= fread($fp, 1024);
265 }
266 fclose($fp);
267 }
268
269 if (!class_exists('PEAR_ChannelFile')) {
270 require_once 'PEAR/ChannelFile.php';
271 }
272
273 $chan = new PEAR_ChannelFile;
274 $chan->fromXmlString($contents);
275 $chan->validate();
276 if ($errs = $chan->getErrors(true)) {
277 foreach ($errs as $err) {
278 $this->ui->outputData($err['level'] . ': ' . $err['message']);
279 }
280 return $this->raiseError('Channel file "' . $params[0] . '" is not valid');
281 }
282 }
283
284 if (!$chan) {
285 return $this->raiseError('Serious error: Channel "' . $params[0] .
286 '" has a corrupted registry entry');
287 }
288
289 $channel = $chan->getName();
290 $caption = 'Channel ' . $channel . ' Information:';
291 $data1 = array(
292 'caption' => $caption,
293 'border' => true);
294 $data1['data']['server'] = array('Name and Server', $chan->getName());
295 if ($chan->getAlias() != $chan->getName()) {
296 $data1['data']['alias'] = array('Alias', $chan->getAlias());
297 }
298
299 $data1['data']['summary'] = array('Summary', $chan->getSummary());
300 $validate = $chan->getValidationPackage();
301 $data1['data']['vpackage'] = array('Validation Package Name', $validate['_content']);
302 $data1['data']['vpackageversion'] =
303 array('Validation Package Version', $validate['attribs']['version']);
304 $d = array();
305 $d['main'] = $data1;
306
307 $data['data'] = array();
308 $data['caption'] = 'Server Capabilities';
309 $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
310 if ($chan->supportsREST()) {
311 if ($chan->supportsREST()) {
312 $funcs = $chan->getFunctions('rest');
313 if (!isset($funcs[0])) {
314 $funcs = array($funcs);
315 }
316 foreach ($funcs as $protocol) {
317 $data['data'][] = array('rest', $protocol['attribs']['type'],
318 $protocol['_content']);
319 }
320 }
321 } else {
322 $data['data'][] = array('No supported protocols');
323 }
324
325 $d['protocols'] = $data;
326 $data['data'] = array();
327 $mirrors = $chan->getMirrors();
328 if ($mirrors) {
329 $data['caption'] = 'Channel ' . $channel . ' Mirrors:';
330 unset($data['headline']);
331 foreach ($mirrors as $mirror) {
332 $data['data'][] = array($mirror['attribs']['host']);
333 $d['mirrors'] = $data;
334 }
335
336 foreach ($mirrors as $i => $mirror) {
337 $data['data'] = array();
338 $data['caption'] = 'Mirror ' . $mirror['attribs']['host'] . ' Capabilities';
339 $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
340 if ($chan->supportsREST($mirror['attribs']['host'])) {
341 if ($chan->supportsREST($mirror['attribs']['host'])) {
342 $funcs = $chan->getFunctions('rest', $mirror['attribs']['host']);
343 if (!isset($funcs[0])) {
344 $funcs = array($funcs);
345 }
346
347 foreach ($funcs as $protocol) {
348 $data['data'][] = array('rest', $protocol['attribs']['type'],
349 $protocol['_content']);
350 }
351 }
352 } else {
353 $data['data'][] = array('No supported protocols');
354 }
355 $d['mirrorprotocols' . $i] = $data;
356 }
357 }
358 $this->ui->outputData($d, 'channel-info');
359 }

References $command, $options, PEAR_ChannelFile\fromXmlString(), getDownloader(), PEAR\isError(), PEAR_ERROR_RETURN, PEAR\staticPopErrorHandling(), and PEAR\staticPushErrorHandling().

Here is the call graph for this function:

◆ doList()

doList ( $command,
$options,
$params )

Definition at line 179 of file Channels.php.

180 {
181 $reg = &$this->config->getRegistry();
182 $registered = $reg->getChannels();
183 usort($registered, array(&$this, '_sortchannels'));
184 $i = $j = 0;
185 $data = array(
186 'caption' => 'Registered Channels:',
187 'border' => true,
188 'headline' => array('Channel', 'Alias', 'Summary')
189 );
190 foreach ($registered as $channel) {
191 $data['data'][] = array($channel->getName(),
192 $channel->getAlias(),
193 $channel->getSummary());
194 }
195
196 if (count($registered) === 0) {
197 $data = '(no registered channels)';
198 }
199 $this->ui->outputData($data, $command);
200 return true;
201 }

References $command, and $options.

◆ doLogin()

doLogin ( $command,
$options,
$params )

Execute the 'login' command.

Parameters
string$commandcommand name
array$optionsoption_name => value
array$paramslist of additional parameters
Returns
bool TRUE on success or a PEAR error on failure

@access public

Definition at line 798 of file Channels.php.

799 {
800 $reg = &$this->config->getRegistry();
801
802 // If a parameter is supplied, use that as the channel to log in to
803 $channel = isset($params[0]) ? $params[0] : $this->config->get('default_channel');
804
805 $chan = $reg->getChannel($channel);
806 if (PEAR::isError($chan)) {
807 return $this->raiseError($chan);
808 }
809
810 $server = $this->config->get('preferred_mirror', null, $channel);
811 $username = $this->config->get('username', null, $channel);
812 if (empty($username)) {
813 $username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
814 }
815 $this->ui->outputData("Logging in to $server.", $command);
816
817 list($username, $password) = $this->ui->userDialog(
818 $command,
819 array('Username', 'Password'),
820 array('text', 'password'),
821 array($username, '')
822 );
823 $username = trim($username);
824 $password = trim($password);
825
826 $ourfile = $this->config->getConfFile('user');
827 if (!$ourfile) {
828 $ourfile = $this->config->getConfFile('system');
829 }
830
831 $this->config->set('username', $username, 'user', $channel);
832 $this->config->set('password', $password, 'user', $channel);
833
834 if ($chan->supportsREST()) {
835 $ok = true;
836 }
837
838 if ($ok !== true) {
839 return $this->raiseError('Login failed!');
840 }
841
842 $this->ui->outputData("Logged in.", $command);
843 // avoid changing any temporary settings changed with -d
844 $ourconfig = new PEAR_Config($ourfile, $ourfile);
845 $ourconfig->set('username', $username, 'user', $channel);
846 $ourconfig->set('password', $password, 'user', $channel);
847 $ourconfig->store();
848
849 return true;
850 }

References $command, $options, and PEAR\isError().

Here is the call graph for this function:

◆ doLogout()

doLogout ( $command,
$options,
$params )

Execute the 'logout' command.

Parameters
string$commandcommand name
array$optionsoption_name => value
array$paramslist of additional parameters
Returns
bool TRUE on success or a PEAR error on failure

@access public

Definition at line 864 of file Channels.php.

865 {
866 $reg = &$this->config->getRegistry();
867
868 // If a parameter is supplied, use that as the channel to log in to
869 $channel = isset($params[0]) ? $params[0] : $this->config->get('default_channel');
870
871 $chan = $reg->getChannel($channel);
872 if (PEAR::isError($chan)) {
873 return $this->raiseError($chan);
874 }
875
876 $server = $this->config->get('preferred_mirror', null, $channel);
877 $this->ui->outputData("Logging out from $server.", $command);
878 $this->config->remove('username', 'user', $channel);
879 $this->config->remove('password', 'user', $channel);
880 $this->config->store();
881 return true;
882 }

References $command, $options, and PEAR\isError().

Here is the call graph for this function:

◆ doUpdate()

doUpdate ( $command,
$options,
$params )

Definition at line 506 of file Channels.php.

507 {
508 if (count($params) !== 1) {
509 return $this->raiseError("No channel file specified");
510 }
511
512 $tmpdir = $this->config->get('temp_dir');
513 if (!file_exists($tmpdir)) {
514 require_once 'System.php';
516 $err = System::mkdir(array('-p', $tmpdir));
518 if (PEAR::isError($err)) {
519 return $this->raiseError('channel-add: temp_dir does not exist: "' .
520 $tmpdir .
521 '" - You can change this location with "pear config-set temp_dir"');
522 }
523 }
524
525 if (!is_writable($tmpdir)) {
526 return $this->raiseError('channel-add: temp_dir is not writable: "' .
527 $tmpdir .
528 '" - You can change this location with "pear config-set temp_dir"');
529 }
530
531 $reg = &$this->config->getRegistry();
532 $lastmodified = false;
533 if ((!file_exists($params[0]) || is_dir($params[0]))
534 && $reg->channelExists(strtolower($params[0]))) {
535 $c = $reg->getChannel(strtolower($params[0]));
536 if (PEAR::isError($c)) {
537 return $this->raiseError($c);
538 }
539
540 $this->ui->outputData("Updating channel \"$params[0]\"", $command);
541 $dl = &$this->getDownloader(array());
542 // if force is specified, use a timestamp of "1" to force retrieval
543 $lastmodified = isset($options['force']) ? false : $c->lastModified();
545 $contents = $dl->downloadHttp('https://' . $c->getName() . '/channel.xml',
546 $this->ui, $tmpdir, null, $lastmodified);
548 if (PEAR::isError($contents)) {
549 // Attempt to fall back to http
550 $this->ui->outputData("Channel \"$params[0]\" is not responding over https://, failed with message: " . $contents->getMessage());
551 $this->ui->outputData("Trying channel \"$params[0]\" over http:// instead");
553 $contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml',
554 $this->ui, $tmpdir, null, $lastmodified);
556 if (PEAR::isError($contents)) {
557 return $this->raiseError('Cannot retrieve channel.xml for channel "' .
558 $c->getName() . '" (' . $contents->getMessage() . ')');
559 }
560 }
561 if (is_array($contents)) {
562 list($contents, $lastmodified) = $contents;
563 }
564 if (!$contents) {
565 $this->ui->outputData("Channel \"$params[0]\" is up to date");
566 return;
567 }
568
569 $contents = implode('', file($contents));
570 if (!class_exists('PEAR_ChannelFile')) {
571 require_once 'PEAR/ChannelFile.php';
572 }
573
574 $channel = new PEAR_ChannelFile;
575 $channel->fromXmlString($contents);
576 if (!$channel->getErrors()) {
577 // security check: is the downloaded file for the channel we got it from?
578 if (strtolower($channel->getName()) != strtolower($c->getName())) {
579 if (!isset($options['force'])) {
580 return $this->raiseError('ERROR: downloaded channel definition file' .
581 ' for channel "' . $channel->getName() . '" from channel "' .
582 strtolower($c->getName()) . '"');
583 }
584
585 $this->ui->log(0, 'WARNING: downloaded channel definition file' .
586 ' for channel "' . $channel->getName() . '" from channel "' .
587 strtolower($c->getName()) . '"');
588 }
589 }
590 } else {
591 if (strpos($params[0], '://')) {
592 $dl = &$this->getDownloader();
594 $loc = $dl->downloadHttp($params[0],
595 $this->ui, $tmpdir, null, $lastmodified);
597 if (PEAR::isError($loc)) {
598 return $this->raiseError("Cannot open " . $params[0] .
599 ' (' . $loc->getMessage() . ')');
600 }
601
602 list($loc, $lastmodified) = $loc;
603 $contents = implode('', file($loc));
604 } else {
605 $fp = false;
606 if (file_exists($params[0])) {
607 $fp = fopen($params[0], 'r');
608 }
609
610 if (!$fp) {
611 return $this->raiseError("Cannot open " . $params[0]);
612 }
613
614 $contents = '';
615 while (!feof($fp)) {
616 $contents .= fread($fp, 1024);
617 }
618 fclose($fp);
619 }
620
621 if (!class_exists('PEAR_ChannelFile')) {
622 require_once 'PEAR/ChannelFile.php';
623 }
624
625 $channel = new PEAR_ChannelFile;
626 $channel->fromXmlString($contents);
627 }
628
629 $exit = false;
630 if (count($errors = $channel->getErrors(true))) {
631 foreach ($errors as $error) {
632 $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));
633 if (!$exit) {
634 $exit = $error['level'] == 'error' ? true : false;
635 }
636 }
637 if ($exit) {
638 return $this->raiseError('Invalid channel.xml file');
639 }
640 }
641
642 if (!$reg->channelExists($channel->getName())) {
643 return $this->raiseError('Error: Channel "' . $channel->getName() .
644 '" does not exist, use channel-add to add an entry');
645 }
646
647 $ret = $reg->updateChannel($channel, $lastmodified);
648 if (PEAR::isError($ret)) {
649 return $ret;
650 }
651
652 if (!$ret) {
653 return $this->raiseError('Updating Channel "' . $channel->getName() .
654 '" in registry failed');
655 }
656
657 $this->config->setChannels($reg->listChannels());
658 $this->config->writeConfigFile();
659 $this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded');
660 }

References $command, $options, PEAR_ChannelFile\fromXmlString(), getDownloader(), PEAR\isError(), PEAR_ERROR_RETURN, PEAR\staticPopErrorHandling(), and PEAR\staticPushErrorHandling().

Referenced by doUpdateAll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doUpdateAll()

doUpdateAll ( $command,
$options,
$params )

Definition at line 203 of file Channels.php.

204 {
205 $reg = &$this->config->getRegistry();
206 $channels = $reg->getChannels();
207
208 $success = true;
209 foreach ($channels as $channel) {
210 if ($channel->getName() != '__uri') {
212 $err = $this->doUpdate('channel-update',
213 $options,
214 array($channel->getName()));
215 if (PEAR::isError($err)) {
216 $this->ui->outputData($err->getMessage(), $command);
217 $success = false;
218 } else {
219 $success &= $err;
220 }
221 }
222 }
223 return $success;
224 }
doUpdate($command, $options, $params)
Definition Channels.php:506

References $command, $options, doUpdate(), PEAR\isError(), PEAR_ERROR_RETURN, and PEAR\staticPushErrorHandling().

Here is the call graph for this function:

◆ getDownloader()

& getDownloader ( )

Definition at line 662 of file Channels.php.

663 {
664 if (!class_exists('PEAR_Downloader')) {
665 require_once 'PEAR/Downloader.php';
666 }
667 $a = new PEAR_Downloader($this->ui, array(), $this->config);
668 return $a;
669 }

Referenced by doAdd(), doInfo(), and doUpdate().

Here is the caller graph for this function:

Field Documentation

◆ $commands

$commands

Definition at line 40 of file Channels.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/Command/Channels.php