class DirectWritePreconditionBypass

Allows certain Composer Stager preconditions to be bypassed.

Only certain preconditions can be bypassed; this class implements all of those interfaces, and only accepts them in its constructor.

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

File

core/modules/package_manager/src/DirectWritePreconditionBypass.php, line 25

Namespace

Drupal\package_manager
View source
final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDifferentInterface {
    use StringTranslationTrait;
    
    /**
     * Whether or not the decorated precondition is being bypassed.
     *
     * @var bool
     */
    private static bool $isBypassed = FALSE;
    public function __construct(ActiveAndStagingDirsAreDifferentInterface $decorated) {
    }
    
    /**
     * Bypasses the decorated precondition.
     */
    public static function activate() : void {
        static::$isBypassed = TRUE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getName() : TranslatableInterface {
        return $this->decorated
            ->getName();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDescription() : TranslatableInterface {
        return $this->decorated
            ->getDescription();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getStatusMessage(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = NULL, int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : TranslatableInterface {
        if (static::$isBypassed) {
            return new TranslatableStringAdapter('This precondition has been skipped because it is not needed in direct-write mode.');
        }
        return $this->decorated
            ->getStatusMessage($activeDir, $stagingDir, $exclusions, $timeout);
    }
    
    /**
     * {@inheritdoc}
     */
    public function isFulfilled(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = NULL, int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : bool {
        if (static::$isBypassed) {
            return TRUE;
        }
        return $this->decorated
            ->isFulfilled($activeDir, $stagingDir, $exclusions, $timeout);
    }
    
    /**
     * {@inheritdoc}
     */
    public function assertIsFulfilled(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = NULL, int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : void {
        if (static::$isBypassed) {
            return;
        }
        $this->decorated
            ->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getLeaves() : array {
        return [
            $this,
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
DirectWritePreconditionBypass::$isBypassed private static property Whether or not the decorated precondition is being bypassed.
DirectWritePreconditionBypass::activate public static function Bypasses the decorated precondition.
DirectWritePreconditionBypass::assertIsFulfilled public function
DirectWritePreconditionBypass::getDescription public function
DirectWritePreconditionBypass::getLeaves public function
DirectWritePreconditionBypass::getName public function
DirectWritePreconditionBypass::getStatusMessage public function
DirectWritePreconditionBypass::isFulfilled public function
DirectWritePreconditionBypass::__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. 1

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