1 | <?php |
||
33 | class Deployer extends Container |
||
34 | { |
||
35 | /** |
||
36 | * Global instance of deployer. It's can be accessed only after constructor call. |
||
37 | * @var Deployer |
||
38 | */ |
||
39 | private static $instance; |
||
40 | |||
41 | /** |
||
42 | * @param Application $console |
||
43 | * @param Console\Input\InputInterface $input |
||
44 | * @param Console\Output\OutputInterface $output |
||
45 | */ |
||
46 | public function __construct(Application $console, Console\Input\InputInterface $input, Console\Output\OutputInterface $output) |
||
47 | { |
||
48 | parent::__construct(); |
||
49 | |||
50 | /****************************** |
||
51 | * Console * |
||
52 | ******************************/ |
||
53 | |||
54 | $this['console'] = function () use ($console) { |
||
55 | return $console; |
||
56 | }; |
||
57 | $this['input'] = function () use ($input) { |
||
58 | return $input; |
||
59 | }; |
||
60 | $this['output'] = function () use ($output) { |
||
61 | return $output; |
||
62 | }; |
||
63 | |||
64 | /****************************** |
||
65 | 35 | * Config * |
|
66 | ******************************/ |
||
67 | 35 | ||
68 | 35 | $this['config'] = function () { |
|
69 | 35 | return new Collection(); |
|
70 | }; |
||
71 | 35 | $this->config['ssh_type'] = 'phpseclib'; |
|
72 | 35 | $this->config['default_stage'] = null; |
|
73 | 35 | ||
74 | 35 | /****************************** |
|
75 | 35 | * Core * |
|
76 | 35 | ******************************/ |
|
77 | |||
78 | 35 | $this['tasks'] = function () { |
|
79 | return new Task\TaskCollection(); |
||
80 | 35 | }; |
|
81 | 35 | $this['servers'] = function () { |
|
82 | return new Server\ServerCollection(); |
||
83 | }; |
||
84 | $this['environments'] = function () { |
||
85 | return new Server\EnvironmentCollection(); |
||
86 | 22 | }; |
|
87 | $this['scriptManager'] = function ($c) { |
||
88 | 22 | return new Task\ScriptManager($c['tasks']); |
|
89 | }; |
||
90 | $this['stageStrategy'] = function ($c) { |
||
91 | return new StageStrategy($c['servers'], $c['environments'], $c['config']['default_stage']); |
||
92 | }; |
||
93 | $this['onFailure'] = function () { |
||
94 | return new Collection(); |
||
95 | }; |
||
96 | |||
97 | /****************************** |
||
98 | * Logger * |
||
99 | ******************************/ |
||
100 | |||
101 | $this['log_level'] = Logger::DEBUG; |
||
102 | $this['log_handler'] = function () { |
||
103 | return isset($this->config['log_file']) |
||
104 | ? new StreamHandler($this->config['log_file'], $this['log_level']) |
||
105 | : new NullHandler($this['log_level']); |
||
106 | }; |
||
107 | 14 | $this['log'] = function () { |
|
108 | $name = isset($this->config['log_name']) ? $this->config['log_name'] : 'Deployer'; |
||
109 | 14 | return new Logger($name, [ |
|
110 | $this['log_handler'] |
||
111 | 14 | ]); |
|
112 | 14 | }; |
|
113 | 14 | ||
114 | /****************************** |
||
115 | * Init command * |
||
116 | 14 | ******************************/ |
|
117 | 14 | ||
118 | 14 | $this['init_command'] = function () { |
|
119 | return new InitCommand(); |
||
120 | }; |
||
121 | |||
122 | self::$instance = $this; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * @return Deployer |
||
127 | */ |
||
128 | public static function get() |
||
132 | |||
133 | /** |
||
134 | * @param string $name |
||
135 | * @param mixed $value |
||
136 | */ |
||
137 | public static function setDefault($name, $value) |
||
141 | 35 | ||
142 | /** |
||
143 | 35 | * @param string $name |
|
144 | 35 | * @param mixed $default |
|
145 | * @return mixed |
||
146 | 1 | */ |
|
147 | public static function getDefault($name, $default = null) |
||
151 | |||
152 | /** |
||
153 | * @param string $name |
||
154 | * @return boolean |
||
155 | */ |
||
156 | public static function hasDefault($name) |
||
160 | |||
161 | /** |
||
162 | 14 | * @param string $name |
|
163 | * @param array $array |
||
164 | 14 | */ |
|
165 | public static function addDefault($name, $array) |
||
177 | |||
178 | /** |
||
179 | * Run console application. |
||
180 | */ |
||
181 | public function run() |
||
191 | |||
192 | /** |
||
193 | * Transform tasks to console commands. |
||
194 | */ |
||
195 | public function addConsoleCommands() |
||
207 | |||
208 | /** |
||
209 | * @param string $name |
||
210 | * @return mixed |
||
211 | * @throws \InvalidArgumentException |
||
212 | */ |
||
213 | public function __get($name) |
||
221 | |||
222 | /** |
||
223 | * @return Application |
||
224 | */ |
||
225 | public function getConsole() |
||
229 | |||
230 | /** |
||
231 | * @return Console\Input\InputInterface |
||
232 | */ |
||
233 | public function getInput() |
||
237 | |||
238 | /** |
||
239 | * @return Console\Output\OutputInterface |
||
240 | */ |
||
241 | public function getOutput() |
||
245 | |||
246 | /** |
||
247 | * @param string $name |
||
248 | * @return Console\Helper\HelperInterface |
||
249 | */ |
||
250 | public function getHelper($name) |
||
254 | |||
255 | /** |
||
256 | * @return StageStrategy |
||
257 | */ |
||
258 | public function getStageStrategy() |
||
262 | |||
263 | /** |
||
264 | * @return Task\ScriptManager |
||
265 | */ |
||
266 | public function getScriptManager() |
||
270 | |||
271 | /** |
||
272 | * @return LoggerInterface |
||
273 | */ |
||
274 | public function getLogger() |
||
278 | |||
279 | /** |
||
280 | * Collect anonymous stats about Deployer usage for improving developer experience. |
||
281 | * If you are not comfortable with this, you will always be able to disable this |
||
282 | * by setting `allow_anonymous_stats` to false in your deploy.php file. |
||
283 | * |
||
284 | * @param CommandEvent $commandEvent |
||
285 | */ |
||
286 | public function collectAnonymousStats(CommandEvent $commandEvent) |
||
344 | } |
||
345 |
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.