|
28 | 28 | use Symfony\Component\Filesystem\Filesystem;
|
29 | 29 | use Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException;
|
30 | 30 | use Symfony\Installer\Exception\AbortException;
|
| 31 | +use Symfony\Installer\Manager\ComposerManager; |
31 | 32 |
|
32 | 33 | /**
|
33 | 34 | * Abstract command used by commands which download and extract compressed Symfony files.
|
@@ -82,6 +83,9 @@ abstract class DownloadCommand extends Command
|
82 | 83 | */
|
83 | 84 | protected $requirementsErrors = array();
|
84 | 85 |
|
| 86 | + /** @var ComposerManager */ |
| 87 | + protected $composerManager; |
| 88 | + |
85 | 89 | /**
|
86 | 90 | * Returns the type of the downloaded application in a human readable format.
|
87 | 91 | * It's mainly used to display readable error messages.
|
@@ -363,23 +367,9 @@ private function getSymfonyRequirementsFilePath()
|
363 | 367 | *
|
364 | 368 | * @return $this
|
365 | 369 | */
|
366 |
| - protected function updateComposerJson() |
| 370 | + protected function updateComposerConfig() |
367 | 371 | {
|
368 |
| - $composerConfig = $this->getProjectComposerConfig(); |
369 |
| - |
370 |
| - if (isset($composerConfig['config']['platform']['php'])) { |
371 |
| - unset($composerConfig['config']['platform']['php']); |
372 |
| - |
373 |
| - if (empty($composerConfig['config']['platform'])) { |
374 |
| - unset($composerConfig['config']['platform']); |
375 |
| - } |
376 |
| - |
377 |
| - if (empty($composerConfig['config'])) { |
378 |
| - unset($composerConfig['config']); |
379 |
| - } |
380 |
| - } |
381 |
| - |
382 |
| - $this->saveProjectComposerConfig($composerConfig); |
| 372 | + $this->composerManager->initializeProjectConfig(); |
383 | 373 |
|
384 | 374 | return $this;
|
385 | 375 | }
|
@@ -418,17 +408,13 @@ protected function createGitIgnore()
|
418 | 408 | */
|
419 | 409 | protected function getInstalledSymfonyVersion()
|
420 | 410 | {
|
421 |
| - $composer = json_decode(file_get_contents($this->projectDir.'/composer.lock'), true); |
| 411 | + $symfonyVersion = $this->composerManager->getPackageVersion('symfony/symfony'); |
422 | 412 |
|
423 |
| - foreach ($composer['packages'] as $package) { |
424 |
| - if ('symfony/symfony' === $package['name']) { |
425 |
| - if ('v' === substr($package['version'], 0, 1)) { |
426 |
| - return substr($package['version'], 1); |
427 |
| - }; |
| 413 | + if (!empty($symfonyVersion) && 'v' === substr($symfonyVersion, 0, 1)) { |
| 414 | + return substr($symfonyVersion, 1); |
| 415 | + }; |
428 | 416 |
|
429 |
| - return $package['version']; |
430 |
| - } |
431 |
| - } |
| 417 | + return $symfonyVersion; |
432 | 418 | }
|
433 | 419 |
|
434 | 420 | /**
|
@@ -520,7 +506,6 @@ protected function getExecutedCommand()
|
520 | 506 | }
|
521 | 507 |
|
522 | 508 | $commandName = $this->getName();
|
523 |
| - $commandArguments = ''; |
524 | 509 |
|
525 | 510 | if ('new' === $commandName) {
|
526 | 511 | $commandArguments = sprintf('%s %s', $this->projectName, ('latest' !== $this->version) ? $this->version : '');
|
@@ -601,107 +586,6 @@ protected function getUrlContents($url)
|
601 | 586 | return $client->get($url)->getBody()->getContents();
|
602 | 587 | }
|
603 | 588 |
|
604 |
| - /** |
605 |
| - * It returns the project's Composer config as a PHP array. |
606 |
| - * |
607 |
| - * @return $this|array |
608 |
| - */ |
609 |
| - protected function getProjectComposerConfig() |
610 |
| - { |
611 |
| - $composerJsonFilepath = $this->projectDir.'/composer.json'; |
612 |
| - |
613 |
| - if (!is_writable($composerJsonFilepath)) { |
614 |
| - if ($this->output->isVerbose()) { |
615 |
| - $this->output->writeln(sprintf( |
616 |
| - " <comment>[WARNING]</comment> Project's Composer config cannot be updated because\n". |
617 |
| - " the <comment>%s</comment> file is not writable.\n", |
618 |
| - $composerJsonFilepath |
619 |
| - )); |
620 |
| - } |
621 |
| - |
622 |
| - return $this; |
623 |
| - } |
624 |
| - |
625 |
| - return json_decode(file_get_contents($composerJsonFilepath), true); |
626 |
| - } |
627 |
| - |
628 |
| - /** |
629 |
| - * It saves the given PHP array as the project's Composer config. In addition |
630 |
| - * to JSON-serializing the contents, it synchronizes the composer.lock file to |
631 |
| - * avoid out-of-sync Composer errors. |
632 |
| - * |
633 |
| - * @param array $config |
634 |
| - */ |
635 |
| - protected function saveProjectComposerConfig(array $config) |
636 |
| - { |
637 |
| - $composerJsonFilepath = $this->projectDir.'/composer.json'; |
638 |
| - $this->fs->dumpFile($composerJsonFilepath, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); |
639 |
| - |
640 |
| - $this->syncComposerLockFile(); |
641 |
| - } |
642 |
| - |
643 |
| - /** |
644 |
| - * Updates the hash values stored in composer.lock to avoid out-of-sync |
645 |
| - * problems when the composer.json file contents are changed. |
646 |
| - */ |
647 |
| - private function syncComposerLockFile() |
648 |
| - { |
649 |
| - $composerJsonFileContents = file_get_contents($this->projectDir.'/composer.json'); |
650 |
| - $composerLockFileContents = json_decode(file_get_contents($this->projectDir.'/composer.lock'), true); |
651 |
| - |
652 |
| - if (array_key_exists('hash', $composerLockFileContents)) { |
653 |
| - $composerLockFileContents['hash'] = md5($composerJsonFileContents); |
654 |
| - } |
655 |
| - |
656 |
| - if (array_key_exists('content-hash', $composerLockFileContents)) { |
657 |
| - $composerLockFileContents['content-hash'] = $this->getComposerContentHash($composerJsonFileContents); |
658 |
| - } |
659 |
| - |
660 |
| - $this->fs->dumpFile($this->projectDir.'/composer.lock', json_encode($composerLockFileContents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); |
661 |
| - } |
662 |
| - |
663 |
| - /** |
664 |
| - * Returns the md5 hash of the sorted content of the composer file. |
665 |
| - * |
666 |
| - * @see https://github.com/composer/composer/blob/master/src/Composer/Package/Locker.php (getContentHash() method) |
667 |
| - * |
668 |
| - * @param string $composerJsonFileContents The contents of the composer.json file. |
669 |
| - * |
670 |
| - * @return string The hash of the composer file content. |
671 |
| - */ |
672 |
| - private function getComposerContentHash($composerJsonFileContents) |
673 |
| - { |
674 |
| - $composerConfig = json_decode($composerJsonFileContents, true); |
675 |
| - |
676 |
| - $relevantKeys = array( |
677 |
| - 'name', |
678 |
| - 'version', |
679 |
| - 'require', |
680 |
| - 'require-dev', |
681 |
| - 'conflict', |
682 |
| - 'replace', |
683 |
| - 'provide', |
684 |
| - 'minimum-stability', |
685 |
| - 'prefer-stable', |
686 |
| - 'repositories', |
687 |
| - 'extra', |
688 |
| - ); |
689 |
| - |
690 |
| - $relevantComposerConfig = array(); |
691 |
| - |
692 |
| - foreach (array_intersect($relevantKeys, array_keys($composerConfig)) as $key) { |
693 |
| - $relevantComposerConfig[$key] = $composerConfig[$key]; |
694 |
| - } |
695 |
| - |
696 |
| - if (isset($composerConfig['config']['platform'])) { |
697 |
| - $relevantComposerConfig['config']['platform'] = $composerConfig['config']['platform']; |
698 |
| - } |
699 |
| - |
700 |
| - ksort($relevantComposerConfig); |
701 |
| - |
702 |
| - return md5(json_encode($relevantComposerConfig)); |
703 |
| - } |
704 |
| - |
705 | 589 | /**
|
706 | 590 | * Enables the signal handler.
|
707 | 591 | *
|
|
0 commit comments