[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Console\Input; 13 14 /** 15 * Represents a command line argument. 16 * 17 * @author Fabien Potencier <fabien@symfony.com> 18 */ 19 class InputArgument 20 { 21 const REQUIRED = 1; 22 const OPTIONAL = 2; 23 const IS_ARRAY = 4; 24 25 private $name; 26 private $mode; 27 private $default; 28 private $description; 29 30 /** 31 * Constructor. 32 * 33 * @param string $name The argument name 34 * @param int $mode The argument mode: self::REQUIRED or self::OPTIONAL 35 * @param string $description A description text 36 * @param mixed $default The default value (for self::OPTIONAL mode only) 37 * 38 * @throws \InvalidArgumentException When argument mode is not valid 39 */ 40 public function __construct($name, $mode = null, $description = '', $default = null) 41 { 42 if (null === $mode) { 43 $mode = self::OPTIONAL; 44 } elseif (!is_int($mode) || $mode > 7 || $mode < 1) { 45 throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode)); 46 } 47 48 $this->name = $name; 49 $this->mode = $mode; 50 $this->description = $description; 51 52 $this->setDefault($default); 53 } 54 55 /** 56 * Returns the argument name. 57 * 58 * @return string The argument name 59 */ 60 public function getName() 61 { 62 return $this->name; 63 } 64 65 /** 66 * Returns true if the argument is required. 67 * 68 * @return bool true if parameter mode is self::REQUIRED, false otherwise 69 */ 70 public function isRequired() 71 { 72 return self::REQUIRED === (self::REQUIRED & $this->mode); 73 } 74 75 /** 76 * Returns true if the argument can take multiple values. 77 * 78 * @return bool true if mode is self::IS_ARRAY, false otherwise 79 */ 80 public function isArray() 81 { 82 return self::IS_ARRAY === (self::IS_ARRAY & $this->mode); 83 } 84 85 /** 86 * Sets the default value. 87 * 88 * @param mixed $default The default value 89 * 90 * @throws \LogicException When incorrect default value is given 91 */ 92 public function setDefault($default = null) 93 { 94 if (self::REQUIRED === $this->mode && null !== $default) { 95 throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); 96 } 97 98 if ($this->isArray()) { 99 if (null === $default) { 100 $default = array(); 101 } elseif (!is_array($default)) { 102 throw new \LogicException('A default value for an array argument must be an array.'); 103 } 104 } 105 106 $this->default = $default; 107 } 108 109 /** 110 * Returns the default value. 111 * 112 * @return mixed The default value 113 */ 114 public function getDefault() 115 { 116 return $this->default; 117 } 118 119 /** 120 * Returns the description text. 121 * 122 * @return string The description text 123 */ 124 public function getDescription() 125 { 126 return $this->description; 127 } 128 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |