class StageNotInActiveValidator

Validates staging root is not a subdirectory of active.

@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

Expanded class hierarchy of StageNotInActiveValidator

1 file declares its use of StageNotInActiveValidator
StageNotInActiveValidatorTest.php in core/modules/package_manager/tests/src/Unit/StageNotInActiveValidatorTest.php

File

core/modules/package_manager/src/Validator/StageNotInActiveValidator.php, line 21

Namespace

Drupal\package_manager\Validator
View source
final class StageNotInActiveValidator implements EventSubscriberInterface {
    use BaseRequirementValidatorTrait {
        getSubscribedEvents as private getSubscribedEventsFromTrait;
    }
    use StringTranslationTrait;
    public function __construct(PathLocator $pathLocator) {
    }
    
    /**
     * Check if staging root is a subdirectory of active.
     */
    public function validate(PreOperationStageEvent $event) : void {
        $project_root = $this->pathLocator
            ->getProjectRoot();
        $staging_root = $this->pathLocator
            ->getStagingRoot();
        if (str_starts_with($staging_root, $project_root)) {
            $message = $this->t("Stage directory is a subdirectory of the active directory.");
            $event->addError([
                $message,
            ]);
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        $events = static::getSubscribedEventsFromTrait();
        // We don't need to listen to PreApplyEvent because once the stage directory
        // has been created, it's not going to be moved.
        unset($events[PreApplyEvent::class]);
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary Member alias Overriden Title Overrides
BaseRequirementValidatorTrait::getSubscribedEvents public static function Implements EventSubscriberInterface::getSubscribedEvents(). Aliased as: getSubscribedEventsFromTrait
StageNotInActiveValidator::getSubscribedEvents public static function
StageNotInActiveValidator::validate public function Check if staging root is a subdirectory of active. Overrides BaseRequirementValidatorTrait::validate
StageNotInActiveValidator::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

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