forked from symfony/flex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCache.php
76 lines (64 loc) · 2.5 KB
/
Cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Flex;
use Composer\Cache as BaseCache;
use Composer\IO\IOInterface;
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\VersionParser;
/**
* @author Nicolas Grekas <[email protected]>
*/
class Cache extends BaseCache
{
private $versionParser;
private $symfonyRequire;
private $symfonyContraints;
private $io;
public function setSymfonyRequire(string $symfonyRequire, IOInterface $io)
{
$this->versionParser = new VersionParser();
$this->symfonyRequire = $symfonyRequire;
$this->symfonyContraints = $this->versionParser->parseConstraints($symfonyRequire);
$this->io = $io;
}
public function read($file)
{
$content = parent::read($file);
if (0 === strpos($file, 'provider-symfony$') && \is_array($data = json_decode($content, true))) {
$content = json_encode($this->removeLegacyTags($data));
}
return $content;
}
public function removeLegacyTags(array $data): array
{
if (!$this->symfonyContraints || !isset($data['packages']['symfony/symfony'])) {
return $data;
}
$symfonyVersions = $data['packages']['symfony/symfony'];
foreach ($data['packages'] as $name => $versions) {
foreach ($versions as $version => $package) {
if ('symfony/symfony' !== $name && 'self.version' !== ($symfonyVersions[preg_replace('/^(\d++\.\d++)\..*/', '$1.x-dev', $version)]['replace'][$name] ?? null)) {
continue;
}
$normalizedVersion = $package['extra']['branch-alias'][$version] ?? null;
$normalizedVersion = $normalizedVersion ? $this->versionParser->normalize($normalizedVersion) : $package['version_normalized'];
$provider = new Constraint('==', $normalizedVersion);
if (!$this->symfonyContraints->matches($provider)) {
if ($this->io) {
$this->io->writeError(sprintf('<info>Restricting packages listed in "symfony/symfony" to "%s"</info>', $this->symfonyRequire));
$this->io = null;
}
unset($data['packages'][$name][$version]);
}
}
}
return $data;
}
}