diff --git a/core/modules/package_manager/package_manager.services.yml b/core/modules/package_manager/package_manager.services.yml index e2ce375cb547f53eb9d096e9f3b9554b28a559cf..88a837631012faf1c718d76ca80a1a5a555204c4 100644 --- a/core/modules/package_manager/package_manager.services.yml +++ b/core/modules/package_manager/package_manager.services.yml @@ -20,8 +20,6 @@ services: Drupal\package_manager\TranslatableStringFactory: public: false decorates: 'PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface' - PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface: - factory: ['@PhpTuf\ComposerStager\API\FileSyncer\Factory\FileSyncerFactoryInterface', 'create'] Drupal\package_manager\LoggingBeginner: public: false decorates: 'PhpTuf\ComposerStager\API\Core\BeginnerInterface' @@ -105,3 +103,101 @@ services: $update_fetcher: '@update.fetcher' $key_value_factory: '@keyvalue' $key_value_expirable_factory: '@keyvalue.expirable' + + # Services from php-tuf/composer-stager package. + PhpTuf\ComposerStager\API\Core\BeginnerInterface: + class: PhpTuf\ComposerStager\Internal\Core\Beginner + PhpTuf\ComposerStager\API\Core\CleanerInterface: + class: PhpTuf\ComposerStager\Internal\Core\Cleaner + PhpTuf\ComposerStager\API\Core\CommitterInterface: + class: PhpTuf\ComposerStager\Internal\Core\Committer + PhpTuf\ComposerStager\API\Core\StagerInterface: + class: PhpTuf\ComposerStager\Internal\Core\Stager + PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface: + class: PhpTuf\ComposerStager\Internal\Environment\Service\Environment + PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface: + class: PhpTuf\ComposerStager\Internal\FileSyncer\Service\FileSyncer + PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface: + class: PhpTuf\ComposerStager\Internal\Filesystem\Service\Filesystem + PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface: + class: PhpTuf\ComposerStager\Internal\Finder\Service\ExecutableFinder + PhpTuf\ComposerStager\API\Finder\Service\FileFinderInterface: + class: PhpTuf\ComposerStager\Internal\Finder\Service\FileFinder + PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface: + class: PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory + PhpTuf\ComposerStager\API\Path\Factory\PathListFactoryInterface: + class: PhpTuf\ComposerStager\Internal\Path\Factory\PathListFactory + PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveAndStagingDirsAreDifferent + PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirExistsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirExists + PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirIsReadyInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsReady + PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirIsWritableInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsWritable + PhpTuf\ComposerStager\API\Precondition\Service\BeginnerPreconditionsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\BeginnerPreconditions + PhpTuf\ComposerStager\API\Precondition\Service\CleanerPreconditionsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\CleanerPreconditions + PhpTuf\ComposerStager\API\Precondition\Service\CommitterPreconditionsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\CommitterPreconditions + PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\CommonPreconditions + PhpTuf\ComposerStager\API\Precondition\Service\ComposerIsAvailableInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\ComposerIsAvailable + PhpTuf\ComposerStager\API\Precondition\Service\HostSupportsRunningProcessesInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\HostSupportsRunningProcesses + PhpTuf\ComposerStager\API\Precondition\Service\NoAbsoluteSymlinksExistInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist + PhpTuf\ComposerStager\API\Precondition\Service\NoHardLinksExistInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist + PhpTuf\ComposerStager\API\Precondition\Service\NoLinksExistOnWindowsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows + PhpTuf\ComposerStager\API\Precondition\Service\NoNestingOnWindowsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\NoNestingOnWindows + PhpTuf\ComposerStager\API\Precondition\Service\NoSymlinksPointOutsideTheCodebaseInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase + PhpTuf\ComposerStager\API\Precondition\Service\NoUnsupportedLinksExistInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\NoUnsupportedLinksExist + PhpTuf\ComposerStager\API\Precondition\Service\RsyncIsAvailableInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\RsyncIsAvailable + PhpTuf\ComposerStager\API\Precondition\Service\StagerPreconditionsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\StagerPreconditions + PhpTuf\ComposerStager\API\Precondition\Service\StagingDirDoesNotExistInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirDoesNotExist + PhpTuf\ComposerStager\API\Precondition\Service\StagingDirExistsInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirExists + PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsReadyInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirIsReady + PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsWritableInterface: + class: PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirIsWritable + PhpTuf\ComposerStager\API\Process\Factory\ProcessFactoryInterface: + class: PhpTuf\ComposerStager\Internal\Process\Factory\ProcessFactory + PhpTuf\ComposerStager\API\Process\Service\ComposerProcessRunnerInterface: + class: PhpTuf\ComposerStager\Internal\Process\Service\ComposerProcessRunner + PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface: + class: PhpTuf\ComposerStager\Internal\Process\Service\OutputCallback + PhpTuf\ComposerStager\API\Process\Service\ProcessInterface: + class: PhpTuf\ComposerStager\Internal\Process\Service\Process + PhpTuf\ComposerStager\API\Process\Service\RsyncProcessRunnerInterface: + class: PhpTuf\ComposerStager\Internal\Process\Service\RsyncProcessRunner + PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface: + class: PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableFactory + PhpTuf\ComposerStager\API\Translation\Service\DomainOptionsInterface: + class: PhpTuf\ComposerStager\Internal\Translation\Service\DomainOptions + PhpTuf\ComposerStager\API\Translation\Service\LocaleOptionsInterface: + class: PhpTuf\ComposerStager\Internal\Translation\Service\LocaleOptions + PhpTuf\ComposerStager\API\Translation\Service\TranslatorInterface: + class: PhpTuf\ComposerStager\Internal\Translation\Service\Translator + PhpTuf\ComposerStager\Internal\Path\Service\PathHelperInterface: + class: PhpTuf\ComposerStager\Internal\Path\Service\PathHelper + public: false + PhpTuf\ComposerStager\Internal\Process\Factory\SymfonyProcessFactoryInterface: + class: PhpTuf\ComposerStager\Internal\Process\Factory\SymfonyProcessFactory + public: false + PhpTuf\ComposerStager\Internal\Process\Service\OutputCallbackAdapterInterface: + class: PhpTuf\ComposerStager\Internal\Process\Service\OutputCallbackAdapter + public: false + PhpTuf\ComposerStager\Internal\Translation\Service\SymfonyTranslatorProxyInterface: + class: PhpTuf\ComposerStager\Internal\Translation\Service\SymfonyTranslatorProxy + public: false diff --git a/core/modules/package_manager/src/PackageManagerServiceProvider.php b/core/modules/package_manager/src/PackageManagerServiceProvider.php deleted file mode 100644 index 648fc2a480b240666ac39458bef04f04b7859cf9..0000000000000000000000000000000000000000 --- a/core/modules/package_manager/src/PackageManagerServiceProvider.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\package_manager; - -use Composer\InstalledVersions; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\DependencyInjection\ServiceProviderInterface; - -/** - * Defines dynamic container services for Package Manager. - * - * Scans the Composer Stager library and registers its classes in the Drupal - * service container. - * - * @todo Refactor this if/when https://www.drupal.org/i/3111008 is fixed. - * - * @internal - * This is an internal part of Package Manager and may be changed or removed - * at any time without warning. External code should not interact with this - * class. - */ -final class PackageManagerServiceProvider implements ServiceProviderInterface { - - /** - * {@inheritdoc} - */ - public function register(ContainerBuilder $container): void { - $path = InstalledVersions::getInstallPath('php-tuf/composer-stager') . '/src'; - - // Certain subdirectories of Composer Stager shouldn't be scanned for - // services. - $ignore_directories = [ - $path . '/API/Exception', - $path . '/Internal/Helper', - $path . '/Internal/Path/Value', - $path . '/Internal/Translation/Value', - ]; - // As we scan for services, compile a list of which classes implement which - // interfaces so that we can set up aliases for interfaces that are only - // implemented by one class (to facilitate autowiring). - $interfaces = []; - - // Find all `.php` files in Composer Stager which aren't in the ignored - // directories. - $iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::CURRENT_AS_SELF | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS); - $iterator = new \RecursiveCallbackFilterIterator($iterator, static function (\SplFileInfo $current) use ($ignore_directories): bool { - if ($current->isDir()) { - return !in_array($current->getPathname(), $ignore_directories, TRUE); - } - return $current->getExtension() === 'php'; - }); - $iterator = new \RecursiveIteratorIterator($iterator); - - /** @var \SplFileInfo $file */ - foreach ($iterator as $file) { - // Convert the file name to a class name. - $class_name = substr($file->getPathname(), strlen($path) + 1, -4); - $class_name = 'PhpTuf\\ComposerStager\\' . str_replace(DIRECTORY_SEPARATOR, '\\', $class_name); - - // Don't register interfaces and abstract classes as services. - $reflector = new \ReflectionClass($class_name); - if ($reflector->isInterface() || $reflector->isAbstract()) { - continue; - } - foreach ($reflector->getInterfaceNames() as $interface) { - $interfaces[$interface][] = $class_name; - } - // Register the class as an autowired, private service. - $container->register($class_name) - ->setClass($class_name) - ->setAutowired(TRUE) - ->setPublic(FALSE); - } - - // Create aliases for interfaces that are only implemented by one class. - // Ignore interfaces that already have a service alias. - foreach ($interfaces as $interface_name => $implementations) { - if (count($implementations) === 1 && !$container->hasAlias($interface_name)) { - $container->setAlias($interface_name, $implementations[0]); - } - } - - } - -} diff --git a/core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php b/core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php index a86450f0b39373fa263276a5eaf33000d3c71df1..7601550d1d06c0feee1f0046df5594ad22cf6472 100644 --- a/core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php +++ b/core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php @@ -104,6 +104,11 @@ public function testCoreServiceAliases(): void { continue; } + // Skip IDs that are interfaces already. + if (interface_exists($id)) { + continue; + } + // Expect standalone classes to be aliased. $implements = class_implements($class); if (!$implements) {