forked from symfony/flex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
186f05e
commit d790a5c
Showing
14 changed files
with
1,240 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?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 $versions; | ||
private $versionParser; | ||
private $symfonyRequire; | ||
private $symfonyConstraints; | ||
private $downloader; | ||
private $io; | ||
|
||
public function setSymfonyRequire(string $symfonyRequire, Downloader $downloader, IOInterface $io = null) | ||
{ | ||
$this->versionParser = new VersionParser(); | ||
$this->symfonyRequire = $symfonyRequire; | ||
$this->symfonyConstraints = $this->versionParser->parseConstraints($symfonyRequire); | ||
$this->downloader = $downloader; | ||
$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->symfonyConstraints || !isset($data['packages'])) { | ||
return $data; | ||
} | ||
|
||
foreach ($data['packages'] as $name => $versions) { | ||
if (!isset($this->getVersions()['splits'][$name])) { | ||
continue; | ||
} | ||
|
||
foreach ($versions as $version => $composerJson) { | ||
if ('dev-master' === $version) { | ||
if (null === $devMasterAlias = $versions['dev-master']['extra']['branch-alias']['dev-master'] ?? null) { | ||
continue; | ||
} | ||
|
||
$normalizedVersion = $this->versionParser->normalize($devMasterAlias); | ||
} elseif (!isset($composerJson['version_normalized'])) { | ||
continue; | ||
} else { | ||
$normalizedVersion = $composerJson['version_normalized']; | ||
} | ||
|
||
if (!$this->symfonyConstraints->matches(new Constraint('==', $normalizedVersion))) { | ||
if (null !== $this->io) { | ||
$this->io->writeError(sprintf('<info>Restricting packages listed in "symfony/symfony" to "%s"</>', $this->symfonyRequire)); | ||
$this->io = null; | ||
} | ||
unset($versions[$version]); | ||
} | ||
} | ||
|
||
$data['packages'][$name] = $versions; | ||
} | ||
|
||
if (null === $symfonySymfony = $data['packages']['symfony/symfony'] ?? null) { | ||
return $data; | ||
} | ||
|
||
foreach ($symfonySymfony as $version => $composerJson) { | ||
if ('dev-master' === $version) { | ||
$normalizedVersion = $this->versionParser->normalize($composerJson['extra']['branch-alias']['dev-master']); | ||
} elseif (!isset($composerJson['version_normalized'])) { | ||
continue; | ||
} else { | ||
$normalizedVersion = $composerJson['version_normalized']; | ||
} | ||
|
||
if (!$this->symfonyConstraints->matches(new Constraint('==', $normalizedVersion))) { | ||
unset($symfonySymfony[$version]); | ||
} | ||
} | ||
|
||
if ($symfonySymfony) { | ||
$data['packages']['symfony/symfony'] = $symfonySymfony; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
private function getVersions(): array | ||
{ | ||
if (null !== $this->versions) { | ||
return $this->versions; | ||
} | ||
|
||
$versions = $this->downloader->getVersions(); | ||
$this->downloader = null; | ||
$okVersions = []; | ||
|
||
foreach ($versions['splits'] as $name => $vers) { | ||
foreach ($vers as $i => $v) { | ||
if (!isset($okVersions[$v])) { | ||
$okVersions[$v] = false; | ||
|
||
for ($j = 0; $j < 60; ++$j) { | ||
if ($this->symfonyConstraints->matches(new Constraint('==', $v.'.'.$j.'.0'))) { | ||
$okVersions[$v] = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!$okVersions[$v]) { | ||
unset($vers[$i]); | ||
} | ||
} | ||
|
||
if (!$vers || $vers === $versions['splits'][$name]) { | ||
unset($versions['splits'][$name]); | ||
} | ||
} | ||
|
||
return $this->versions = $versions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?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\Repository\ComposerRepository as BaseComposerRepository; | ||
|
||
/** | ||
* @author Nicolas Grekas <[email protected]> | ||
*/ | ||
class ComposerRepository extends BaseComposerRepository | ||
{ | ||
private $providerFiles; | ||
|
||
protected function loadProviderListings($data) | ||
{ | ||
if (null !== $this->providerFiles) { | ||
parent::loadProviderListings($data); | ||
|
||
return; | ||
} | ||
|
||
$data = [$data]; | ||
|
||
while ($data) { | ||
$this->providerFiles = []; | ||
foreach ($data as $data) { | ||
$this->loadProviderListings($data); | ||
} | ||
|
||
$loadingFiles = $this->providerFiles; | ||
$this->providerFiles = null; | ||
$data = []; | ||
$this->rfs->download($loadingFiles, function (...$args) use (&$data) { | ||
$data[] = $this->fetchFile(...$args); | ||
}); | ||
} | ||
} | ||
|
||
protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $storeLastModifiedTime = false) | ||
{ | ||
if (null !== $this->providerFiles) { | ||
$this->providerFiles[] = [$filename, $cacheKey, $sha256, $storeLastModifiedTime]; | ||
|
||
return []; | ||
} | ||
|
||
return parent::fetchFile($filename, $cacheKey, $sha256, $storeLastModifiedTime); | ||
} | ||
} |
Oops, something went wrong.