Skip to content
Snippets Groups Projects
Commit 0e122007 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3293685 by phenaproxima: Remove need for close coupling of Composer...

Issue #3293685 by phenaproxima: Remove need for close coupling of Composer Stager API in our container services
parent 602bc418
No related branches found
No related tags found
No related merge requests found
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"drupal/core": "^9.3", "drupal/core": "^9.3",
"php-tuf/composer-stager": "1.0.0-beta2", "php-tuf/composer-stager": "^1.0.0-beta2",
"composer/composer": "^2.2.12 || ^2.3.5", "composer/composer": "^2.2.12 || ^2.3.5",
"composer-runtime-api": "^2.0.9" "composer-runtime-api": "^2.0.9",
"symfony/config": "^4.4 || ^6.1"
}, },
"config": { "config": {
"platform": { "platform": {
......
...@@ -5,129 +5,30 @@ services: ...@@ -5,129 +5,30 @@ services:
Symfony\Component\Process\ExecutableFinder: Symfony\Component\Process\ExecutableFinder:
public: false public: false
# Basic infrastructure services for Composer Stager. # Basic infrastructure services for Composer Stager, overridden by us to
# provide additional functionality.
Drupal\package_manager\ProcessFactory: Drupal\package_manager\ProcessFactory:
arguments: arguments:
- '@file_system' - '@file_system'
- '@config.factory' - '@config.factory'
public: false public: false
PhpTuf\ComposerStager\Infrastructure\Service\Filesystem\Filesystem:
autowire: true
public: false
Drupal\package_manager\ExecutableFinder: Drupal\package_manager\ExecutableFinder:
arguments: arguments:
$config_factory: '@config.factory' $config_factory: '@config.factory'
autowire: true autowire: true
public: false public: false
PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactory:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinder:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Factory\Process\ProcessFactoryInterface:
alias: 'Drupal\package_manager\ProcessFactory'
PhpTuf\ComposerStager\Domain\Service\Filesystem\FilesystemInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Filesystem\Filesystem'
PhpTuf\ComposerStager\Infrastructure\Service\Finder\ExecutableFinderInterface:
alias: 'Drupal\package_manager\ExecutableFinder'
PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactory'
PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinder'
# Executable runners for Composer Stager.
PhpTuf\ComposerStager\Infrastructure\Service\ProcessRunner\RsyncRunner:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\ProcessRunner\ComposerRunner:
autowire: true
public: false
PhpTuf\ComposerStager\Domain\Service\ProcessRunner\RsyncRunnerInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\ProcessRunner\RsyncRunner'
PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\ProcessRunner\ComposerRunner'
# File syncers for Composer Stager.
PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\RsyncFileSyncer:
autowire: true
PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\PhpFileSyncer:
autowire: true
Drupal\package_manager\FileSyncerFactory: Drupal\package_manager\FileSyncerFactory:
arguments: arguments:
$config_factory: '@config.factory' $config_factory: '@config.factory'
autowire: true autowire: true
public: false public: false
PhpTuf\ComposerStager\Infrastructure\Service\Finder\ExecutableFinderInterface:
alias: 'Drupal\package_manager\ExecutableFinder'
PhpTuf\ComposerStager\Infrastructure\Factory\Process\ProcessFactoryInterface:
alias: 'Drupal\package_manager\ProcessFactory'
PhpTuf\ComposerStager\Domain\Service\FileSyncer\FileSyncerInterface: PhpTuf\ComposerStager\Domain\Service\FileSyncer\FileSyncerInterface:
factory: ['@Drupal\package_manager\FileSyncerFactory', 'create'] factory: ['@Drupal\package_manager\FileSyncerFactory', 'create']
# Composer Stager preconditions.
PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\CommonPreconditions:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\BeginnerPreconditions:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\StagerPreconditions:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\CommitterPreconditions:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\StagingDirIsReady:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ComposerIsAvailable:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveDirExists:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveDirIsWritable:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveAndStagingDirsAreDifferent:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\StagingDirExists:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\StagingDirIsWritable:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\StagingDirDoesNotExist:
autowire: true
public: false
PhpTuf\ComposerStager\Infrastructure\Service\Precondition\CodeBaseContainsNoSymlinks:
autowire: true
public: false
PhpTuf\ComposerStager\Domain\Aggregate\PreconditionsTree\CommitterPreconditionsInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\CommitterPreconditions'
PhpTuf\ComposerStager\Domain\Aggregate\PreconditionsTree\BeginnerPreconditionsInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\BeginnerPreconditions'
PhpTuf\ComposerStager\Domain\Aggregate\PreconditionsTree\StagerPreconditionsInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\StagerPreconditions'
PhpTuf\ComposerStager\Domain\Aggregate\PreconditionsTree\CommonPreconditionsInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\CommonPreconditions'
PhpTuf\ComposerStager\Domain\Aggregate\PreconditionsTree\StagingDirIsReadyInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Aggregate\PreconditionsTree\StagingDirIsReady'
PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ComposerIsAvailable'
PhpTuf\ComposerStager\Domain\Service\Precondition\ActiveDirExistsInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveDirExists'
PhpTuf\ComposerStager\Domain\Service\Precondition\ActiveDirIsWritableInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveDirIsWritable'
PhpTuf\ComposerStager\Domain\Service\Precondition\ActiveAndStagingDirsAreDifferentInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveAndStagingDirsAreDifferent'
PhpTuf\ComposerStager\Domain\Service\Precondition\StagingDirExistsInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\StagingDirExists'
PhpTuf\ComposerStager\Domain\Service\Precondition\StagingDirIsWritableInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\StagingDirIsWritable'
PhpTuf\ComposerStager\Domain\Service\Precondition\StagingDirDoesNotExistInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\StagingDirDoesNotExist'
PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface:
alias: 'PhpTuf\ComposerStager\Infrastructure\Service\Precondition\CodeBaseContainsNoSymlinks'
# Services provided to Drupal by Package Manager. # Services provided to Drupal by Package Manager.
package_manager.beginner: package_manager.beginner:
class: PhpTuf\ComposerStager\Domain\Core\Beginner\Beginner class: PhpTuf\ComposerStager\Domain\Core\Beginner\Beginner
......
...@@ -5,6 +5,10 @@ namespace Drupal\package_manager; ...@@ -5,6 +5,10 @@ namespace Drupal\package_manager;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase; use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\package_manager\EventSubscriber\UpdateDataSubscriber; use Drupal\package_manager\EventSubscriber\UpdateDataSubscriber;
use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
/** /**
...@@ -23,6 +27,24 @@ final class PackageManagerServiceProvider extends ServiceProviderBase { ...@@ -23,6 +27,24 @@ final class PackageManagerServiceProvider extends ServiceProviderBase {
public function register(ContainerBuilder $container) { public function register(ContainerBuilder $container) {
parent::register($container); parent::register($container);
// Use an interface that we know exists to determine the absolute path where
// Composer Stager is installed.
$mirror = new \ReflectionClass(BeginnerInterface::class);
$path = dirname($mirror->getFileName(), 4);
// Recursively register all classes and interfaces under that directory,
// relative to the \PhpTuf\ComposerStager namespace.
$loader = new DirectoryLoader($container, new FileLocator());
// All the registered services should be auto-wired and private by default.
$default_definition = new Definition();
$default_definition->setAutowired(TRUE);
$default_definition->setPublic(FALSE);
$loader->registerClasses($default_definition, 'PhpTuf\ComposerStager\\', $path, [
// Ignore classes which we don't want to register as services.
$path . '/Domain/Exception',
$path . '/Infrastructure/Value',
]);
if (array_key_exists('update', $container->getParameter('container.modules'))) { if (array_key_exists('update', $container->getParameter('container.modules'))) {
$container->register('package_manager.update_data_subscriber') $container->register('package_manager.update_data_subscriber')
->setClass(UpdateDataSubscriber::class) ->setClass(UpdateDataSubscriber::class)
......
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
namespace Drupal\Tests\package_manager\Kernel; namespace Drupal\Tests\package_manager\Kernel;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\package_manager\ExecutableFinder;
use Drupal\package_manager\ProcessFactory;
use PhpTuf\ComposerStager\Infrastructure\Factory\Process\ProcessFactoryInterface;
use PhpTuf\ComposerStager\Infrastructure\Service\Finder\ExecutableFinderInterface;
/** /**
* Tests that Package Manager services are wired correctly. * Tests that Package Manager services are wired correctly.
...@@ -28,6 +32,16 @@ class ServicesTest extends KernelTestBase { ...@@ -28,6 +32,16 @@ class ServicesTest extends KernelTestBase {
foreach ($services as $service) { foreach ($services as $service) {
$this->assertIsObject($this->container->get($service)); $this->assertIsObject($this->container->get($service));
} }
// Ensure that any overridden Composer Stager services were overridden
// correctly.
$overrides = [
ExecutableFinderInterface::class => ExecutableFinder::class,
ProcessFactoryInterface::class => ProcessFactory::class,
];
foreach ($overrides as $interface => $expected_class) {
$this->assertInstanceOf($expected_class, $this->container->get($interface));
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment