class NoOpStager

A composer-stager Stager implementation that does nothing, except logging.

By default, it will modify composer.lock in the stage directory, to fool the \Drupal\package_manager\Validator\LockFileValidator into thinking that there are pending composer operations.

Opt out of this by calling

setLockFileShouldChange(FALSE);

.

@internal

Hierarchy

Expanded class hierarchy of NoOpStager

See also

::setLockFileShouldChange()

\Drupal\package_manager\Validator\LockFileValidator

2 files declare their use of NoOpStager
LockFileValidatorTest.php in core/modules/package_manager/tests/src/Kernel/LockFileValidatorTest.php
StageBaseTest.php in core/modules/package_manager/tests/src/Kernel/StageBaseTest.php

File

core/modules/package_manager/tests/modules/package_manager_bypass/src/NoOpStager.php, line 28

Namespace

Drupal\package_manager_bypass
View source
final class NoOpStager implements StagerInterface {
    use ComposerStagerExceptionTrait;
    use LoggingDecoratorTrait;
    
    /**
     * Constructs a Stager object.
     *
     * @param \Drupal\Core\State\StateInterface $state
     *   The state service.
     */
    public function __construct(StateInterface $state) {
        $this->state = $state;
    }
    
    /**
     * {@inheritdoc}
     */
    public function stage(array $composerCommand, PathInterface $activeDir, PathInterface $stagingDir, ?OutputCallbackInterface $callback = NULL, ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : void {
        $this->saveInvocationArguments($composerCommand, $stagingDir, $timeout);
        $this->throwExceptionIfSet();
        // If desired, simulate a change to the lock file (e.g., as a result of
        // running `composer update`).
        $lockFile = new JsonFile($stagingDir->absolute() . '/composer.lock');
        $changeLockFile = $this->state
            ->get(static::class . ' lock', TRUE);
        if ($changeLockFile && $lockFile->exists()) {
            $data = $lockFile->read();
            $data['_time'] = microtime();
            $lockFile->write($data);
        }
    }
    
    /**
     * Sets whether ::stage() should simulate a change in the lock file.
     *
     * @param bool $value
     *   (optional) Whether to simulate a change in the lock file when
     *   ::stage() is called. Defaults to TRUE.
     */
    public static function setLockFileShouldChange(bool $value = TRUE) : void {
        \Drupal::state()->set(static::class . ' lock', $value);
    }

}

Members

Title Sort descending Modifiers Object type Summary
ComposerStagerExceptionTrait::setException public static function Sets an exception to be thrown.
ComposerStagerExceptionTrait::throwExceptionIfSet private function Throws the exception if set.
LoggingDecoratorTrait::$state private property The state service.
LoggingDecoratorTrait::getInvocationArguments public function Returns the arguments from every invocation of the main class method.
LoggingDecoratorTrait::saveInvocationArguments private function Records the arguments from an invocation of the main class method.
NoOpStager::setLockFileShouldChange public static function Sets whether ::stage() should simulate a change in the lock file.
NoOpStager::stage public function
NoOpStager::__construct public function Constructs a Stager object.

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