class SymlinkValidator

Same name and namespace in other branches
  1. 11.x core/modules/package_manager/src/Validator/SymlinkValidator.php \Drupal\package_manager\Validator\SymlinkValidator

Flags errors if unsupported symbolic links are detected.

@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.

Hierarchy

  • class \Drupal\package_manager\Validator\SymlinkValidator implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses \Drupal\package_manager\Validator\BaseRequirementValidatorTrait

Expanded class hierarchy of SymlinkValidator

See also

https://github.com/php-tuf/composer-stager/tree/develop/src/Domain/Serv…

1 file declares its use of SymlinkValidator
SymlinkValidatorTest.php in core/modules/package_manager/tests/src/Kernel/SymlinkValidatorTest.php

File

core/modules/package_manager/src/Validator/SymlinkValidator.php, line 26

Namespace

Drupal\package_manager\Validator
View source
final class SymlinkValidator implements EventSubscriberInterface {
  use BaseRequirementValidatorTrait;
  public function __construct(private readonly PathLocator $pathLocator, private readonly NoUnsupportedLinksExistInterface $precondition, private readonly PathFactoryInterface $pathFactory, private readonly PathListFactoryInterface $pathListFactory) {
  }
  
  /**
   * Flags errors if the project root or stage directory contain symbolic links.
   */
  public function validate(SandboxValidationEvent $event) : void {
    if ($event instanceof PreRequireEvent) {
      // We don't need to check symlinks again during PreRequireEvent; this was
      // already just validated during PreCreateEvent.
      return;
    }
    $active_dir = $this->pathFactory
      ->create($this->pathLocator
      ->getProjectRoot());
    // The precondition requires us to pass both an active and stage directory,
    // so if the stage hasn't been created or claimed yet, use the directory
    // that contains this file, which contains only a few files and no symlinks,
    // as the stage directory. The precondition itself doesn't care if the
    // directory actually exists or not.
    $stage_dir = __DIR__;
    if ($event->sandboxManager
      ->sandboxDirectoryExists()) {
      $stage_dir = $event->sandboxManager
        ->getSandboxDirectory();
    }
    $stage_dir = $this->pathFactory
      ->create($stage_dir);
    // Return early if no excluded paths were collected because this validator
    // is dependent on knowing which paths to exclude when searching for
    // symlinks.
    // @see \Drupal\package_manager\StatusCheckTrait::runStatusCheck()
    if ($event->excludedPaths === NULL) {
      return;
    }
    // The list of excluded paths is immutable, but the precondition may need to
    // mutate it, so convert it back to a normal, mutable path list.
    $exclusions = $this->pathListFactory
      ->create(...$event->excludedPaths
      ->getAll());
    try {
      $this->precondition
        ->assertIsFulfilled($active_dir, $stage_dir, $exclusions);
    } catch (PreconditionException $e) {
      $event->addErrorFromThrowable($e);
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
BaseRequirementValidatorTrait::getSubscribedEvents public static function Implements EventSubscriberInterface::getSubscribedEvents().
SymlinkValidator::validate public function Flags errors if the project root or stage directory contain symbolic links. Overrides BaseRequirementValidatorTrait::validate
SymlinkValidator::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.