Overview

Namespaces

  • Deimos
    • CLI
      • Exceptions
  • PHP

Classes

  • Deimos\CLI\CLI
  • Deimos\CLI\Tokenizer
  • Deimos\CLI\Variable

Interfaces

  • Deimos\CLI\InterfaceVariable
  • Throwable

Exceptions

  • Deimos\CLI\Exceptions\CLIRun
  • Deimos\CLI\Exceptions\Required
  • Deimos\CLI\Exceptions\UndefinedAlias
  • Deimos\CLI\Exceptions\UndefinedVariable
  • Exception
  • InvalidArgumentException
  • LogicException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: namespace Deimos\CLI;
  4: 
  5: class Variable implements InterfaceVariable
  6: {
  7: 
  8:     /**
  9:      * @var string
 10:      */
 11:     protected $name;
 12: 
 13:     /**
 14:      * @var bool
 15:      */
 16:     protected $required;
 17: 
 18:     /**
 19:      * @var array
 20:      */
 21:     protected $value = [];
 22: 
 23:     /**
 24:      * @var array
 25:      */
 26:     protected $defaultValue = [];
 27: 
 28:     /**
 29:      * @var bool
 30:      */
 31:     protected $isDefaultValue;
 32: 
 33:     /**
 34:      * @var bool
 35:      */
 36:     protected $boolType;
 37: 
 38:     /**
 39:      * @var string
 40:      */
 41:     protected $help;
 42: 
 43:     /**
 44:      * @var array
 45:      */
 46:     protected $aliases = [];
 47: 
 48:     /**
 49:      * Variable constructor.
 50:      *
 51:      * @param $name
 52:      */
 53:     public function __construct($name)
 54:     {
 55:         $this->name = $name;
 56:     }
 57: 
 58:     /**
 59:      * @param $name
 60:      *
 61:      * @return static
 62:      */
 63:     public function alias($name)
 64:     {
 65:         $this->aliases[] = $name;
 66: 
 67:         return $this;
 68:     }
 69: 
 70:     /**
 71:      * @return array
 72:      */
 73:     public function aliases()
 74:     {
 75:         return $this->aliases;
 76:     }
 77: 
 78:     /**
 79:      * @return $this
 80:      */
 81:     public function boolType()
 82:     {
 83:         $this->boolType = true;
 84:         $this->defaultValue(false);
 85: 
 86:         return $this;
 87:     }
 88: 
 89:     /**
 90:      * @return bool
 91:      */
 92:     public function isBoolType()
 93:     {
 94:         return (bool)$this->boolType;
 95:     }
 96: 
 97:     /**
 98:      * @return $this
 99:      */
100:     public function required()
101:     {
102:         $this->required = true;
103: 
104:         return $this;
105:     }
106: 
107:     /**
108:      * @return bool
109:      */
110:     public function isRequired()
111:     {
112:         return (bool)$this->required;
113:     }
114: 
115:     /**
116:      * @param $mixed
117:      *
118:      * @return $this
119:      */
120:     public function help($mixed)
121:     {
122:         $this->help = $mixed;
123: 
124:         return $this;
125:     }
126: 
127:     /**
128:      * @param mixed $mixed
129:      *
130:      * @return $this
131:      */
132:     public function defaultValue($mixed)
133:     {
134:         if (!$this->isDefaultValue)
135:         {
136:             $this->defaultValue   = $mixed;
137:             $this->isDefaultValue = true;
138:         }
139: 
140:         return $this;
141:     }
142: 
143:     /**
144:      * @param $data
145:      */
146:     public function setValue($data)
147:     {
148:         $this->value = $data;
149:     }
150: 
151:     /**
152:      * @return mixed
153:      */
154:     public function value()
155:     {
156:         if ($this->value !== [])
157:         {
158:             return $this->value;
159:         }
160: 
161:         return $this->defaultValue;
162:     }
163: 
164:     /**
165:      * @return string
166:      */
167:     public function name()
168:     {
169:         return $this->name;
170:     }
171: 
172: }
API documentation generated by ApiGen