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