1 | <?php |
||
31 | class Deployer extends Container |
||
32 | { |
||
33 | /** |
||
34 | * Global instance of deployer. It's can be accessed only after constructor call. |
||
35 | * @var Deployer |
||
36 | */ |
||
37 | private static $instance; |
||
38 | |||
39 | /** |
||
40 | * @param Application $console |
||
41 | * @param Console\Input\InputInterface $input |
||
42 | * @param Console\Output\OutputInterface $output |
||
43 | */ |
||
44 | public function __construct(Application $console, Console\Input\InputInterface $input, Console\Output\OutputInterface $output) |
||
45 | { |
||
46 | parent::__construct(); |
||
47 | |||
48 | /****************************** |
||
49 | * Console * |
||
50 | ******************************/ |
||
51 | |||
52 | $this['console'] = function () use ($console) { |
||
53 | return $console; |
||
54 | }; |
||
55 | $this['input'] = function () use ($input) { |
||
56 | return $input; |
||
57 | }; |
||
58 | $this['output'] = function () use ($output) { |
||
59 | return $output; |
||
60 | }; |
||
61 | |||
62 | /****************************** |
||
63 | * Config * |
||
64 | ******************************/ |
||
65 | 35 | ||
66 | $this['config'] = function () { |
||
67 | 35 | return new Collection(); |
|
68 | 35 | }; |
|
69 | 35 | $this->config['ssh_type'] = 'phpseclib'; |
|
70 | $this->config['default_stage'] = null; |
||
71 | 35 | ||
72 | 35 | /****************************** |
|
73 | 35 | * Core * |
|
74 | 35 | ******************************/ |
|
75 | 35 | ||
76 | 35 | $this['tasks'] = function () { |
|
77 | return new Task\TaskCollection(); |
||
78 | 35 | }; |
|
79 | $this['servers'] = function () { |
||
80 | 35 | return new Server\ServerCollection(); |
|
81 | 35 | }; |
|
82 | $this['environments'] = function () { |
||
83 | return new Server\EnvironmentCollection(); |
||
84 | }; |
||
85 | $this['scriptManager'] = function ($c) { |
||
86 | 22 | return new Task\ScriptManager($c['tasks']); |
|
87 | }; |
||
88 | 22 | $this['stageStrategy'] = function ($c) { |
|
89 | return new StageStrategy($c['servers'], $c['environments'], $c['config']['default_stage']); |
||
90 | }; |
||
91 | |||
92 | /****************************** |
||
93 | * Logger * |
||
94 | ******************************/ |
||
95 | |||
96 | $this['log_level'] = Logger::DEBUG; |
||
97 | $this['log_handler'] = function () { |
||
98 | return isset($this->config['log_file']) |
||
99 | ? new StreamHandler($this->config['log_file'], $this['log_level']) |
||
100 | : new NullHandler($this['log_level']); |
||
101 | }; |
||
102 | $this['log'] = function () { |
||
103 | $name = isset($this->config['log_name']) ? $this->config['log_name'] : 'Deployer'; |
||
104 | return new Logger($name, [ |
||
105 | $this['log_handler'] |
||
106 | ]); |
||
107 | 14 | }; |
|
108 | |||
109 | 14 | self::$instance = $this; |
|
110 | } |
||
111 | 14 | ||
112 | 14 | /** |
|
113 | 14 | * @return Deployer |
|
114 | */ |
||
115 | public static function get() |
||
119 | |||
120 | /** |
||
121 | * @param string $name |
||
122 | * @param mixed $value |
||
123 | */ |
||
124 | public static function setDefault($name, $value) |
||
128 | |||
129 | /** |
||
130 | * @param string $name |
||
131 | * @param mixed $default |
||
132 | * @return mixed |
||
133 | */ |
||
134 | public static function getDefault($name, $default = null) |
||
138 | |||
139 | /** |
||
140 | * @param string $name |
||
141 | 35 | * @return boolean |
|
142 | */ |
||
143 | 35 | public static function hasDefault($name) |
|
147 | |||
148 | /** |
||
149 | * @param string $name |
||
150 | * @param array $array |
||
151 | */ |
||
152 | public static function addDefault($name, $array) |
||
164 | 14 | ||
165 | /** |
||
166 | * Run console application. |
||
167 | */ |
||
168 | public function run() |
||
177 | |||
178 | /** |
||
179 | * Transform tasks to console commands. |
||
180 | */ |
||
181 | public function addConsoleCommands() |
||
193 | |||
194 | /** |
||
195 | * @param string $name |
||
196 | * @return mixed |
||
197 | * @throws \InvalidArgumentException |
||
198 | */ |
||
199 | public function __get($name) |
||
207 | |||
208 | /** |
||
209 | * @return Application |
||
210 | */ |
||
211 | public function getConsole() |
||
215 | |||
216 | /** |
||
217 | * @return Console\Input\InputInterface |
||
218 | */ |
||
219 | public function getInput() |
||
223 | |||
224 | /** |
||
225 | * @return Console\Output\OutputInterface |
||
226 | */ |
||
227 | public function getOutput() |
||
231 | |||
232 | /** |
||
233 | * @param string $name |
||
234 | * @return Console\Helper\HelperInterface |
||
235 | */ |
||
236 | public function getHelper($name) |
||
240 | |||
241 | /** |
||
242 | * @return StageStrategy |
||
243 | */ |
||
244 | public function getStageStrategy() |
||
248 | |||
249 | /** |
||
250 | * @return Task\ScriptManager |
||
251 | */ |
||
252 | public function getScriptManager() |
||
256 | |||
257 | /** |
||
258 | * @return LoggerInterface |
||
259 | */ |
||
260 | public function getLogger() |
||
264 | } |
||
265 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.