MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
InputArgument.php
Ir para a documentação deste ficheiro.
1<?php
2
4
5/*
6 * This file is part of the Symfony framework.
7 *
8 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
9 *
10 * This source file is subject to the MIT license that is bundled
11 * with this source code in the file LICENSE.
12 */
13
20{
21 const REQUIRED = 1;
22 const OPTIONAL = 2;
23 const IS_ARRAY = 4;
24
25 protected $name;
26 protected $mode;
27 protected $default;
28 protected $description;
29
40 public function __construct($name, $mode = null, $description = '', $default = null)
41 {
42 if (null === $mode) {
44 } else if (is_string($mode) || $mode > 7) {
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
60 public function getName()
61 {
62 return $this->name;
63 }
64
70 public function isRequired()
71 {
72 return self::REQUIRED === (self::REQUIRED & $this->mode);
73 }
74
80 public function isArray()
81 {
82 return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
83 }
84
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 Parameter::OPTIONAL mode.');
96 }
97
98 if ($this->isArray()) {
99 if (null === $default) {
100 $default = array();
101 } else if (!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
114 public function getDefault()
115 {
116 return $this->default;
117 }
118
124 public function getDescription()
125 {
126 return $this->description;
127 }
128}
__construct($name, $mode=null, $description='', $default=null)