Total Complexity | 74 |
Total Lines | 770 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Compile often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Compile, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
73 | class Compile extends Configurable |
||
74 | { |
||
75 | use ChangeableWorkingDirectory; |
||
76 | |||
77 | private const HELP = <<<'HELP' |
||
78 | The <info>%command.name%</info> command will compile code in a new PHAR based on a variety of settings. |
||
79 | <comment> |
||
80 | This command relies on a configuration file for loading |
||
81 | PHAR packaging settings. If a configuration file is not |
||
82 | specified through the <info>--config|-c</info> option, one of |
||
83 | the following files will be used (in order): <info>box.json</info>, |
||
84 | <info>box.json.dist</info> |
||
85 | </comment> |
||
86 | The configuration file is actually a JSON object saved to a file. For more |
||
87 | information check the documentation online: |
||
88 | <comment> |
||
89 | https://github.com/humbug/box |
||
90 | </comment> |
||
91 | HELP; |
||
92 | |||
93 | private const DEBUG_OPTION = 'debug'; |
||
94 | private const NO_PARALLEL_PROCESSING_OPTION = 'no-parallel'; |
||
95 | private const NO_RESTART_OPTION = 'no-restart'; |
||
96 | private const DEV_OPTION = 'dev'; |
||
97 | private const NO_CONFIG_OPTION = 'no-config'; |
||
98 | |||
99 | private const DEBUG_DIR = '.box_dump'; |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | protected function configure(): void |
||
105 | { |
||
106 | parent::configure(); |
||
107 | |||
108 | $this->setName('compile'); |
||
109 | $this->setDescription('Compile an application into a PHAR'); |
||
110 | $this->setHelp(self::HELP); |
||
111 | |||
112 | $this->addOption( |
||
113 | self::DEBUG_OPTION, |
||
114 | null, |
||
115 | InputOption::VALUE_NONE, |
||
116 | 'Dump the files added to the PHAR in a `'.self::DEBUG_DIR.'` directory' |
||
117 | ); |
||
118 | $this->addOption( |
||
119 | self::NO_PARALLEL_PROCESSING_OPTION, |
||
120 | null, |
||
121 | InputOption::VALUE_NONE, |
||
122 | 'Disable the parallel processing' |
||
123 | ); |
||
124 | $this->addOption( |
||
125 | self::NO_RESTART_OPTION, |
||
126 | null, |
||
127 | InputOption::VALUE_NONE, |
||
128 | 'Do not restart the PHP process. Box restarts the process by default to disable xdebug and set `phar.readonly=0`' |
||
129 | ); |
||
130 | $this->addOption( |
||
131 | self::DEV_OPTION, |
||
132 | null, |
||
133 | InputOption::VALUE_NONE, |
||
134 | 'Skips the compression step' |
||
135 | ); |
||
136 | $this->addOption( |
||
137 | self::NO_CONFIG_OPTION, |
||
138 | null, |
||
139 | InputOption::VALUE_NONE, |
||
140 | 'Ignore the config file even when one is specified with the --config option' |
||
141 | ); |
||
142 | |||
143 | $this->configureWorkingDirOption(); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | protected function execute(InputInterface $input, OutputInterface $output): void |
||
150 | { |
||
151 | $io = new SymfonyStyle($input, $output); |
||
152 | |||
153 | if ($input->getOption(self::NO_RESTART_OPTION)) { |
||
154 | putenv('BOX_ALLOW_XDEBUG=1'); |
||
155 | } |
||
156 | |||
157 | if ($debug = $input->getOption(self::DEBUG_OPTION)) { |
||
158 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
||
159 | } |
||
160 | |||
161 | self::checkPhpSettings($io, $output); |
||
162 | |||
163 | if ($input->getOption(self::NO_PARALLEL_PROCESSING_OPTION)) { |
||
164 | disable_parallel_processing(); |
||
165 | $io->writeln('<info>[debug] Disabled parallel processing</info>', OutputInterface::VERBOSITY_DEBUG); |
||
166 | } |
||
167 | |||
168 | $this->changeWorkingDirectory($input); |
||
169 | |||
170 | $io->writeln($this->getApplication()->getHelp()); |
||
171 | $io->writeln(''); |
||
172 | |||
173 | $config = $input->getOption(self::NO_CONFIG_OPTION) |
||
174 | ? Configuration::create(null, new stdClass()) |
||
175 | : $this->getConfig($input, $output, true) |
||
176 | ; |
||
177 | $path = $config->getOutputPath(); |
||
178 | |||
179 | $logger = new BuildLogger($io); |
||
180 | |||
181 | $startTime = microtime(true); |
||
182 | |||
183 | $this->removeExistingArtifacts($config, $logger, $debug); |
||
184 | |||
185 | $logger->logStartBuilding($path); |
||
186 | |||
187 | $box = $this->createPhar($config, $input, $output, $logger, $io, $debug); |
||
188 | |||
189 | $this->correctPermissions($path, $config, $logger); |
||
190 | |||
191 | $this->logEndBuilding($logger, $io, $box, $path, $startTime); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Taken from Composer. |
||
196 | * |
||
197 | * @see https://github.com/composer/composer/blob/34c371f5f23e25eb9aa54ccc65136cf50930612e/bin/composer#L20-L50 |
||
198 | */ |
||
199 | private static function checkPhpSettings(SymfonyStyle $io, OutputInterface $output): void |
||
200 | { |
||
201 | (new PhpSettingsHandler(new ConsoleLogger($output)))->check(); |
||
202 | |||
203 | if (function_exists('ini_set')) { |
||
204 | $memoryLimit = trim(ini_get('memory_limit')); |
||
205 | |||
206 | // Increase memory_limit if it is lower than 500MB |
||
207 | if ('-1' !== $memoryLimit && memory_to_bytes($memoryLimit) < 1024 * 1024 * 512 && false === getenv('BOX_MEMORY_LIMIT')) { |
||
208 | @ini_set('memory_limit', '512M'); |
||
|
|||
209 | |||
210 | $io->writeln( |
||
211 | sprintf( |
||
212 | '<info>[debug] Bumped the memory limit from "%s" to "%s".</info>', |
||
213 | $memoryLimit, |
||
214 | '512M' |
||
215 | ), |
||
216 | OutputInterface::VERBOSITY_DEBUG |
||
217 | ); |
||
218 | } |
||
219 | |||
220 | // Set user defined memory limit |
||
221 | if ($newMemoryLimit = getenv('BOX_MEMORY_LIMIT')) { |
||
222 | @ini_set('memory_limit', $newMemoryLimit); |
||
223 | |||
224 | $io->writeln( |
||
225 | sprintf( |
||
226 | '<info>[debug] Bumped the memory limit from "%s" to BOX_MEMORY_LIMIT="%s".</info>', |
||
227 | $memoryLimit, |
||
228 | $newMemoryLimit |
||
229 | ), |
||
230 | OutputInterface::VERBOSITY_DEBUG |
||
231 | ); |
||
232 | } |
||
233 | |||
234 | // Note that there is no need to restore since those changes will be applied only to the current process which will die once |
||
235 | // the compilation is done. |
||
236 | } |
||
237 | } |
||
238 | |||
239 | private function createPhar( |
||
240 | Configuration $config, |
||
241 | InputInterface $input, |
||
242 | OutputInterface $output, |
||
243 | BuildLogger $logger, |
||
244 | SymfonyStyle $io, |
||
245 | bool $debug |
||
246 | ): Box { |
||
247 | $box = Box::create( |
||
248 | $config->getTmpOutputPath() |
||
249 | ); |
||
250 | $box->startBuffering(); |
||
251 | |||
252 | $this->registerReplacementValues($config, $box, $logger); |
||
253 | $this->registerCompactors($config, $box, $logger); |
||
254 | $this->registerFileMapping($config, $box, $logger); |
||
255 | |||
256 | // Registering the main script _before_ adding the rest if of the files is _very_ important. The temporary |
||
257 | // file used for debugging purposes and the Composer dump autoloading will not work correctly otherwise. |
||
258 | $main = $this->registerMainScript($config, $box, $logger); |
||
259 | |||
260 | $check = $this->registerRequirementsChecker($config, $box, $logger); |
||
261 | |||
262 | $this->addFiles($config, $box, $logger, $io); |
||
263 | |||
264 | $this->registerStub($config, $box, $main, $check, $logger); |
||
265 | $this->configureMetadata($config, $box, $logger); |
||
266 | |||
267 | $box->endBuffering($config->dumpAutoload()); |
||
268 | |||
269 | $this->configureCompressionAlgorithm($config, $box, $input->getOption(self::DEV_OPTION), $io, $logger); |
||
270 | |||
271 | if ($debug) { |
||
272 | $box->getPhar()->extractTo(self::DEBUG_DIR, null, true); |
||
273 | } |
||
274 | |||
275 | $this->signPhar($config, $box, $config->getTmpOutputPath(), $input, $output, $logger); |
||
276 | |||
277 | if ($config->getTmpOutputPath() !== $config->getOutputPath()) { |
||
278 | rename($config->getTmpOutputPath(), $config->getOutputPath()); |
||
279 | } |
||
280 | |||
281 | return $box; |
||
282 | } |
||
283 | |||
284 | private function removeExistingArtifacts(Configuration $config, BuildLogger $logger, bool $debug): void |
||
285 | { |
||
286 | $path = $config->getOutputPath(); |
||
287 | |||
288 | if ($debug) { |
||
289 | remove(self::DEBUG_DIR); |
||
290 | |||
291 | $date = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->format(DATE_ATOM); |
||
292 | $file = null !== $config->getFile() ? $config->getFile() : 'No config file'; |
||
293 | |||
294 | remove(self::DEBUG_DIR); |
||
295 | |||
296 | dump_file( |
||
297 | self::DEBUG_DIR.'/.box_configuration', |
||
298 | <<<EOF |
||
299 | // |
||
300 | // Processed content of the configuration file "$file" dumped for debugging purposes |
||
301 | // Time: $date |
||
302 | // |
||
303 | |||
304 | |||
305 | EOF |
||
306 | .(new CliDumper())->dump( |
||
307 | (new VarCloner())->cloneVar($config), |
||
308 | true |
||
309 | ) |
||
310 | ); |
||
311 | } |
||
312 | |||
313 | if (false === file_exists($path)) { |
||
314 | return; |
||
315 | } |
||
316 | |||
317 | $logger->log( |
||
318 | BuildLogger::QUESTION_MARK_PREFIX, |
||
319 | sprintf( |
||
320 | 'Removing the existing PHAR "%s"', |
||
321 | $path |
||
322 | ) |
||
323 | ); |
||
324 | |||
325 | remove($path); |
||
326 | } |
||
327 | |||
328 | private function registerReplacementValues(Configuration $config, Box $box, BuildLogger $logger): void |
||
329 | { |
||
330 | $values = $config->getProcessedReplacements(); |
||
331 | |||
332 | if ([] === $values) { |
||
333 | return; |
||
334 | } |
||
335 | |||
336 | $logger->log( |
||
337 | BuildLogger::QUESTION_MARK_PREFIX, |
||
338 | 'Setting replacement values' |
||
339 | ); |
||
340 | |||
341 | foreach ($values as $key => $value) { |
||
342 | $logger->log( |
||
343 | BuildLogger::PLUS_PREFIX, |
||
344 | sprintf( |
||
345 | '%s: %s', |
||
346 | $key, |
||
347 | $value |
||
348 | ) |
||
349 | ); |
||
350 | } |
||
351 | |||
352 | $box->registerPlaceholders($values); |
||
353 | } |
||
354 | |||
355 | private function registerCompactors(Configuration $config, Box $box, BuildLogger $logger): void |
||
356 | { |
||
357 | $compactors = $config->getCompactors(); |
||
358 | |||
359 | if ([] === $compactors) { |
||
360 | $logger->log( |
||
361 | BuildLogger::QUESTION_MARK_PREFIX, |
||
362 | 'No compactor to register' |
||
363 | ); |
||
364 | |||
365 | return; |
||
366 | } |
||
367 | |||
368 | $logger->log( |
||
369 | BuildLogger::QUESTION_MARK_PREFIX, |
||
370 | 'Registering compactors' |
||
371 | ); |
||
372 | |||
373 | $logCompactors = function (Compactor $compactor) use ($logger): void { |
||
374 | $compactorClassParts = explode('\\', get_class($compactor)); |
||
375 | |||
376 | if ('_HumbugBox' === substr($compactorClassParts[0], 0, strlen('_HumbugBox'))) { |
||
377 | // Keep the non prefixed class name for the user |
||
378 | array_shift($compactorClassParts); |
||
379 | } |
||
380 | |||
381 | $logger->log( |
||
382 | BuildLogger::PLUS_PREFIX, |
||
383 | implode('\\', $compactorClassParts) |
||
384 | ); |
||
385 | }; |
||
386 | |||
387 | array_map($logCompactors, $compactors); |
||
388 | |||
389 | $box->registerCompactors($compactors); |
||
390 | } |
||
391 | |||
392 | private function registerFileMapping(Configuration $config, Box $box, BuildLogger $logger): void |
||
393 | { |
||
394 | $fileMapper = $config->getFileMapper(); |
||
395 | |||
396 | $this->logMap($fileMapper, $logger); |
||
397 | |||
398 | $box->registerFileMapping( |
||
399 | $config->getBasePath(), |
||
400 | $fileMapper |
||
401 | ); |
||
402 | } |
||
403 | |||
404 | private function addFiles(Configuration $config, Box $box, BuildLogger $logger, SymfonyStyle $io): void |
||
405 | { |
||
406 | $logger->log(BuildLogger::QUESTION_MARK_PREFIX, 'Adding binary files'); |
||
407 | |||
408 | $count = count($config->getBinaryFiles()); |
||
409 | |||
410 | $box->addFiles($config->getBinaryFiles(), true); |
||
411 | |||
412 | $logger->log( |
||
413 | BuildLogger::CHEVRON_PREFIX, |
||
414 | 0 === $count |
||
415 | ? 'No file found' |
||
416 | : sprintf('%d file(s)', $count) |
||
417 | ); |
||
418 | |||
419 | $logger->log(BuildLogger::QUESTION_MARK_PREFIX, 'Adding files'); |
||
420 | |||
421 | $count = count($config->getFiles()); |
||
422 | |||
423 | try { |
||
424 | $box->addFiles($config->getFiles(), false); |
||
425 | } catch (MultiReasonException $exception) { |
||
426 | // This exception is handled a different way to give me meaningful feedback to the user |
||
427 | foreach ($exception->getReasons() as $reason) { |
||
428 | $io->error($reason); |
||
429 | } |
||
430 | |||
431 | throw $exception; |
||
432 | } |
||
433 | |||
434 | $logger->log( |
||
435 | BuildLogger::CHEVRON_PREFIX, |
||
436 | 0 === $count |
||
437 | ? 'No file found' |
||
438 | : sprintf('%d file(s)', $count) |
||
439 | ); |
||
440 | } |
||
441 | |||
442 | private function registerMainScript(Configuration $config, Box $box, BuildLogger $logger): string |
||
469 | } |
||
470 | |||
471 | private function registerRequirementsChecker(Configuration $config, Box $box, BuildLogger $logger): bool |
||
472 | { |
||
473 | if (false === $config->checkRequirements()) { |
||
474 | return false; |
||
475 | } |
||
476 | |||
477 | $logger->log( |
||
478 | BuildLogger::QUESTION_MARK_PREFIX, |
||
479 | 'Adding requirements checker' |
||
480 | ); |
||
481 | |||
482 | $checkFiles = RequirementsDumper::dump( |
||
483 | $config->getComposerJsonDecodedContents() ?? [], |
||
484 | $config->getComposerLockDecodedContents() ?? [], |
||
485 | $config->getCompressionAlgorithm() |
||
486 | ); |
||
487 | |||
488 | foreach ($checkFiles as $fileWithContents) { |
||
489 | [$file, $contents] = $fileWithContents; |
||
490 | |||
491 | $box->addFile('.box/'.$file, $contents, true); |
||
492 | } |
||
493 | |||
494 | return true; |
||
495 | } |
||
496 | |||
497 | private function registerStub(Configuration $config, Box $box, string $main, bool $checkRequirements, BuildLogger $logger): void |
||
498 | { |
||
499 | if ($config->isStubGenerated()) { |
||
500 | $logger->log( |
||
501 | BuildLogger::QUESTION_MARK_PREFIX, |
||
502 | 'Generating new stub' |
||
503 | ); |
||
504 | |||
505 | $stub = $this->createStub($config, $main, $checkRequirements, $logger); |
||
506 | |||
507 | $box->getPhar()->setStub($stub->generate()); |
||
508 | |||
509 | return; |
||
510 | } |
||
511 | if (null !== ($stub = $config->getStubPath())) { |
||
512 | $logger->log( |
||
513 | BuildLogger::QUESTION_MARK_PREFIX, |
||
514 | sprintf( |
||
515 | 'Using stub file: %s', |
||
516 | $stub |
||
517 | ) |
||
518 | ); |
||
519 | |||
520 | $box->registerStub($stub); |
||
521 | |||
522 | return; |
||
523 | } |
||
524 | |||
525 | // TODO: add warning that the check requirements could not be added |
||
526 | $aliasWasAdded = $box->getPhar()->setAlias($config->getAlias()); |
||
527 | |||
528 | Assertion::true( |
||
529 | $aliasWasAdded, |
||
530 | sprintf( |
||
531 | 'The alias "%s" is invalid. See Phar::setAlias() documentation for more information.', |
||
532 | $config->getAlias() |
||
533 | ) |
||
534 | ); |
||
535 | |||
536 | $box->getPhar()->setDefaultStub($main); |
||
537 | |||
538 | $logger->log( |
||
539 | BuildLogger::QUESTION_MARK_PREFIX, |
||
540 | 'Using default stub' |
||
541 | ); |
||
542 | } |
||
543 | |||
544 | private function configureMetadata(Configuration $config, Box $box, BuildLogger $logger): void |
||
545 | { |
||
546 | if (null !== ($metadata = $config->getMetadata())) { |
||
547 | $logger->log( |
||
548 | BuildLogger::QUESTION_MARK_PREFIX, |
||
549 | 'Setting metadata' |
||
550 | ); |
||
551 | |||
552 | $logger->log( |
||
553 | BuildLogger::MINUS_PREFIX, |
||
554 | is_string($metadata) ? $metadata : var_export($metadata, true) |
||
555 | ); |
||
556 | |||
557 | $box->getPhar()->setMetadata($metadata); |
||
558 | } |
||
559 | } |
||
560 | |||
561 | private function configureCompressionAlgorithm(Configuration $config, Box $box, bool $dev, SymfonyStyle $io, BuildLogger $logger): void |
||
562 | { |
||
563 | if (null === ($algorithm = $config->getCompressionAlgorithm())) { |
||
564 | $logger->log( |
||
565 | BuildLogger::QUESTION_MARK_PREFIX, |
||
566 | $dev |
||
567 | ? 'No compression' |
||
568 | : '<error>No compression</error>' |
||
569 | ); |
||
570 | |||
571 | return; |
||
572 | } |
||
573 | |||
574 | $logger->log( |
||
575 | BuildLogger::QUESTION_MARK_PREFIX, |
||
576 | sprintf( |
||
577 | 'Compressing with the algorithm "<comment>%s</comment>"', |
||
578 | array_search($algorithm, get_phar_compression_algorithms(), true) |
||
1 ignored issue
–
show
|
|||
579 | ) |
||
580 | ); |
||
581 | |||
582 | $restoreLimit = $this->bumpOpenFileDescriptorLimit($box, $io); |
||
583 | |||
584 | try { |
||
585 | $extension = $box->compress($algorithm); |
||
586 | |||
587 | if (null !== $extension) { |
||
588 | $logger->log( |
||
589 | BuildLogger::CHEVRON_PREFIX, |
||
590 | sprintf( |
||
591 | '<info>Warning: the extension "%s" will now be required to execute the PHAR</info>', |
||
592 | $extension |
||
593 | ) |
||
594 | ); |
||
595 | } |
||
596 | } catch (RuntimeException $exception) { |
||
597 | $io->error($exception->getMessage()); |
||
598 | |||
599 | // Continue: the compression failure should not result in completely bailing out the compilation process |
||
600 | } finally { |
||
601 | $restoreLimit(); |
||
602 | } |
||
603 | } |
||
604 | |||
605 | /** |
||
606 | * Bumps the maximum number of open file descriptor if necessary. |
||
607 | * |
||
608 | * @return callable callable to call to restore the original maximum number of open files descriptors |
||
609 | */ |
||
610 | private function bumpOpenFileDescriptorLimit(Box $box, SymfonyStyle $io): callable |
||
611 | { |
||
612 | $filesCount = count($box) + 128; // Add a little extra for good measure |
||
613 | |||
614 | if (function_exists('posix_getrlimit') && function_exists('posix_setrlimit')) { |
||
615 | $softLimit = posix_getrlimit()['soft openfiles']; |
||
616 | $hardLimit = posix_getrlimit()['hard openfiles']; |
||
617 | |||
618 | if ($softLimit < $filesCount) { |
||
619 | $io->writeln( |
||
620 | sprintf( |
||
621 | '<info>[debug] Increased the maximum number of open file descriptors from ("%s", "%s") to ("%s", "%s")' |
||
622 | .'</info>', |
||
623 | $softLimit, |
||
624 | $hardLimit, |
||
625 | $filesCount, |
||
626 | 'unlimited' |
||
627 | ), |
||
628 | OutputInterface::VERBOSITY_DEBUG |
||
629 | ); |
||
630 | |||
631 | posix_setrlimit( |
||
632 | POSIX_RLIMIT_NOFILE, |
||
633 | $filesCount, |
||
634 | 'unlimited' === $hardLimit ? POSIX_RLIMIT_INFINITY : $hardLimit |
||
635 | ); |
||
636 | } |
||
637 | } else { |
||
638 | $io->writeln( |
||
639 | '<info>[debug] Could not check the maximum number of open file descriptors: the functions "posix_getrlimit()" and ' |
||
640 | .'"posix_setrlimit" could not be found.</info>', |
||
641 | OutputInterface::VERBOSITY_DEBUG |
||
642 | ); |
||
643 | } |
||
644 | |||
645 | return function () use ($io, $softLimit, $hardLimit): void { |
||
646 | if (function_exists('posix_setrlimit') && isset($softLimit, $hardLimit)) { |
||
647 | posix_setrlimit( |
||
648 | POSIX_RLIMIT_NOFILE, |
||
649 | $softLimit, |
||
650 | 'unlimited' === $hardLimit ? POSIX_RLIMIT_INFINITY : $hardLimit |
||
651 | ); |
||
652 | |||
653 | $io->writeln( |
||
654 | '<info>[debug] Restored the maximum number of open file descriptors</info>', |
||
655 | OutputInterface::VERBOSITY_DEBUG |
||
656 | ); |
||
657 | } |
||
658 | }; |
||
659 | } |
||
660 | |||
661 | private function signPhar( |
||
662 | Configuration $config, |
||
663 | Box $box, |
||
664 | string $path, |
||
665 | InputInterface $input, |
||
666 | OutputInterface $output, |
||
667 | BuildLogger $logger |
||
668 | ): void { |
||
669 | // sign using private key, if applicable |
||
670 | //TODO: check that out |
||
671 | remove($path.'.pubkey'); |
||
672 | |||
673 | $key = $config->getPrivateKeyPath(); |
||
674 | |||
675 | if (null === $key) { |
||
676 | if (null !== ($algorithm = $config->getSigningAlgorithm())) { |
||
677 | $box->getPhar()->setSignatureAlgorithm($algorithm); |
||
678 | } |
||
679 | |||
680 | return; |
||
681 | } |
||
682 | |||
683 | $logger->log( |
||
684 | BuildLogger::QUESTION_MARK_PREFIX, |
||
685 | 'Signing using a private key' |
||
686 | ); |
||
687 | |||
688 | $passphrase = $config->getPrivateKeyPassphrase(); |
||
689 | |||
690 | if ($config->isPrivateKeyPrompt()) { |
||
691 | if (false === $input->isInteractive()) { |
||
692 | throw new RuntimeException( |
||
693 | sprintf( |
||
694 | 'Accessing to the private key "%s" requires a passphrase but none provided. Either ' |
||
695 | .'provide one or run this command in interactive mode.', |
||
696 | $key |
||
697 | ) |
||
698 | ); |
||
699 | } |
||
700 | |||
701 | /** @var $dialog QuestionHelper */ |
||
702 | $dialog = $this->getHelper('question'); |
||
703 | |||
704 | $question = new Question('Private key passphrase:'); |
||
705 | $question->setHidden(false); |
||
706 | $question->setHiddenFallback(false); |
||
707 | |||
708 | $passphrase = $dialog->ask($input, $output, $question); |
||
709 | |||
710 | $output->writeln(''); |
||
711 | } |
||
712 | |||
713 | $box->signUsingFile($key, $passphrase); |
||
714 | } |
||
715 | |||
716 | private function correctPermissions(string $path, Configuration $config, BuildLogger $logger): void |
||
717 | { |
||
718 | if (null !== ($chmod = $config->getFileMode())) { |
||
719 | $logger->log( |
||
720 | BuildLogger::QUESTION_MARK_PREFIX, |
||
721 | sprintf( |
||
722 | 'Setting file permissions to <comment>%s</comment>', |
||
723 | '0'.decoct($chmod) |
||
724 | ) |
||
725 | ); |
||
726 | |||
727 | chmod($path, $chmod); |
||
728 | } |
||
729 | } |
||
730 | |||
731 | private function createStub(Configuration $config, ?string $main, bool $checkRequirements, BuildLogger $logger): StubGenerator |
||
786 | } |
||
787 | |||
788 | private function logMap(MapFile $fileMapper, BuildLogger $logger): void |
||
789 | { |
||
790 | $map = $fileMapper->getMap(); |
||
791 | |||
792 | if ([] === $map) { |
||
793 | return; |
||
794 | } |
||
795 | |||
796 | $logger->log( |
||
797 | BuildLogger::QUESTION_MARK_PREFIX, |
||
814 | ) |
||
815 | ); |
||
816 | } |
||
817 | } |
||
818 | } |
||
819 | |||
820 | private function logEndBuilding(BuildLogger $logger, SymfonyStyle $io, Box $box, string $path, float $startTime): void |
||
847 |
If you suppress an error, we recommend checking for the error condition explicitly: