Skip to content

Commit d790a5c

Browse files
Restore compat with Composer 1
1 parent 186f05e commit d790a5c

14 files changed

+1240
-41
lines changed

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sudo: false
55
matrix:
66
include:
77
- php: 7.1
8-
env: COMPOSER_FLAGS='--prefer-lowest'
8+
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
99
- php: 7.2
1010
- php: 7.3
1111
- php: 7.4
@@ -24,12 +24,16 @@ env:
2424

2525
before_install:
2626
- ([[ $TRAVIS_PHP_VERSION = nightly ]] && composer config platform.php 7.4.99 || true)
27-
- composer self-update --snapshot
2827
- composer validate
2928

3029
install:
30+
- composer require --no-update composer/composer:^1.0.2
3131
- composer update $COMPOSER_FLAGS
3232

3333
script:
34+
- ./vendor/bin/simple-phpunit
35+
- composer self-update --snapshot
36+
- composer require --no-update composer/composer:^2
37+
- composer update $COMPOSER_FLAGS
3438
- ./vendor/bin/simple-phpunit
3539
- find src/ -name '*.php' | xargs -n1 php -l

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
"minimum-stability": "dev",
1313
"require": {
1414
"php": ">=7.1",
15-
"composer-plugin-api": "^2.0"
15+
"composer-plugin-api": "^1.0|^2.0"
1616
},
1717
"require-dev": {
18-
"composer/composer": "^2.0@dev",
18+
"composer/composer": "^1.0.2|^2.0",
1919
"symfony/dotenv": "^4.4|^5.0",
2020
"symfony/phpunit-bridge": "^4.4|^5.0",
21-
"symfony/process": "^4.4|^5.0"
21+
"symfony/process": "^3.4|^4.4|^5.0"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -27,7 +27,7 @@
2727
},
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "2.0-dev"
30+
"dev-master": "1.8-dev"
3131
},
3232
"class": "Symfony\\Flex\\Flex"
3333
}

src/Cache.php

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Flex;
13+
14+
use Composer\Cache as BaseCache;
15+
use Composer\IO\IOInterface;
16+
use Composer\Semver\Constraint\Constraint;
17+
use Composer\Semver\VersionParser;
18+
19+
/**
20+
* @author Nicolas Grekas <[email protected]>
21+
*/
22+
class Cache extends BaseCache
23+
{
24+
private $versions;
25+
private $versionParser;
26+
private $symfonyRequire;
27+
private $symfonyConstraints;
28+
private $downloader;
29+
private $io;
30+
31+
public function setSymfonyRequire(string $symfonyRequire, Downloader $downloader, IOInterface $io = null)
32+
{
33+
$this->versionParser = new VersionParser();
34+
$this->symfonyRequire = $symfonyRequire;
35+
$this->symfonyConstraints = $this->versionParser->parseConstraints($symfonyRequire);
36+
$this->downloader = $downloader;
37+
$this->io = $io;
38+
}
39+
40+
public function read($file)
41+
{
42+
$content = parent::read($file);
43+
44+
if (0 === strpos($file, 'provider-symfony$') && \is_array($data = json_decode($content, true))) {
45+
$content = json_encode($this->removeLegacyTags($data));
46+
}
47+
48+
return $content;
49+
}
50+
51+
public function removeLegacyTags(array $data): array
52+
{
53+
if (!$this->symfonyConstraints || !isset($data['packages'])) {
54+
return $data;
55+
}
56+
57+
foreach ($data['packages'] as $name => $versions) {
58+
if (!isset($this->getVersions()['splits'][$name])) {
59+
continue;
60+
}
61+
62+
foreach ($versions as $version => $composerJson) {
63+
if ('dev-master' === $version) {
64+
if (null === $devMasterAlias = $versions['dev-master']['extra']['branch-alias']['dev-master'] ?? null) {
65+
continue;
66+
}
67+
68+
$normalizedVersion = $this->versionParser->normalize($devMasterAlias);
69+
} elseif (!isset($composerJson['version_normalized'])) {
70+
continue;
71+
} else {
72+
$normalizedVersion = $composerJson['version_normalized'];
73+
}
74+
75+
if (!$this->symfonyConstraints->matches(new Constraint('==', $normalizedVersion))) {
76+
if (null !== $this->io) {
77+
$this->io->writeError(sprintf('<info>Restricting packages listed in "symfony/symfony" to "%s"</>', $this->symfonyRequire));
78+
$this->io = null;
79+
}
80+
unset($versions[$version]);
81+
}
82+
}
83+
84+
$data['packages'][$name] = $versions;
85+
}
86+
87+
if (null === $symfonySymfony = $data['packages']['symfony/symfony'] ?? null) {
88+
return $data;
89+
}
90+
91+
foreach ($symfonySymfony as $version => $composerJson) {
92+
if ('dev-master' === $version) {
93+
$normalizedVersion = $this->versionParser->normalize($composerJson['extra']['branch-alias']['dev-master']);
94+
} elseif (!isset($composerJson['version_normalized'])) {
95+
continue;
96+
} else {
97+
$normalizedVersion = $composerJson['version_normalized'];
98+
}
99+
100+
if (!$this->symfonyConstraints->matches(new Constraint('==', $normalizedVersion))) {
101+
unset($symfonySymfony[$version]);
102+
}
103+
}
104+
105+
if ($symfonySymfony) {
106+
$data['packages']['symfony/symfony'] = $symfonySymfony;
107+
}
108+
109+
return $data;
110+
}
111+
112+
private function getVersions(): array
113+
{
114+
if (null !== $this->versions) {
115+
return $this->versions;
116+
}
117+
118+
$versions = $this->downloader->getVersions();
119+
$this->downloader = null;
120+
$okVersions = [];
121+
122+
foreach ($versions['splits'] as $name => $vers) {
123+
foreach ($vers as $i => $v) {
124+
if (!isset($okVersions[$v])) {
125+
$okVersions[$v] = false;
126+
127+
for ($j = 0; $j < 60; ++$j) {
128+
if ($this->symfonyConstraints->matches(new Constraint('==', $v.'.'.$j.'.0'))) {
129+
$okVersions[$v] = true;
130+
break;
131+
}
132+
}
133+
}
134+
135+
if (!$okVersions[$v]) {
136+
unset($vers[$i]);
137+
}
138+
}
139+
140+
if (!$vers || $vers === $versions['splits'][$name]) {
141+
unset($versions['splits'][$name]);
142+
}
143+
}
144+
145+
return $this->versions = $versions;
146+
}
147+
}

src/Command/RecipesCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class RecipesCommand extends BaseCommand
3232
private $symfonyLock;
3333
private $downloader;
3434

35-
public function __construct(/* cannot be type-hinted */ $flex, Lock $symfonyLock, HttpDownloader $downloader)
35+
public function __construct(/* cannot be type-hinted */ $flex, Lock $symfonyLock, $downloader)
3636
{
3737
$this->flex = $flex;
3838
$this->symfonyLock = $symfonyLock;
@@ -354,8 +354,12 @@ private function findRecipeCommitDataFromTreeRef(string $package, string $repo,
354354

355355
private function requestGitHubApi(string $path)
356356
{
357-
$response = $this->downloader->get($path);
357+
if ($this->downloader instanceof HttpDownloader) {
358+
$contents = $this->downloader->get($path)->getBody();
359+
} else {
360+
$contents = $this->downloader->getContents('api.github.com', $path, false);
361+
}
358362

359-
return json_decode($response->getBody(), true);
363+
return json_decode($contents, true);
360364
}
361365
}

src/Command/UnpackCommand.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
114114
$lockFile->write($lockData);
115115

116116
// force removal of files under vendor/
117-
$locker = new Locker($io, $lockFile, $composer->getInstallationManager(), file_get_contents($json->getPath()));
117+
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
118+
$locker = new Locker($io, $lockFile, $composer->getRepositoryManager(), $composer->getInstallationManager(), file_get_contents($json->getPath()));
119+
} else {
120+
$locker = new Locker($io, $lockFile, $composer->getInstallationManager(), file_get_contents($json->getPath()));
121+
}
118122
$composer->setLocker($locker);
119123
$install = Installer::create($io, $composer);
120124
$install
@@ -124,6 +128,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
124128
->setIgnorePlatformRequirements(true)
125129
;
126130

131+
if (method_exists($install, 'setSkipSuggest')) {
132+
$install->setSkipSuggest(true);
133+
}
134+
127135
return $install->run();
128136
}
129137
}

src/ComposerRepository.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Flex;
13+
14+
use Composer\Repository\ComposerRepository as BaseComposerRepository;
15+
16+
/**
17+
* @author Nicolas Grekas <[email protected]>
18+
*/
19+
class ComposerRepository extends BaseComposerRepository
20+
{
21+
private $providerFiles;
22+
23+
protected function loadProviderListings($data)
24+
{
25+
if (null !== $this->providerFiles) {
26+
parent::loadProviderListings($data);
27+
28+
return;
29+
}
30+
31+
$data = [$data];
32+
33+
while ($data) {
34+
$this->providerFiles = [];
35+
foreach ($data as $data) {
36+
$this->loadProviderListings($data);
37+
}
38+
39+
$loadingFiles = $this->providerFiles;
40+
$this->providerFiles = null;
41+
$data = [];
42+
$this->rfs->download($loadingFiles, function (...$args) use (&$data) {
43+
$data[] = $this->fetchFile(...$args);
44+
});
45+
}
46+
}
47+
48+
protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $storeLastModifiedTime = false)
49+
{
50+
if (null !== $this->providerFiles) {
51+
$this->providerFiles[] = [$filename, $cacheKey, $sha256, $storeLastModifiedTime];
52+
53+
return [];
54+
}
55+
56+
return parent::fetchFile($filename, $cacheKey, $sha256, $storeLastModifiedTime);
57+
}
58+
}

0 commit comments

Comments
 (0)