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 | $this['onFailure'] = function () { |
||
92 | return new Collection(); |
||
93 | }; |
||
94 | |||
95 | /****************************** |
||
96 | * Logger * |
||
97 | ******************************/ |
||
98 | |||
99 | $this['log_level'] = Logger::DEBUG; |
||
100 | $this['log_handler'] = function () { |
||
101 | return isset($this->config['log_file']) |
||
102 | ? new StreamHandler($this->config['log_file'], $this['log_level']) |
||
103 | : new NullHandler($this['log_level']); |
||
104 | }; |
||
105 | $this['log'] = function () { |
||
106 | $name = isset($this->config['log_name']) ? $this->config['log_name'] : 'Deployer'; |
||
107 | 14 | return new Logger($name, [ |
|
108 | $this['log_handler'] |
||
109 | 14 | ]); |
|
110 | }; |
||
111 | 14 | ||
112 | 14 | /****************************** |
|
113 | 14 | * Init command * |
|
114 | ******************************/ |
||
115 | |||
116 | 14 | $this['init_command'] = function () { |
|
117 | 14 | return new InitCommand(); |
|
118 | 14 | }; |
|
119 | |||
120 | self::$instance = $this; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @return Deployer |
||
125 | */ |
||
126 | public static function get() |
||
130 | |||
131 | /** |
||
132 | * @param string $name |
||
133 | * @param mixed $value |
||
134 | */ |
||
135 | public static function setDefault($name, $value) |
||
139 | |||
140 | /** |
||
141 | 35 | * @param string $name |
|
142 | * @param mixed $default |
||
143 | 35 | * @return mixed |
|
144 | 35 | */ |
|
145 | public static function getDefault($name, $default = null) |
||
149 | |||
150 | /** |
||
151 | * @param string $name |
||
152 | * @return boolean |
||
153 | */ |
||
154 | public static function hasDefault($name) |
||
158 | |||
159 | /** |
||
160 | * @param string $name |
||
161 | * @param array $array |
||
162 | 14 | */ |
|
163 | public static function addDefault($name, $array) |
||
175 | |||
176 | /** |
||
177 | * Run console application. |
||
178 | */ |
||
179 | public function run() |
||
188 | |||
189 | /** |
||
190 | * Transform tasks to console commands. |
||
191 | */ |
||
192 | public function addConsoleCommands() |
||
204 | |||
205 | /** |
||
206 | * @param string $name |
||
207 | * @return mixed |
||
208 | * @throws \InvalidArgumentException |
||
209 | */ |
||
210 | public function __get($name) |
||
218 | |||
219 | /** |
||
220 | * @return Application |
||
221 | */ |
||
222 | public function getConsole() |
||
226 | |||
227 | /** |
||
228 | * @return Console\Input\InputInterface |
||
229 | */ |
||
230 | public function getInput() |
||
234 | |||
235 | /** |
||
236 | * @return Console\Output\OutputInterface |
||
237 | */ |
||
238 | public function getOutput() |
||
242 | |||
243 | /** |
||
244 | * @param string $name |
||
245 | * @return Console\Helper\HelperInterface |
||
246 | */ |
||
247 | public function getHelper($name) |
||
251 | |||
252 | /** |
||
253 | * @return StageStrategy |
||
254 | */ |
||
255 | public function getStageStrategy() |
||
259 | |||
260 | /** |
||
261 | * @return Task\ScriptManager |
||
262 | */ |
||
263 | public function getScriptManager() |
||
267 | |||
268 | /** |
||
269 | * @return LoggerInterface |
||
270 | */ |
||
271 | public function getLogger() |
||
275 | } |
||
276 |
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.