123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- class sfCommandArgument
- {
- const REQUIRED = 1;
- const OPTIONAL = 2;
- const IS_ARRAY = 4;
- protected
- $name = null,
- $mode = null,
- $default = null,
- $help = '';
-
- public function __construct($name, $mode = null, $help = '', $default = null)
- {
- if (is_null($mode))
- {
- $mode = self::OPTIONAL;
- }
- else if (is_string($mode) || $mode > 7)
- {
- throw new sfCommandException(sprintf('Argument mode "%s" is not valid.', $mode));
- }
- $this->name = $name;
- $this->mode = $mode;
- $this->help = $help;
- $this->setDefault($default);
- }
-
- public function getName()
- {
- return $this->name;
- }
-
- public function isRequired()
- {
- return self::REQUIRED === (self::REQUIRED & $this->mode);
- }
-
- public function isArray()
- {
- return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
- }
-
- public function setDefault($default = null)
- {
- if (self::REQUIRED === $this->mode && !is_null($default))
- {
- throw new sfCommandException('Cannot set a default value except for sfCommandParameter::OPTIONAL mode.');
- }
- if ($this->isArray())
- {
- if (is_null($default))
- {
- $default = array();
- }
- else if (!is_array($default))
- {
- throw new sfCommandException('A default value for an array argument must be an array.');
- }
- }
- $this->default = $default;
- }
-
- public function getDefault()
- {
- return $this->default;
- }
-
- public function getHelp()
- {
- return $this->help;
- }
- }
|