Mirror.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 5 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available through the world-wide-web at the following url: |
  11. // | http://www.php.net/license/3_0.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | [email protected] so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Alexander Merz <[email protected]> |
  17. // | |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Mirror.php,v 1.5 2004/03/18 12:23:57 mj Exp $
  21. require_once "PEAR/Command/Common.php";
  22. require_once "PEAR/Command.php";
  23. require_once "PEAR/Remote.php";
  24. require_once "PEAR.php";
  25. /**
  26. * PEAR commands for providing file mirrors
  27. *
  28. */
  29. class PEAR_Command_Mirror extends PEAR_Command_Common
  30. {
  31. // {{{ properties
  32. var $commands = array(
  33. 'download-all' => array(
  34. 'summary' => 'Downloads each available package from master_server',
  35. 'function' => 'doDownloadAll',
  36. 'shortcut' => 'da',
  37. 'options' => array(),
  38. 'doc' => '
  39. Requests a list of available packages from the package server
  40. (master_server) and downloads them to current working directory'
  41. ),
  42. );
  43. // }}}
  44. // {{{ constructor
  45. /**
  46. * PEAR_Command_Mirror constructor.
  47. *
  48. * @access public
  49. * @param object PEAR_Frontend a reference to an frontend
  50. * @param object PEAR_Config a reference to the configuration data
  51. */
  52. function PEAR_Command_Mirror(&$ui, &$config)
  53. {
  54. parent::PEAR_Command_Common($ui, $config);
  55. }
  56. // }}}
  57. // {{{ doDownloadAll()
  58. /**
  59. * retrieves a list of avaible Packages from master server
  60. * and downloads them
  61. *
  62. * @access public
  63. * @param string $command the command
  64. * @param array $options the command options before the command
  65. * @param array $params the stuff after the command name
  66. * @return bool true if succesful
  67. * @throw PEAR_Error
  68. */
  69. function doDownloadAll($command, $options, $params)
  70. {
  71. $this->config->set("php_dir", ".");
  72. $remote = &new PEAR_Remote($this->config);
  73. $remoteInfo = $remote->call("package.listAll");
  74. if (PEAR::isError($remoteInfo)) {
  75. return $remoteInfo;
  76. }
  77. $cmd = &PEAR_Command::factory("download", $this->config);
  78. if (PEAR::isError($cmd)) {
  79. return $cmd;
  80. }
  81. foreach ($remoteInfo as $pkgn => $pkg) {
  82. /**
  83. * Error handling not neccesary, because already done by
  84. * the download command
  85. */
  86. $cmd->run("download", array(), array($pkgn));
  87. }
  88. return true;
  89. }
  90. // }}}
  91. }