1 | <?php |
||
61 | class Deployer extends Container |
||
62 | { |
||
63 | /** |
||
64 | * Global instance of deployer. It's can be accessed only after constructor call. |
||
65 | * @var Deployer |
||
66 | */ |
||
67 | private static $instance; |
||
68 | |||
69 | /** |
||
70 | * @param Application $console |
||
71 | */ |
||
72 | 10 | public function __construct(Application $console, InputInterface $input, OutputInterface $output) |
|
73 | { |
||
74 | 10 | parent::__construct(); |
|
75 | |||
76 | /****************************** |
||
77 | * Console * |
||
78 | ******************************/ |
||
79 | |||
80 | $this['console'] = function () use ($console) { |
||
81 | return $console; |
||
82 | }; |
||
83 | $this['input'] = function () use ($input) { |
||
84 | return $input; |
||
85 | }; |
||
86 | $this['output'] = function () use ($output) { |
||
87 | 1 | return $output; |
|
88 | }; |
||
89 | $this['inputDefinition'] = function () { |
||
90 | return new InputDefinition(); |
||
91 | }; |
||
92 | |||
93 | /****************************** |
||
94 | * Config * |
||
95 | ******************************/ |
||
96 | |||
97 | $this['config'] = function () { |
||
98 | 10 | return new Configuration(); |
|
99 | }; |
||
100 | 10 | $this->config['ssh_multiplexing'] = true; |
|
101 | 10 | $this->config['default_stage'] = null; |
|
102 | |||
103 | /****************************** |
||
104 | * Core * |
||
105 | ******************************/ |
||
106 | |||
107 | $this['pop'] = function ($c) { |
||
108 | 1 | return new Printer($c['output']); |
|
109 | }; |
||
110 | $this['sshClient'] = function ($c) { |
||
111 | return new Client($c['output'], $c['pop'], $c['logger']); |
||
112 | }; |
||
113 | $this['rsync'] = function ($c) { |
||
114 | return new Rsync($c['pop'], $c['output']); |
||
115 | }; |
||
116 | $this['processRunner'] = function ($c) { |
||
117 | 1 | return new ProcessRunner($c['pop'], $c['logger']); |
|
118 | }; |
||
119 | $this['tasks'] = function () { |
||
120 | 10 | return new Task\TaskCollection(); |
|
121 | }; |
||
122 | $this['hosts'] = function () { |
||
123 | 4 | return new Host\HostCollection(); |
|
124 | }; |
||
125 | $this['scriptManager'] = function ($c) { |
||
126 | 2 | return new Task\ScriptManager($c['tasks']); |
|
127 | }; |
||
128 | $this['selector'] = function ($c) { |
||
129 | return new Selector($c['hosts']); |
||
130 | }; |
||
131 | $this['fail'] = function () { |
||
132 | return new Collection(); |
||
133 | }; |
||
134 | $this['messenger'] = function ($c) { |
||
135 | return new Messenger($c['input'], $c['output']); |
||
136 | }; |
||
137 | $this['executor'] = function ($c) { |
||
138 | return new ParallelExecutor( |
||
139 | $c['input'], |
||
140 | $c['output'], |
||
141 | $c['messenger'], |
||
142 | $c['console'], |
||
143 | $c['sshClient'], |
||
144 | $c['config'] |
||
145 | ); |
||
146 | }; |
||
147 | |||
148 | /****************************** |
||
149 | * Logger * |
||
150 | ******************************/ |
||
151 | |||
152 | $this['log_handler'] = function () { |
||
153 | 1 | return !empty($this->config['log_file']) |
|
154 | ? new FileHandler($this->config['log_file']) |
||
155 | 1 | : new NullHandler(); |
|
156 | }; |
||
157 | $this['logger'] = function () { |
||
158 | 1 | return new Logger($this['log_handler']); |
|
159 | }; |
||
160 | |||
161 | 10 | self::$instance = $this; |
|
162 | |||
163 | task('connect', function () { |
||
164 | $this['sshClient']->connect(currentHost()); |
||
165 | 10 | })->desc('Connect to remote server'); |
|
166 | 10 | } |
|
167 | |||
168 | /** |
||
169 | * @return Deployer |
||
170 | */ |
||
171 | 19 | public static function get() |
|
175 | |||
176 | /** |
||
177 | * Init console application |
||
178 | */ |
||
179 | public function init() |
||
190 | |||
191 | /** |
||
192 | * Transform tasks to console commands. |
||
193 | */ |
||
194 | public function addTaskCommands() |
||
204 | |||
205 | /** |
||
206 | * @param string $name |
||
207 | * @return mixed |
||
208 | * @throws \InvalidArgumentException |
||
209 | */ |
||
210 | 17 | public function __get($name) |
|
218 | |||
219 | /** |
||
220 | * @return Application |
||
221 | */ |
||
222 | public function getConsole() |
||
226 | |||
227 | /** |
||
228 | * @param string $name |
||
229 | * @return Console\Helper\HelperInterface |
||
230 | */ |
||
231 | public function getHelper($name) |
||
235 | |||
236 | /** |
||
237 | * Run Deployer |
||
238 | * |
||
239 | * @param string $version |
||
240 | * @param string $deployFile |
||
241 | */ |
||
242 | public static function run($version, $deployFile) |
||
263 | |||
264 | public static function load(string $deployFile) |
||
284 | |||
285 | private static function printException(OutputInterface $output, Throwable $exception) |
||
300 | |||
301 | /** |
||
302 | * Collect anonymous stats about Deployer usage for improving developer experience. |
||
303 | * If you are not comfortable with this, you will always be able to disable this |
||
304 | * by setting `allow_anonymous_stats` to false in your deploy.php file. |
||
305 | * |
||
306 | * @param CommandEvent $commandEvent |
||
307 | * @codeCoverageIgnore |
||
308 | */ |
||
309 | public function collectAnonymousStats(CommandEvent $commandEvent) |
||
344 | } |
||
345 |