Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
InputArgument.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Console\Input;
013
014 use Symfony\Component\Console\Exception\InvalidArgumentException;
015 use Symfony\Component\Console\Exception\LogicException;
016
017 /**
018 * Represents a command line argument.
019 *
020 * @author Fabien Potencier <fabien@symfony.com>
021 */
022 class InputArgument
023 {
024 const REQUIRED = 1;
025 const OPTIONAL = 2;
026 const IS_ARRAY = 4;
027
028 private $name;
029 private $mode;
030 private $default;
031 private $description;
032
033 /**
034 * Constructor.
035 *
036 * @param string $name The argument name
037 * @param int $mode The argument mode: self::REQUIRED or self::OPTIONAL
038 * @param string $description A description text
039 * @param mixed $default The default value (for self::OPTIONAL mode only)
040 *
041 * @throws InvalidArgumentException When argument mode is not valid
042 */
043 public function __construct($name, $mode = null, $description = '', $default = null)
044 {
045 if (null === $mode) {
046 $mode = self::OPTIONAL;
047 } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
048 throw new InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
049 }
050
051 $this->name = $name;
052 $this->mode = $mode;
053 $this->description = $description;
054
055 $this->setDefault($default);
056 }
057
058 /**
059 * Returns the argument name.
060 *
061 * @return string The argument name
062 */
063 public function getName()
064 {
065 return $this->name;
066 }
067
068 /**
069 * Returns true if the argument is required.
070 *
071 * @return bool true if parameter mode is self::REQUIRED, false otherwise
072 */
073 public function isRequired()
074 {
075 return self::REQUIRED === (self::REQUIRED & $this->mode);
076 }
077
078 /**
079 * Returns true if the argument can take multiple values.
080 *
081 * @return bool true if mode is self::IS_ARRAY, false otherwise
082 */
083 public function isArray()
084 {
085 return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
086 }
087
088 /**
089 * Sets the default value.
090 *
091 * @param mixed $default The default value
092 *
093 * @throws LogicException When incorrect default value is given
094 */
095 public function setDefault($default = null)
096 {
097 if (self::REQUIRED === $this->mode && null !== $default) {
098 throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
099 }
100
101 if ($this->isArray()) {
102 if (null === $default) {
103 $default = array();
104 } elseif (!is_array($default)) {
105 throw new LogicException('A default value for an array argument must be an array.');
106 }
107 }
108
109 $this->default = $default;
110 }
111
112 /**
113 * Returns the default value.
114 *
115 * @return mixed The default value
116 */
117 public function getDefault()
118 {
119 return $this->default;
120 }
121
122 /**
123 * Returns the description text.
124 *
125 * @return string The description text
126 */
127 public function getDescription()
128 {
129 return $this->description;
130 }
131 }
132