* * 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\Package\RootPackageInterface; use Composer\Semver\Constraint\Constraint; use Composer\Semver\VersionParser; /** * @author Nicolas Grekas
*/
class Cache extends BaseCache
{
private $versions;
private $versionParser;
private $symfonyRequire;
private $rootConstraints = [];
private $symfonyConstraints;
private $downloader;
private $io;
public function setSymfonyRequire(string $symfonyRequire, RootPackageInterface $rootPackage, Downloader $downloader, IOInterface $io = null)
{
$this->versionParser = new VersionParser();
$this->symfonyRequire = $symfonyRequire;
$this->symfonyConstraints = $this->versionParser->parseConstraints($symfonyRequire);
$this->downloader = $downloader;
$this->io = $io;
foreach ($rootPackage->getRequires() + $rootPackage->getDevRequires() as $name => $link) {
$this->rootConstraints[$name] = $link->getConstraint();
}
}
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->symfonyConstraints || !isset($data['packages'])) {
return $data;
}
foreach ($data['packages'] as $name => $versions) {
if (!isset($this->getVersions()['splits'][$name])) {
continue;
}
$rootConstraint = $this->rootConstraints[$name] ?? null;
$rootVersions = [];
foreach ($versions as $version => $composerJson) {
if (null !== $alias = $composerJson['extra']['branch-alias'][$version] ?? null) {
$normalizedVersion = $this->versionParser->normalize($alias);
} elseif (null === $normalizedVersion = $composerJson['version_normalized'] ?? null) {
continue;
}
$constraint = new Constraint('==', $normalizedVersion);
if ($rootConstraint && $rootConstraint->matches($constraint)) {
$rootVersions[$version] = $composerJson;
}
if (!$this->symfonyConstraints->matches($constraint)) {
if (null !== $this->io) {
$this->io->writeError(sprintf('