You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Action.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * This file is part of the PEAR Console_CommandLine package.
  5. *
  6. * PHP version 5
  7. *
  8. * LICENSE: This source file is subject to the MIT license that is available
  9. * through the world-wide-web at the following URI:
  10. * http://opensource.org/licenses/mit-license.php
  11. *
  12. * @category Console
  13. * @package Console_CommandLine
  14. * @author David JEAN LOUIS <izimobil@gmail.com>
  15. * @copyright 2007 David JEAN LOUIS
  16. * @license http://opensource.org/licenses/mit-license.php MIT License
  17. * @version CVS: $Id$
  18. * @link http://pear.php.net/package/Console_CommandLine
  19. * @since File available since release 0.1.0
  20. * @filesource
  21. */
  22. /**
  23. * Class that represent an option action.
  24. *
  25. * @category Console
  26. * @package Console_CommandLine
  27. * @author David JEAN LOUIS <izimobil@gmail.com>
  28. * @copyright 2007 David JEAN LOUIS
  29. * @license http://opensource.org/licenses/mit-license.php MIT License
  30. * @version Release: 1.2.2
  31. * @link http://pear.php.net/package/Console_CommandLine
  32. * @since Class available since release 0.1.0
  33. */
  34. abstract class Console_CommandLine_Action
  35. {
  36. // Properties {{{
  37. /**
  38. * A reference to the result instance.
  39. *
  40. * @var Console_CommandLine_Result $result The result instance
  41. */
  42. protected $result;
  43. /**
  44. * A reference to the option instance.
  45. *
  46. * @var Console_CommandLine_Option $option The action option
  47. */
  48. protected $option;
  49. /**
  50. * A reference to the parser instance.
  51. *
  52. * @var Console_CommandLine $parser The parser
  53. */
  54. protected $parser;
  55. // }}}
  56. // __construct() {{{
  57. /**
  58. * Constructor
  59. *
  60. * @param Console_CommandLine_Result $result The result instance
  61. * @param Console_CommandLine_Option $option The action option
  62. * @param Console_CommandLine $parser The current parser
  63. *
  64. * @return void
  65. */
  66. public function __construct($result, $option, $parser)
  67. {
  68. $this->result = $result;
  69. $this->option = $option;
  70. $this->parser = $parser;
  71. }
  72. // }}}
  73. // getResult() {{{
  74. /**
  75. * Convenience method to retrieve the value of result->options[name].
  76. *
  77. * @return mixed The result value or null
  78. */
  79. public function getResult()
  80. {
  81. if (isset($this->result->options[$this->option->name])) {
  82. return $this->result->options[$this->option->name];
  83. }
  84. return null;
  85. }
  86. // }}}
  87. // format() {{{
  88. /**
  89. * Allow a value to be pre-formatted prior to being used in a choices test.
  90. * Setting $value to the new format will keep the formatting.
  91. *
  92. * @param mixed &$value The value to format
  93. *
  94. * @return mixed The formatted value
  95. */
  96. public function format(&$value)
  97. {
  98. return $value;
  99. }
  100. // }}}
  101. // setResult() {{{
  102. /**
  103. * Convenience method to assign the result->options[name] value.
  104. *
  105. * @param mixed $result The result value
  106. *
  107. * @return void
  108. */
  109. public function setResult($result)
  110. {
  111. $this->result->options[$this->option->name] = $result;
  112. }
  113. // }}}
  114. // execute() {{{
  115. /**
  116. * Executes the action with the value entered by the user.
  117. * All children actions must implement this method.
  118. *
  119. * @param mixed $value The option value
  120. * @param array $params An optional array of parameters
  121. *
  122. * @return string
  123. */
  124. abstract public function execute($value = false, $params = array());
  125. // }}}
  126. }