|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Phpcq\RepositoryBuilder\Api\GithubClient; |
| 6 | +use Phpcq\RepositoryBuilder\Command\RebuildCommand; |
| 7 | +use Phpcq\RepositoryBuilder\SourceProvider\Plugin\Github\RepositoryFactory as GithubRepositoryFactory; |
| 8 | +use Phpcq\RepositoryBuilder\SourceProvider\PluginProviderRepositoryFactory; |
| 9 | +use Phpcq\RepositoryBuilder\SourceProvider\Tool\Github\TagProviderRepositoryFactory; |
| 10 | +use Phpcq\RepositoryBuilder\SourceProvider\Tool\PharIo\RepositoryFactory as PharIoRepositoryFactory; |
| 11 | +use Symfony\Component\Cache\Adapter\PhpFilesAdapter; |
| 12 | +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; |
| 13 | +use Symfony\Component\HttpClient\CachingHttpClient; |
| 14 | +use Symfony\Component\HttpClient\HttpClient; |
| 15 | +use Symfony\Component\HttpKernel\HttpCache\Store; |
| 16 | +use Symfony\Contracts\HttpClient\HttpClientInterface; |
| 17 | + |
| 18 | +use function Symfony\Component\DependencyInjection\Loader\Configurator\param; |
| 19 | +use function Symfony\Component\DependencyInjection\Loader\Configurator\service; |
| 20 | +use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_locator; |
| 21 | + |
| 22 | +return function(ContainerConfigurator $container): void { |
| 23 | + $services = $container->services() |
| 24 | + ->defaults() |
| 25 | + ->autowire() |
| 26 | + ->autoconfigure(); |
| 27 | + |
| 28 | + $services->set('http.store') |
| 29 | + ->class(Store::class) |
| 30 | + ->args(['%kernel.project_dir%/var/http-cache']); |
| 31 | + |
| 32 | + $services->set('http.client.internal') |
| 33 | + ->class(HttpClientInterface::class) |
| 34 | + ->factory([HttpClient::class, 'create']); |
| 35 | + |
| 36 | + $services->set('http.client') |
| 37 | + ->class(CachingHttpClient::class) |
| 38 | + ->args([service('http.client.internal'), service('http.store')]); |
| 39 | + |
| 40 | + $services->set(GithubClient::class) |
| 41 | + ->args([service('http.client'), service('github.cache'), param('env(GITHUB_TOKEN)')]); |
| 42 | + |
| 43 | + $services->set('github.cache') |
| 44 | + ->class(PhpFilesAdapter::class) |
| 45 | + ->arg('$namespace', 'github-') |
| 46 | + ->arg('$directory', '%kernel.project_dir%/var/github-cache'); |
| 47 | + |
| 48 | + $services->set(PharIoRepositoryFactory::class) |
| 49 | + ->args([service('http.client'), '%kernel.project_dir%/var/repositories/phar.io']) |
| 50 | + ->tag('repository.factory', ['key' => 'tool-phar.io']); |
| 51 | + |
| 52 | + $services->set(TagProviderRepositoryFactory::class) |
| 53 | + ->args([service(GithubClient::class)]) |
| 54 | + ->tag('repository.factory', ['key' => 'tool-github']); |
| 55 | + |
| 56 | + /** @psalm-suppress DeprecatedClass */ |
| 57 | + $services->set(PluginProviderRepositoryFactory::class) |
| 58 | + ->tag('repository.factory', ['key' => 'plugin']); |
| 59 | + |
| 60 | + $services->set(GithubRepositoryFactory::class) |
| 61 | + ->tag('repository.factory', ['key' => 'plugin-github']); |
| 62 | + |
| 63 | + $services->load('Phpcq\\RepositoryBuilder\\Command\\', '../src/Command') |
| 64 | + ->tag('console.command'); |
| 65 | + |
| 66 | + $services->set(RebuildCommand::class) |
| 67 | + ->args([tagged_locator(tag: 'repository.factory', indexAttribute: 'key')]) |
| 68 | + ->tag('console.command'); |
| 69 | +}; |
0 commit comments