Commit 12a31cc0 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Tentative d'ajout d'une couche d'abstraction pour gérer plusieurs sources.

No related merge requests found
Pipeline #6583 failed with stages
in 46 seconds
Showing with 519 additions and 56 deletions
+519 -56
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Configuration;
/**
* Class GithubRelease.
*/
class GithubRelease
{
}
......@@ -16,7 +16,7 @@ use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Yaml\Yaml;
/**
* Class MakeShim.
* Configuration file of the build command.
*/
class MakeShim implements ConfigurationInterface
{
......
File moved
File moved
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Package;
/**
* Interface PackageInterface.
*/
interface PackageInterface
{
/**
* @return string
*/
public function getName(): string;
/**
* @return string
*/
public function getVersion(): string;
/**
* @return array
*/
public function getComposerConfig(): array;
/**
* @return string
*/
public function getBinaryPath(): string;
/**
* @return string
*/
public function getArchiveURL(): string;
/**
* @return string|null
*/
public function getSignatureURL(): ?string;
}
......@@ -7,18 +7,18 @@
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Configuration;
namespace Irstea\MakeShim\Configuration\Packagist;
use Irstea\MakeShim\Packagist\Package;
use Irstea\MakeShim\Packagist\Package as PackageObject;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\NodeInterface;
use Symfony\Component\Config\Definition\Processor;
/**
* Class Composer.
* Allow to parse the parts of composer.json in whom we have some interest.
*/
class Composer
class Package
{
/** @var NodeInterface|null */
private $configTree;
......@@ -29,11 +29,11 @@ class Composer
/**
* @param array $config
*
* @return Package
* @return PackageObject
*/
public function process(array $config): Package
public function process(array $config): PackageObject
{
return Package::fromConfiguration(
return PackageObject::fromConfiguration(
$this->getProcessor()->process(
$this->getConfigTree(),
[$config],
......@@ -79,42 +79,42 @@ class Composer
$rootNode
->ignoreExtraKeys()
->children()
->scalarNode('name')->isRequired()->end()
->scalarNode('version')->isRequired()->end()
->scalarNode('type')->isRequired()->end()
->scalarNode('homepage')->end()
->arrayNode('keywords')->scalarPrototype()->end()->end()
->arrayNode('authors')->variablePrototype()->end()->end()
->arrayNode('license')
->beforeNormalization()->castToArray()->end()
->scalarPrototype()->end()
->end()
->arrayNode('bin')
->isRequired()
->requiresAtLeastOneElement()
->scalarPrototype()->end()
->end()
->arrayNode('require')
->beforeNormalization()
->always(\Closure::fromCallable([$this, 'keepPlatformRequirements']))
->end()
->scalarPrototype()->end()
->end()
->arrayNode('suggest')
->beforeNormalization()
->always(\Closure::fromCallable([$this, 'keepPlatformRequirements']))
->end()
->scalarPrototype()->end()
->end()
->arrayNode('replace')
->scalarPrototype()->end()
->end()
->arrayNode('conflicts')
->beforeNormalization()
->always(\Closure::fromCallable([$this, 'keepPlatformRequirements']))
->end()
->scalarPrototype()->end()
->end()
->scalarNode('name')->isRequired()->end()
->scalarNode('version')->isRequired()->end()
->scalarNode('type')->isRequired()->end()
->scalarNode('homepage')->end()
->arrayNode('keywords')->scalarPrototype()->end()->end()
->arrayNode('authors')->variablePrototype()->end()->end()
->arrayNode('license')
->beforeNormalization()->castToArray()->end()
->scalarPrototype()->end()
->end()
->arrayNode('bin')
->isRequired()
->requiresAtLeastOneElement()
->scalarPrototype()->end()
->end()
->arrayNode('require')
->beforeNormalization()
->always(\Closure::fromCallable([$this, 'keepPlatformRequirements']))
->end()
->scalarPrototype()->end()
->end()
->arrayNode('suggest')
->beforeNormalization()
->always(\Closure::fromCallable([$this, 'keepPlatformRequirements']))
->end()
->scalarPrototype()->end()
->end()
->arrayNode('replace')
->scalarPrototype()->end()
->end()
->arrayNode('conflicts')
->beforeNormalization()
->always(\Closure::fromCallable([$this, 'keepPlatformRequirements']))
->end()
->scalarPrototype()->end()
->end()
->end();
return $treeBuilder;
......
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Configuration\Packagist;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* Class PackageList.
*/
class PackageList implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
// TODO: Implement getConfigTreeBuilder() method.
}
}
......@@ -13,6 +13,7 @@ use Assert\Assert;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use Irstea\MakeShim\Configuration;
use Irstea\MakeShim\Package\ProviderInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
......@@ -24,7 +25,7 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
/**
* Class Packagist.
*/
final class Packagist implements PackagistInterface, LoggerAwareInterface
final class Packagist implements ProviderInterface, LoggerAwareInterface
{
use LoggerAwareTrait;
......@@ -34,7 +35,7 @@ final class Packagist implements PackagistInterface, LoggerAwareInterface
private const PACKAGIST_BASE_URL = 'https://repo.packagist.org/p';
/**
* @var Configuration\Composer
* @var Configuration\Package
*/
private $configuration;
......@@ -46,11 +47,11 @@ final class Packagist implements PackagistInterface, LoggerAwareInterface
/**
* Packagist constructor.
*
* @param ClientInterface $client
* @param Configuration\Composer $configuration
* @param LoggerInterface|null $logger
* @param ClientInterface $client
* @param Configuration\Package $configuration
* @param LoggerInterface|null $logger
*/
public function __construct(ClientInterface $client, Configuration\Composer $configuration, LoggerInterface $logger = null)
public function __construct(ClientInterface $client, Configuration\Package $configuration, LoggerInterface $logger = null)
{
$this->client = $client;
$this->configuration = $configuration;
......
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Package\Phive;
use Irstea\MakeShim\Package\ProviderInterface;
/**
* Class Phive.
*/
class Phive implements ProviderInterface
{
/**
* {@inheritdoc}
*/
public function enumerateVersions(string $packageName): array
{
// TODO: Implement enumerateVersions() method.
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Configuration\Phive;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* Class Repository.
*/
class Repository implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('repository');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
$rootNode
->fixXmlConfig('phar')
->children()
->arrayNode('phars')
->useAttributeAsKey('name', false)
->arrayPrototype()
->fixXmlConfig('release')
->children()
->scalarNode('name')->isRequired()->end()
->arrayNode('releases')
->useAttributeAsKey('version', false)
->arrayPrototype()
->children()
->scalarNode('version')->isRequired()->end()
->scalarNode('url')->isRequired()->end()
->arrayNode('signature')
->children()
->scalarNode('type')->end()
->end()
->end()
->arrayNode('hash')
->children()
->scalarNode('type')->end()
->scalarNode('value')->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Configuration\Phive;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* Class RepositoryList.
*/
class RepositoryList implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('repositories');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
$rootNode
->fixXmlConfig('phar')
->children()
->arrayNode('phars')
->useAttributeAsKey('alias', false)
->arrayPrototype()
->children()
->scalarNode('alias')->isRequired()->end()
->scalarNode('composer')->end()
->arrayNode('repository')
->children()
->scalarNode('type')->defaultValue('phive')->end()
->scalarNode('url')->isRequired()->end()
->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
......@@ -7,17 +7,17 @@
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Packagist;
namespace Irstea\MakeShim\Package;
/**
* Interface PackagistInterface.
* Interface ProviderInterface.
*/
interface PackagistInterface
interface ProviderInterface
{
/**
* @param string $packageName
*
* @return Package[]
* @return PackageInterface[]
*/
public function enumerateVersions(string $packageName): array;
}
......@@ -23,8 +23,8 @@ use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Irstea\MakeShim\Builder\Builder;
use Irstea\MakeShim\Command\BuildCommand;
use Irstea\MakeShim\Configuration\Composer;
use Irstea\MakeShim\Configuration\MakeShim;
use Irstea\MakeShim\Configuration\Package;
use Irstea\MakeShim\Packagist\Packagist;
use Irstea\MakeShim\Packagist\VersionFilter;
use Irstea\MakeShim\Repository\Factory;
......@@ -58,7 +58,7 @@ $container['build-command'] = static function (Container $c) {
$container['packagist'] = static function (Container $c) {
return new Packagist(
$c['http-client'],
new Composer(),
new Package(),
$c['logger']
);
};
......
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Tests\Configuration\Composer;
use Irstea\MakeShim\Configuration\Packagist\Package;
use PHPUnit\Framework\TestCase;
/**
* Class PackageListTest.
*/
final class PackageListTest extends TestCase
{
public function testPackage(): void
{
$package = new Package();
$data = \Safe\json_decode(\Safe\file_get_contents(__DIR__ . '/../../../composer.json'), true);
$result = $package->process($data);
dump($result);
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Tests\Configuration\Phive;
use Irstea\MakeShim\Configuration\Phive\RepositoryList;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Util\XmlUtils;
/**
* Class RepositoryListTest.
*/
final class RepositoryListTest extends TestCase
{
public function testRepositoryList(): void
{
$domDocument = XmlUtils::loadFile(__DIR__ . '/fixtures/list.xml');
$input = XmlUtils::convertDomElementToArray($domDocument->documentElement);
$proc = new Processor();
$config = new RepositoryList();
$result = $proc->processConfiguration($config, [$input]);
self::assertIsArray($result);
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/make-shim".
* (c) 2019 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Irstea\MakeShim\Tests\Configuration\Phive;
use Irstea\MakeShim\Configuration\Phive\Repository;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Util\XmlUtils;
/**
* Class PhiveRepositoriesTest.
*/
final class RepositoryTest extends TestCase
{
public function testRepository(): void
{
$domDocument = XmlUtils::loadFile(__DIR__ . '/fixtures/repository.xml');
$input = XmlUtils::convertDomElementToArray($domDocument->documentElement);
$proc = new Processor();
$config = new Repository();
$result = $proc->processConfiguration($config, [$input]);
dump($result);
self::assertIsArray($result);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<repositories xmlns="https://phar.io/repository-list">
<phar alias="phpbench" composer="phpbench/phpbench">
<repository type="github" url="https://api.github.com/repos/phpbench/phpbench/releases" />
</phar>
<phar alias="infection" composer="infection/infection">
<repository type="github" url="https://api.github.com/repos/infection/infection/releases" />
</phar>
<phar alias="phpab" composer="theseer/autoload">
<repository type="github" url="https://api.github.com/repos/theseer/autoload/releases" />
</phar>
<phar alias="phpcpd" composer="sebastian/phpcpd">
<repository url="https://phar.phpunit.de/phive.xml"/>
</phar>
<phar alias="phpdox" composer="theseer/phpdox">
<repository type="github" url="https://api.github.com/repos/theseer/phpdox/releases" />
</phar>
<phar alias="phploc" composer="phploc/phploc">
<repository url="https://phar.phpunit.de/phive.xml"/>
</phar>
<phar alias="phpunit" composer="phpunit/phpunit">
<repository url="https://phar.phpunit.de/phive.xml"/>
</phar>
<phar alias="phpbu" composer="phpbu/phpbu">
<repository url="https://phar.phpbu.de/phive.xml"/>
</phar>
<phar alias="php-doc-check" composer="nielsdeblaauw/php-doc-check">
<repository type="github" url="https://api.github.com/repos/nielsdeblaauw/php-doc-check/releases"/>
</phar>
<phar alias="dephpend" composer="dephpend/dephpend">
<repository url="https://phar.dephpend.com/phive.xml"/>
</phar>
<phar alias="phpdocumentor" composer="phpdocumentor/phpdocumentor">
<repository type="github" url="https://api.github.com/repos/phpdocumentor/phpdocumentor2/releases" />
</phar>
<phar alias="carbon" composer="jpuck/carbon-console">
<repository type="github" url="https://api.github.com/repos/jpuck/carbon-console/releases" />
</phar>
<phar alias="composer-require-checker" composer="maglnet/composer-require-checker">
<repository type="github" url="https://api.github.com/repos/maglnet/ComposerRequireChecker/releases" />
</phar>
<phar alias="phpstan" composer="phpstan/phpstan">
<repository type="github" url="https://api.github.com/repos/phpstan/phpstan/releases" />
</phar>
<phar alias="phpcs" composer="squizlabs/php_codesniffer">
<repository url="https://squizlabs.github.io/PHP_CodeSniffer/phars/phive.xml" />
</phar>
<phar alias="phpcbf" composer="squizlabs/php_codesniffer">
<repository url="https://squizlabs.github.io/PHP_CodeSniffer/phars/phive.xml" />
</phar>
<phar alias="n98-magerun" composer="n98/magerun">
<repository url="https://files.magerun.net/phive.xml" />
</phar>
<phar alias="n98-magerun2" composer="n98/magerun2">
<repository url="https://files.magerun.net/phive.xml" />
</phar>
<phar alias="pipelines" composer="ktomk/pipelines">
<repository type="github" url="https://api.github.com/repos/ktomk/pipelines/releases" />
</phar>
<phar alias="phing" composer="phing/phing">
<repository type="github" url="https://api.github.com/repos/phingofficial/phing/releases" />
</phar>
<phar alias="psalm" composer="vimeo/psalm">
<repository type="github" url="https://api.github.com/repos/vimeo/psalm/releases" />
</phar>
<phar alias="clapi" composer="ngabor84/clapi">
<repository type="github" url="https://api.github.com/repos/ngabor84/clapi/releases" />
</phar>
<phar alias="sshman" composer="mwender/sshman">
<repository type="github" url="https://api.github.com/repos/mwender/sshman/releases" />
</phar>
<phar alias="php-coveralls" composer="php-coveralls/php-coveralls">
<repository type="github" url="https://api.github.com/repos/php-coveralls/php-coveralls/releases" />
</phar>
<phar alias="php-cs-fixer" composer="friendsofphp/php-cs-fixer">
<repository type="github" url="https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/releases" />
</phar>
<phar alias="phan" composer="phan/phan">
<repository type="github" url="https://api.github.com/repos/phan/phan/releases" />
</phar>
<phar alias="ecc" composer="ngabor84/ecc">
<repository type="github" url="https://api.github.com/repos/ngabor84/ecc/releases" />
</phar>
<phar alias="wp" composer="wp-cli/wp-cli">
<repository type="github" url="https://api.github.com/repos/wp-cli/wp-cli/releases" />
</phar>
<phar alias="psh" composer="shopware/psh">
<repository type="github" url="https://api.github.com/repos/shopwareLabs/psh/releases" />
</phar>
<phar alias="sw-cli-tools" composer="shopwarelabs/sw-cli-tools">
<repository type="github" url="https://api.github.com/repos/shopwareLabs/sw-cli-tools/releases" />
</phar>
<phar alias="paratest" composer="brianium/paratest">
<repository type="github" url="https://api.github.com/repos/paratestphp/paratest/releases" />
</phar>
<phar alias="deptrac" composer="sensiolabs-de/deptrac">
<repository type="github" url="https://api.github.com/repos/sensiolabs-de/deptrac/releases" />
</phar>
</repositories>
<?xml version="1.0"?>
<repository xmlns="https://phar.io/repository" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://phar.io/repository https://phar.io/data/repository.xsd">
<phar name="dephpend">
<release version="0.4.0" url="https://phar.dephpend.com/dephpend-0.4.0.phar">
<signature type="gpg"/>
<hash type="sha-256" value="72240f80b5ff05cc88d8eb23d989f633a456a3c96ed39a08b0fdbbf4d5c88b84"/>
</release>
<release version="0.3.2" url="https://phar.dephpend.com/dephpend-0.3.2.phar">
<signature type="gpg"/>
<hash type="sha-256" value="9e246643638a76d7a96259159d51dd8a6cdef5886fb2ef15ea1df8e84e3a2c34"/>
</release>
<release version="0.3.1" url="https://phar.dephpend.com/dephpend-0.3.1.phar">
<signature type="gpg"/>
<hash type="sha-256" value="08be1f0fe7c6de19c3df89b2203d1e5c83c520302002d95fd2013d76e6d2f683"/>
</release>
<release version="0.3.0" url="https://phar.dephpend.com/dephpend-0.3.0.phar">
<signature type="gpg"/>
<hash type="sha-256" value="e59d6816136c1ebe6aab3d07ffaeb8b136e844e5b922dac685fbba5faa2e52f8"/>
</release>
<release version="0.2.0" url="https://phar.dephpend.com/dephpend-0.2.0.phar">
<signature type="gpg"/>
<hash type="sha-256" value="74fbf5178d4b72f66428bcfb79448bc06e44bae75f4ca9a1ee4682c222e06448"/>
</release>
<release version="0.1.0" url="https://phar.dephpend.com/dephpend-0.1.0.phar">
<signature type="gpg"/>
<hash type="sha-256" value="7849206947e12cc45ee449be7b881df3236010d0e66b1ab2acf4044d5afe13b7"/>
</release>
</phar>
</repository>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment