| Total Complexity | 74 |
| Total Lines | 771 |
| 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 |
||
| 72 | class Compile extends Configurable |
||
| 73 | { |
||
| 74 | use ChangeableWorkingDirectory; |
||
| 75 | |||
| 76 | private const HELP = <<<'HELP' |
||
| 77 | The <info>%command.name%</info> command will compile code in a new PHAR based on a variety of settings. |
||
| 78 | <comment> |
||
| 79 | This command relies on a configuration file for loading |
||
| 80 | PHAR packaging settings. If a configuration file is not |
||
| 81 | specified through the <info>--config|-c</info> option, one of |
||
| 82 | the following files will be used (in order): <info>box.json</info>, |
||
| 83 | <info>box.json.dist</info> |
||
| 84 | </comment> |
||
| 85 | The configuration file is actually a JSON object saved to a file. For more |
||
| 86 | information check the documentation online: |
||
| 87 | <comment> |
||
| 88 | https://github.com/humbug/box |
||
| 89 | </comment> |
||
| 90 | HELP; |
||
| 91 | |||
| 92 | private const DEBUG_OPTION = 'debug'; |
||
| 93 | private const NO_PARALLEL_PROCESSING_OPTION = 'no-parallel'; |
||
| 94 | private const NO_RESTART_OPTION = 'no-restart'; |
||
| 95 | private const DEV_OPTION = 'dev'; |
||
| 96 | private const NO_CONFIG_OPTION = 'no-config'; |
||
| 97 | |||
| 98 | private const DEBUG_DIR = '.box_dump'; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * {@inheritdoc} |
||
| 102 | */ |
||
| 103 | protected function configure(): void |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * {@inheritdoc} |
||
| 147 | */ |
||
| 148 | protected function execute(InputInterface $input, OutputInterface $output): void |
||
| 149 | { |
||
| 150 | $io = new SymfonyStyle($input, $output); |
||
| 151 | |||
| 152 | if ($input->getOption(self::NO_RESTART_OPTION)) { |
||
| 153 | putenv(BOX_ALLOW_XDEBUG.'=1'); |
||
| 154 | } |
||
| 155 | |||
| 156 | if ($debug = $input->getOption(self::DEBUG_OPTION)) { |
||
| 157 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
||
| 158 | } |
||
| 159 | |||
| 160 | (new PhpSettingsHandler(new ConsoleLogger($output)))->check(); |
||
| 161 | |||
| 162 | if ($input->getOption(self::NO_PARALLEL_PROCESSING_OPTION)) { |
||
| 163 | disable_parallel_processing(); |
||
| 164 | $io->writeln('<info>[debug] Disabled parallel processing</info>', OutputInterface::VERBOSITY_DEBUG); |
||
| 165 | } |
||
| 166 | |||
| 167 | $this->changeWorkingDirectory($input); |
||
| 168 | |||
| 169 | $io->writeln($this->getApplication()->getHelp()); |
||
| 170 | $io->writeln(''); |
||
| 171 | |||
| 172 | $config = $input->getOption(self::NO_CONFIG_OPTION) |
||
| 173 | ? Configuration::create(null, new stdClass()) |
||
| 174 | : $this->getConfig($input, $output, true) |
||
| 175 | ; |
||
| 176 | $path = $config->getOutputPath(); |
||
| 177 | |||
| 178 | $logger = new BuildLogger($io); |
||
| 179 | |||
| 180 | $startTime = microtime(true); |
||
| 181 | |||
| 182 | $this->removeExistingArtifacts($config, $logger, $debug); |
||
| 183 | |||
| 184 | $logger->logStartBuilding($path); |
||
| 185 | |||
| 186 | $box = $this->createPhar($config, $input, $output, $logger, $io, $debug); |
||
| 187 | |||
| 188 | $this->correctPermissions($path, $config, $logger); |
||
| 189 | |||
| 190 | $this->logEndBuilding($logger, $io, $box, $path, $startTime); |
||
| 191 | } |
||
| 192 | |||
| 193 | private function createPhar( |
||
| 194 | Configuration $config, |
||
| 195 | InputInterface $input, |
||
| 196 | OutputInterface $output, |
||
| 197 | BuildLogger $logger, |
||
| 198 | SymfonyStyle $io, |
||
| 199 | bool $debug |
||
| 200 | ): Box { |
||
| 201 | $box = Box::create( |
||
| 202 | $config->getTmpOutputPath() |
||
| 203 | ); |
||
| 204 | $box->startBuffering(); |
||
| 205 | |||
| 206 | $this->registerReplacementValues($config, $box, $logger); |
||
| 207 | $this->registerCompactors($config, $box, $logger); |
||
| 208 | $this->registerFileMapping($config, $box, $logger); |
||
| 209 | |||
| 210 | // Registering the main script _before_ adding the rest if of the files is _very_ important. The temporary |
||
| 211 | // file used for debugging purposes and the Composer dump autoloading will not work correctly otherwise. |
||
| 212 | $main = $this->registerMainScript($config, $box, $logger); |
||
| 213 | |||
| 214 | $check = $this->registerRequirementsChecker($config, $box, $logger); |
||
| 215 | |||
| 216 | $this->addFiles($config, $box, $logger, $io); |
||
| 217 | |||
| 218 | $this->registerStub($config, $box, $main, $check, $logger); |
||
| 219 | $this->configureMetadata($config, $box, $logger); |
||
| 220 | |||
| 221 | $this->commit($box, $config, $logger); |
||
| 222 | |||
| 223 | $this->checkComposerFiles($box, $config, $logger); |
||
| 224 | |||
| 225 | $this->configureCompressionAlgorithm($config, $box, $input->getOption(self::DEV_OPTION), $io, $logger); |
||
| 226 | |||
| 227 | if ($debug) { |
||
| 228 | $box->getPhar()->extractTo(self::DEBUG_DIR, null, true); |
||
| 229 | } |
||
| 230 | |||
| 231 | $this->signPhar($config, $box, $config->getTmpOutputPath(), $input, $output, $logger); |
||
| 232 | |||
| 233 | if ($config->getTmpOutputPath() !== $config->getOutputPath()) { |
||
| 234 | rename($config->getTmpOutputPath(), $config->getOutputPath()); |
||
| 235 | } |
||
| 236 | |||
| 237 | return $box; |
||
| 238 | } |
||
| 239 | |||
| 240 | private function removeExistingArtifacts(Configuration $config, BuildLogger $logger, bool $debug): void |
||
| 241 | { |
||
| 242 | $path = $config->getOutputPath(); |
||
| 243 | |||
| 244 | if ($debug) { |
||
| 245 | remove(self::DEBUG_DIR); |
||
| 246 | |||
| 247 | $date = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->format(DATE_ATOM); |
||
| 248 | $file = null !== $config->getFile() ? $config->getFile() : 'No config file'; |
||
| 249 | |||
| 250 | remove(self::DEBUG_DIR); |
||
| 251 | |||
| 252 | dump_file( |
||
| 253 | self::DEBUG_DIR.'/.box_configuration', |
||
| 254 | <<<EOF |
||
| 255 | // |
||
| 256 | // Processed content of the configuration file "$file" dumped for debugging purposes |
||
| 257 | // Time: $date |
||
| 258 | // |
||
| 259 | |||
| 260 | |||
| 261 | EOF |
||
| 262 | .(new CliDumper())->dump( |
||
| 263 | (new VarCloner())->cloneVar($config), |
||
| 264 | true |
||
| 265 | ) |
||
| 266 | ); |
||
| 267 | } |
||
| 268 | |||
| 269 | if (false === file_exists($path)) { |
||
| 270 | return; |
||
| 271 | } |
||
| 272 | |||
| 273 | $logger->log( |
||
| 274 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 275 | sprintf( |
||
| 276 | 'Removing the existing PHAR "%s"', |
||
| 277 | $path |
||
| 278 | ) |
||
| 279 | ); |
||
| 280 | |||
| 281 | remove($path); |
||
| 282 | } |
||
| 283 | |||
| 284 | private function registerReplacementValues(Configuration $config, Box $box, BuildLogger $logger): void |
||
| 285 | { |
||
| 286 | $values = $config->getProcessedReplacements(); |
||
| 287 | |||
| 288 | if ([] === $values) { |
||
| 289 | return; |
||
| 290 | } |
||
| 291 | |||
| 292 | $logger->log( |
||
| 293 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 294 | 'Setting replacement values' |
||
| 295 | ); |
||
| 296 | |||
| 297 | foreach ($values as $key => $value) { |
||
| 298 | $logger->log( |
||
| 299 | BuildLogger::PLUS_PREFIX, |
||
| 300 | sprintf( |
||
| 301 | '%s: %s', |
||
| 302 | $key, |
||
| 303 | $value |
||
| 304 | ) |
||
| 305 | ); |
||
| 306 | } |
||
| 307 | |||
| 308 | $box->registerPlaceholders($values); |
||
| 309 | } |
||
| 310 | |||
| 311 | private function registerCompactors(Configuration $config, Box $box, BuildLogger $logger): void |
||
| 312 | { |
||
| 313 | $compactors = $config->getCompactors(); |
||
| 314 | |||
| 315 | if ([] === $compactors) { |
||
| 316 | $logger->log( |
||
| 317 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 318 | 'No compactor to register' |
||
| 319 | ); |
||
| 320 | |||
| 321 | return; |
||
| 322 | } |
||
| 323 | |||
| 324 | $logger->log( |
||
| 325 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 326 | 'Registering compactors' |
||
| 327 | ); |
||
| 328 | |||
| 329 | $logCompactors = function (Compactor $compactor) use ($logger): void { |
||
| 330 | $compactorClassParts = explode('\\', get_class($compactor)); |
||
| 331 | |||
| 332 | if ('_HumbugBox' === substr($compactorClassParts[0], 0, strlen('_HumbugBox'))) { |
||
| 333 | // Keep the non prefixed class name for the user |
||
| 334 | array_shift($compactorClassParts); |
||
| 335 | } |
||
| 336 | |||
| 337 | $logger->log( |
||
| 338 | BuildLogger::PLUS_PREFIX, |
||
| 339 | implode('\\', $compactorClassParts) |
||
| 340 | ); |
||
| 341 | }; |
||
| 342 | |||
| 343 | array_map($logCompactors, $compactors); |
||
| 344 | |||
| 345 | $box->registerCompactors($compactors); |
||
| 346 | } |
||
| 347 | |||
| 348 | private function registerFileMapping(Configuration $config, Box $box, BuildLogger $logger): void |
||
| 349 | { |
||
| 350 | $fileMapper = $config->getFileMapper(); |
||
| 351 | |||
| 352 | $this->logMap($fileMapper, $logger); |
||
| 353 | |||
| 354 | $box->registerFileMapping( |
||
| 355 | $config->getBasePath(), |
||
| 356 | $fileMapper |
||
| 357 | ); |
||
| 358 | } |
||
| 359 | |||
| 360 | private function addFiles(Configuration $config, Box $box, BuildLogger $logger, SymfonyStyle $io): void |
||
| 361 | { |
||
| 362 | $logger->log(BuildLogger::QUESTION_MARK_PREFIX, 'Adding binary files'); |
||
| 363 | |||
| 364 | $count = count($config->getBinaryFiles()); |
||
| 365 | |||
| 366 | $box->addFiles($config->getBinaryFiles(), true); |
||
| 367 | |||
| 368 | $logger->log( |
||
| 369 | BuildLogger::CHEVRON_PREFIX, |
||
| 370 | 0 === $count |
||
| 371 | ? 'No file found' |
||
| 372 | : sprintf('%d file(s)', $count) |
||
| 373 | ); |
||
| 374 | |||
| 375 | $logger->log(BuildLogger::QUESTION_MARK_PREFIX, 'Adding files'); |
||
| 376 | |||
| 377 | $count = count($config->getFiles()); |
||
| 378 | |||
| 379 | try { |
||
| 380 | $box->addFiles($config->getFiles(), false); |
||
| 381 | } catch (MultiReasonException $exception) { |
||
| 382 | // This exception is handled a different way to give me meaningful feedback to the user |
||
| 383 | foreach ($exception->getReasons() as $reason) { |
||
| 384 | $io->error($reason); |
||
| 385 | } |
||
| 386 | |||
| 387 | throw $exception; |
||
| 388 | } |
||
| 389 | |||
| 390 | $logger->log( |
||
| 391 | BuildLogger::CHEVRON_PREFIX, |
||
| 392 | 0 === $count |
||
| 393 | ? 'No file found' |
||
| 394 | : sprintf('%d file(s)', $count) |
||
| 395 | ); |
||
| 396 | } |
||
| 397 | |||
| 398 | private function registerMainScript(Configuration $config, Box $box, BuildLogger $logger): ?string |
||
| 399 | { |
||
| 400 | if (false === $config->hasMainScript()) { |
||
| 401 | $logger->log( |
||
| 402 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 403 | 'No main script path configured' |
||
| 404 | ); |
||
| 405 | |||
| 406 | return null; |
||
| 407 | } |
||
| 408 | |||
| 409 | $main = $config->getMainScriptPath(); |
||
| 410 | |||
| 411 | $logger->log( |
||
| 412 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 413 | sprintf( |
||
| 414 | 'Adding main file: %s', |
||
| 415 | $main |
||
| 416 | ) |
||
| 417 | ); |
||
| 418 | |||
| 419 | $localMain = $box->addFile( |
||
| 420 | $main, |
||
| 421 | $config->getMainScriptContents() |
||
| 422 | ); |
||
| 423 | |||
| 424 | $relativeMain = make_path_relative($main, $config->getBasePath()); |
||
| 425 | |||
| 426 | if ($localMain !== $relativeMain) { |
||
| 427 | $logger->log( |
||
| 428 | BuildLogger::CHEVRON_PREFIX, |
||
| 429 | $localMain |
||
| 430 | ); |
||
| 431 | } |
||
| 432 | |||
| 433 | return $localMain; |
||
| 434 | } |
||
| 435 | |||
| 436 | private function registerRequirementsChecker(Configuration $config, Box $box, BuildLogger $logger): bool |
||
| 437 | { |
||
| 438 | if (false === $config->checkRequirements()) { |
||
| 439 | $logger->log( |
||
| 440 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 441 | 'Skip requirements checker' |
||
| 442 | ); |
||
| 443 | |||
| 444 | return false; |
||
| 445 | } |
||
| 446 | |||
| 447 | $logger->log( |
||
| 448 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 449 | 'Adding requirements checker' |
||
| 450 | ); |
||
| 451 | |||
| 452 | $checkFiles = RequirementsDumper::dump( |
||
| 453 | $config->getComposerJsonDecodedContents() ?? [], |
||
| 454 | $config->getComposerLockDecodedContents() ?? [], |
||
| 455 | $config->getCompressionAlgorithm() |
||
| 456 | ); |
||
| 457 | |||
| 458 | foreach ($checkFiles as $fileWithContents) { |
||
| 459 | [$file, $contents] = $fileWithContents; |
||
| 460 | |||
| 461 | $box->addFile('.box/'.$file, $contents, true); |
||
| 462 | } |
||
| 463 | |||
| 464 | return true; |
||
| 465 | } |
||
| 466 | |||
| 467 | private function registerStub(Configuration $config, Box $box, ?string $main, bool $checkRequirements, BuildLogger $logger): void |
||
| 468 | { |
||
| 469 | if ($config->isStubGenerated()) { |
||
| 470 | $logger->log( |
||
| 471 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 472 | 'Generating new stub' |
||
| 473 | ); |
||
| 474 | |||
| 475 | $stub = $this->createStub($config, $main, $checkRequirements, $logger); |
||
| 476 | |||
| 477 | $box->getPhar()->setStub($stub->generate()); |
||
| 478 | |||
| 479 | return; |
||
| 480 | } |
||
| 481 | if (null !== ($stub = $config->getStubPath())) { |
||
| 482 | $logger->log( |
||
| 483 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 484 | sprintf( |
||
| 485 | 'Using stub file: %s', |
||
| 486 | $stub |
||
| 487 | ) |
||
| 488 | ); |
||
| 489 | |||
| 490 | $box->registerStub($stub); |
||
| 491 | |||
| 492 | return; |
||
| 493 | } |
||
| 494 | |||
| 495 | // TODO: add warning that the check requirements could not be added |
||
| 496 | $aliasWasAdded = $box->getPhar()->setAlias($config->getAlias()); |
||
| 497 | |||
| 498 | Assertion::true( |
||
| 499 | $aliasWasAdded, |
||
| 500 | sprintf( |
||
| 501 | 'The alias "%s" is invalid. See Phar::setAlias() documentation for more information.', |
||
| 502 | $config->getAlias() |
||
| 503 | ) |
||
| 504 | ); |
||
| 505 | |||
| 506 | $box->getPhar()->setDefaultStub($main); |
||
| 507 | |||
| 508 | $logger->log( |
||
| 509 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 510 | 'Using default stub' |
||
| 511 | ); |
||
| 512 | } |
||
| 513 | |||
| 514 | private function configureMetadata(Configuration $config, Box $box, BuildLogger $logger): void |
||
| 515 | { |
||
| 516 | if (null !== ($metadata = $config->getMetadata())) { |
||
| 517 | $logger->log( |
||
| 518 | BuildLogger::QUESTION_MARK_PREFIX, |
||
| 519 | 'Setting metadata' |
||
| 520 | ); |
||
| 521 | |||
| 522 | $logger->log( |
||
| 523 | BuildLogger::MINUS_PREFIX, |
||
| 524 | is_string($metadata) ? $metadata : var_export($metadata, true) |
||
| 525 | ); |
||
| 526 | |||
| 527 | $box->getPhar()->setMetadata($metadata); |
||
| 528 | } |
||
| 529 | } |
||
| 530 | |||
| 531 | private function commit(Box $box, Configuration $config, BuildLogger $logger): void |
||
| 532 | { |
||
| 533 | $message = $config->dumpAutoload() |
||
| 534 | ? 'Dumping the Composer autoloader' |
||
| 535 | : 'Skipping dumping the Composer autoloader' |
||
| 536 | ; |
||
| 537 | |||
| 538 | $logger->log(BuildLogger::QUESTION_MARK_PREFIX, $message); |
||
| 539 | |||
| 540 | $box->endBuffering($config->dumpAutoload()); |
||
| 541 | } |
||
| 542 | |||
| 543 | private function checkComposerFiles(Box $box, Configuration $config, BuildLogger $logger): void |
||
| 544 | { |
||
| 545 | $message = $config->excludeComposerFiles() |
||
| 546 | ? 'Removing the Composer dump artefacts' |
||
| 547 | : 'Keep the Composer dump artefacts' |
||
| 548 | ; |
||
| 549 | |||
| 550 | $logger->log(BuildLogger::QUESTION_MARK_PREFIX, $message); |
||
| 551 | |||
| 552 | if ($config->excludeComposerFiles()) { |
||
| 553 | $box->removeComposerArtefacts( |
||
| 554 | ComposerConfiguration::retrieveVendorDir( |
||
| 555 | $config->getComposerJsonDecodedContents() ?? [] |
||
| 556 | ) |
||
| 557 | ); |
||
| 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 |
||
| 814 | ) |
||
| 815 | ); |
||
| 816 | } |
||
| 817 | } |
||
| 818 | } |
||
| 819 | |||
| 820 | private function logEndBuilding(BuildLogger $logger, SymfonyStyle $io, Box $box, string $path, float $startTime): void |
||
| 843 | ) |
||
| 844 | ); |
||
| 845 | } |
||
| 846 | } |
||
| 847 |