Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit e56698f

Browse files
authored
Removing legacy tags (#25)
| Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - #23 | License | MIT | Doc PR | -
1 parent ebbb58d commit e56698f

File tree

11 files changed

+313
-10
lines changed

11 files changed

+313
-10
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
<a href="https://github.com/narrowspark/discovery/releases"><img src="https://img.shields.io/packagist/v/narrowspark/discovery.svg?style=flat-square"></a>
44
<a href="https://php.net/"><img src="https://img.shields.io/badge/php-%5E7.2.0-8892BF.svg?style=flat-square"></a>
55
<a href="https://codecov.io/gh/narrowspark/discovery"><img src="https://img.shields.io/codecov/c/github/narrowspark/discovery/master.svg?style=flat-square"></a>
6+
<a href="#"><img src="https://img.shields.io/badge/style-level%207-brightgreen.svg?style=flat-square&label=phpstan"></a>
67
<a href="http://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
78
</p>
89

910
Branch Status
1011
------------
11-
[![Travis branch](https://img.shields.io/travis/narrowspark/discovery/master.svg?style=flat-square)](https://travis-ci.org/narrowspark/discovery)
12-
[![Codecov branch](https://img.shields.io/codecov/c/github/narrowspark/discovery/master.svg?style=flat-square)](https://codecov.io/gh/narrowspark/discovery/branch/master)
12+
[![Travis branch](https://img.shields.io/travis/narrowspark/discovery/master.svg?longCache=false&style=for-the-badge)](https://travis-ci.org/narrowspark/discovery)
13+
[![Appveyor branch](https://img.shields.io/appveyor/ci/narrowspark/discovery/master.svg?longCache=false&style=for-the-badge)](https://ci.appveyor.com/project/narrowspark/discovery/branch/master)
1314

1415
Installation
1516
-------------

appveyor.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
build: false
2+
platform:
3+
- x64
4+
- x86
5+
clone_depth: 1
6+
clone_folder: C:\projects\discovery
7+
8+
environment:
9+
matrix:
10+
- dependencies: basic
11+
PHP_VERSION: 7.2
12+
- dependencies: high
13+
PHP_VERSION: 7.2
14+
- dependencies: lowest
15+
PHP_VERSION: 7.2
16+
17+
matrix:
18+
fast_finish: true
19+
allow_failures:
20+
- dependencies: lowest
21+
PHP_VERSION: 7.2
22+
23+
services:
24+
- memcached
25+
26+
# cache is cleared when linked file is modified
27+
cache:
28+
# Cache chocolatey packages
29+
- C:\ProgramData\chocolatey\bin -> .appveyor.yml
30+
- C:\ProgramData\chocolatey\lib -> .appveyor.yml
31+
# Cache php install
32+
- C:\tools\php -> .appveyor.yml
33+
# Cache composer
34+
- C:\projects\discovery\vendor -> composer.json
35+
- '%LOCALAPPDATA%\Composer\files -> composer.json'
36+
37+
init:
38+
- SET PHP=1
39+
- SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH%
40+
- SET ANSICON=121x90 (121x90)
41+
- SET COMPOSER_NO_INTERACTION=1
42+
- SET COMPOSER_UP=php composer.phar update --no-interaction --prefer-dist --no-progress --profile --no-suggest --ansi
43+
- REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v DelayedExpansion /t REG_DWORD /d 1 /f
44+
45+
install:
46+
# If there is a newer build queued for the same PR, cancel this one.
47+
# The AppVeyor 'rollout builds' option is supposed to serve the same
48+
# purpose but it is problematic because it tends to cancel builds pushed
49+
# directly to master instead of just PR builds (or the converse).
50+
# credits: JuliaLang developers.
51+
- ps: if ($Env:APPVEYOR_PULL_REQUEST_NUMBER -and $Env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
52+
https://ci.appveyor.com/api/projects/$Env:APPVEYOR_ACCOUNT_NAME/$Env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
53+
Where-Object pullRequestId -eq $Env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
54+
throw "There are newer queued builds for this pull request, failing early." }
55+
# Install PHP
56+
- IF EXIST C:\tools\php (SET PHP=0)
57+
- IF %PHP%==1 appveyor DownloadFile "https://raw.githubusercontent.com/prisis/ps-install-php/master/Install-PHP.ps1"
58+
- ps: if (-not (Test-Path C:\tools\php)) {.\Install-PHP.ps1 -InstallPath C:\tools\php -Version $Env:PHP_VERSION -Highest -Arch $Env:PLATFORM -Extensions mbstring,intl,openssl,fileinfo,curl}
59+
# PHP settings and extensions
60+
- IF %PHP%==1 cd C:\tools\php
61+
- IF %PHP%==1 echo zend_extension=php_opcache.dll >> php.ini
62+
- IF %PHP%==1 echo max_execution_time=1200 >> php.ini
63+
- IF %PHP%==1 echo date.timezone="Europe/Berlin" >> php.ini
64+
- IF %PHP%==1 echo opcache.enable_cli=1 >> php.ini
65+
- IF %PHP%==1 echo apc.enable_cli=1 >> php.ini
66+
- IF %APPVEYOR_REPO_BRANCH%==master (SET COMPOSER_ROOT_VERSION=dev-master) ELSE (SET COMPOSER_ROOT_VERSION=%APPVEYOR_REPO_BRANCH%.x-dev)
67+
- cd C:\projects\discovery
68+
- php -r "readfile('https://getcomposer.org/installer');" | php
69+
# Matrix
70+
- php composer.phar global require hirak/prestissimo
71+
- IF %dependencies%==basic appveyor-retry %COMPOSER_UP%
72+
- IF %dependencies%==lowest appveyor-retry %COMPOSER_UP% --prefer-lowest --prefer-stable
73+
- IF %dependencies%==high appveyor-retry %COMPOSER_UP%
74+
- cd build/appveyor
75+
- appveyor DownloadFile https://cdn.rawgit.com/prisis/43a2a7b137998ac92e24ee4daaa8e296/raw/681b89b8e156750de46558ead661509c468fb9a2/try_catch.sh
76+
77+
test_script:
78+
- cd C:\projects\discovery
79+
- sh ./build/appveyor/script.sh

build/appveyor/script.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
source ./build/appveyor/try_catch.sh
4+
5+
for f in ./src/*; do
6+
if [[ -d "$f" && ! -L "$f" ]]; then
7+
TYPE="$(basename "$f")";
8+
9+
if [[ "$TYPE" = "Common" ]]; then
10+
TESTSUITE="Narrowspark Discovery Common Test Suite";
11+
elif [[ "$TYPE" = "Discovery" ]]; then
12+
TESTSUITE="Narrowspark Discovery Test Suite";
13+
fi
14+
15+
echo "";
16+
echo -e "$TESTSUITE";
17+
echo "";
18+
19+
try
20+
sh vendor/bin/phpunit --verbose -c ./phpunit.xml.dist --testsuite="$TESTSUITE";
21+
catch || {
22+
exit 1
23+
}
24+
fi
25+
done

src/Common/Configurator/AbstractConfigurator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function markData(string $packageName, string $data, int $spaceMultipl
110110
}
111111

112112
/**
113-
* Insert string at specified position.
113+
* Insert string before specified position.
114114
*
115115
* @param string $string
116116
* @param string $insertStr

src/Discovery/Discovery.php

+24-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
declare(strict_types=1);
33
namespace Narrowspark\Discovery;
44

5+
use Closure;
56
use Composer\Composer;
67
use Composer\DependencyResolver\Operation\InstallOperation;
78
use Composer\DependencyResolver\Operation\UninstallOperation;
@@ -22,7 +23,9 @@
2223
use Composer\Plugin\PluginInterface;
2324
use Composer\Plugin\PreFileDownloadEvent;
2425
use Composer\Repository\ComposerRepository as BaseComposerRepository;
26+
use Composer\Repository\RepositoryFactory;
2527
use Composer\Repository\RepositoryInterface;
28+
use Composer\Repository\RepositoryManager;
2629
use Composer\Script\Event;
2730
use Composer\Script\ScriptEvents;
2831
use Composer\Util\ProcessExecutor;
@@ -34,6 +37,7 @@
3437
use Narrowspark\Discovery\Installer\QuestionInstallationManager;
3538
use Narrowspark\Discovery\Prefetcher\ParallelDownloader;
3639
use Narrowspark\Discovery\Prefetcher\Prefetcher;
40+
use Narrowspark\Discovery\Prefetcher\TruncatedComposerRepository;
3741
use RecursiveDirectoryIterator;
3842
use RecursiveIteratorIterator;
3943
use ReflectionClass;
@@ -253,9 +257,26 @@ public function activate(Composer $composer, IOInterface $io): void
253257
$this->rfs = new ParallelDownloader($this->io, $composerConfig, $rfs->getOptions(), $rfs->isTlsDisabled());
254258

255259
$this->prefetcher = new Prefetcher($this->composer, $this->io, $this->input, $this->rfs);
256-
257260
$this->prefetcher->prefetchComposerRepositories($rfs);
258261

262+
$manager = RepositoryFactory::manager($this->io, $composerConfig, $composer->getEventDispatcher(), $this->rfs);
263+
$setRepositories = Closure::bind(function (RepositoryManager $manager) {
264+
$manager->repositoryClasses = $this->repositoryClasses;
265+
$manager->setRepositoryClass('composer', TruncatedComposerRepository::class);
266+
$manager->repositories = $this->repositories;
267+
268+
$i = 0;
269+
270+
foreach (RepositoryFactory::defaultRepos(null, $this->config, $manager) as $repo) {
271+
$manager->repositories[$i++] = $repo;
272+
}
273+
274+
$manager->setLocalRepository($this->getLocalRepository());
275+
}, $composer->getRepositoryManager(), RepositoryManager::class);
276+
277+
$setRepositories($manager);
278+
$composer->setRepositoryManager($manager);
279+
259280
$this->lock->add('@readme', [
260281
'This file locks the discovery information of your project to a known state',
261282
'This file is @generated automatically',
@@ -794,9 +815,9 @@ private function getErrorMessage(): ?string
794815
return 'You must enable the openssl extension in your "php.ini" file.';
795816
}
796817

797-
\preg_match_all('/\d+.\d+.\d+/m', Composer::VERSION, $matches, \PREG_SET_ORDER, 0);
818+
\preg_match('/\d+.\d+.\d+/m', Composer::VERSION, $matches);
798819

799-
if ($matches !== null && \version_compare('1.6.0', $matches[0], '<=')) {
820+
if ($matches !== null && \version_compare($matches[0], '1.6.0') === -1) {
800821
return \sprintf('Your version "%s" of Composer is too old; Please upgrade.', Composer::VERSION);
801822
}
802823

src/Discovery/Prefetcher/Cache.php

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace Narrowspark\Discovery\Prefetcher;
4+
5+
use Composer\Cache as BaseComposerCache;
6+
7+
/**
8+
* Ported from symfony flex, see original.
9+
*
10+
* @see https://github.com/symfony/flex/blob/master/src/Cache.php
11+
*
12+
* (c) Nicolas Grekas <[email protected]>
13+
*/
14+
class Cache extends BaseComposerCache
15+
{
16+
/**
17+
* @var array
18+
*/
19+
private static $lowestTags = [
20+
'symfony/symfony' => [
21+
'version' => 'v3.4.0',
22+
'replaces' => [
23+
'symfony/asset',
24+
'symfony/browser-kit',
25+
'symfony/cache',
26+
'symfony/config',
27+
'symfony/console',
28+
'symfony/css-selector',
29+
'symfony/dependency-injection',
30+
'symfony/debug',
31+
'symfony/debug-bundle',
32+
'symfony/doctrine-bridge',
33+
'symfony/dom-crawler',
34+
'symfony/dotenv',
35+
'symfony/event-dispatcher',
36+
'symfony/expression-language',
37+
'symfony/filesystem',
38+
'symfony/finder',
39+
'symfony/form',
40+
'symfony/framework-bundle',
41+
'symfony/http-foundation',
42+
'symfony/http-kernel',
43+
'symfony/inflector',
44+
'symfony/intl',
45+
'symfony/ldap',
46+
'symfony/lock',
47+
'symfony/messenger',
48+
'symfony/monolog-bridge',
49+
'symfony/options-resolver',
50+
'symfony/process',
51+
'symfony/property-access',
52+
'symfony/property-info',
53+
'symfony/proxy-manager-bridge',
54+
'symfony/routing',
55+
'symfony/security',
56+
'symfony/security-core',
57+
'symfony/security-csrf',
58+
'symfony/security-guard',
59+
'symfony/security-http',
60+
'symfony/security-bundle',
61+
'symfony/serializer',
62+
'symfony/stopwatch',
63+
'symfony/templating',
64+
'symfony/translation',
65+
'symfony/twig-bridge',
66+
'symfony/twig-bundle',
67+
'symfony/validator',
68+
'symfony/var-dumper',
69+
'symfony/web-link',
70+
'symfony/web-profiler-bundle',
71+
'symfony/web-server-bundle',
72+
'symfony/workflow',
73+
'symfony/yaml',
74+
],
75+
],
76+
];
77+
78+
/**
79+
* @param string $file
80+
*
81+
* @return bool|string
82+
*/
83+
public function read($file)
84+
{
85+
$content = parent::read($file);
86+
87+
if (0 === \mb_strpos($file, 'provider-symfony$')) {
88+
$content = \json_encode($this->removeLegacyTags(\json_decode($content, true)));
89+
}
90+
91+
return $content;
92+
}
93+
94+
/**
95+
* @param array $data
96+
*
97+
* @return array
98+
*/
99+
public function removeLegacyTags(array $data): array
100+
{
101+
foreach (self::$lowestTags as $lowestPackage => $settings) {
102+
$lowestVersion = $settings['version'];
103+
$replacedPackages = $settings['replaces'];
104+
105+
if (! isset($data['packages'][$lowestPackage][$lowestVersion])) {
106+
continue;
107+
}
108+
109+
foreach ($data['packages'] as $package => $versions) {
110+
if ($package !== $lowestPackage && ! \in_array($package, $replacedPackages, true)) {
111+
continue;
112+
}
113+
114+
foreach ($versions as $version => $composerJson) {
115+
if (\version_compare($version, $lowestVersion, '<')) {
116+
unset($data['packages'][$package][$version]);
117+
}
118+
}
119+
}
120+
121+
break;
122+
}
123+
124+
return $data;
125+
}
126+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace Narrowspark\Discovery\Prefetcher;
4+
5+
use Composer\Config;
6+
use Composer\EventDispatcher\EventDispatcher;
7+
use Composer\IO\IOInterface;
8+
use Composer\Repository\ComposerRepository as BaseComposerRepository;
9+
use Composer\Util\RemoteFilesystem;
10+
11+
/**
12+
* Ported from symfony flex, see original.
13+
*
14+
* @see https://github.com/symfony/flex/blob/master/src/Cache.php
15+
*
16+
* (c) Nicolas Grekas <[email protected]>
17+
*/
18+
class TruncatedComposerRepository extends BaseComposerRepository
19+
{
20+
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null)
21+
{
22+
parent::__construct($repoConfig, $io, $config, $eventDispatcher, $rfs);
23+
$this->cache = new Cache($io, $config->get('cache-repo-dir') . '/' . \preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
24+
}
25+
26+
protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $storeLastModifiedTime = false)
27+
{
28+
$data = parent::fetchFile($filename, $cacheKey, $sha256, $storeLastModifiedTime);
29+
30+
return $this->cache->removeLegacyTags($data);
31+
}
32+
}

tests/Common/Installer/InstallationManagerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
declare(strict_types=1);
3-
namespace Narrowspark\Discovery\Test\Installer;
3+
namespace Narrowspark\Discovery\Common\Test\Installer;
44

55
use Composer\DependencyResolver\Operation\InstallOperation;
66
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;

tests/Common/Installer/InstallerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
declare(strict_types=1);
3-
namespace Narrowspark\Discovery\Test\Installer;
3+
namespace Narrowspark\Discovery\Common\Test\Installer;
44

55
use Composer\Autoload\AutoloadGenerator;
66
use Composer\Downloader\DownloadManager;

0 commit comments

Comments
 (0)