Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

AbstractPrecondition.php

Namespace

PhpTuf\ComposerStager\Internal\Precondition\Service

File

vendor/php-tuf/composer-stager/src/Internal/Precondition/Service/AbstractPrecondition.php

View source
<?php

declare (strict_types=1);
namespace PhpTuf\ComposerStager\Internal\Precondition\Service;

use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface;
use PhpTuf\ComposerStager\API\Exception\PreconditionException;
use PhpTuf\ComposerStager\API\Path\Value\PathInterface;
use PhpTuf\ComposerStager\API\Path\Value\PathListInterface;
use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface;
use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface;
use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface;
use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface;
use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait;

/**
 * @package Precondition
 *
 * @internal Don't depend directly on this class. It may be changed or removed at any time without notice.
 */
abstract class AbstractPrecondition implements PreconditionInterface {
    use TranslatableAwareTrait;
    public final function getStatusMessage(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : TranslatableInterface {
        try {
            $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout);
        } catch (PreconditionException $e) {
            return $e->getTranslatableMessage();
        }
        return $this->getFulfilledStatusMessage();
    }
    public final function getLeaves() : array {
        return [
            $this,
        ];
    }
    public final function isFulfilled(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : bool {
        try {
            $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout);
        } catch (PreconditionException) {
            return false;
        }
        return true;
    }
    
    /**
     * @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException
     *   If the precondition is unfulfilled.
     */
    protected abstract function doAssertIsFulfilled(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : void;
    
    /** Gets a status message for when the precondition is fulfilled. */
    protected abstract function getFulfilledStatusMessage() : TranslatableInterface;
    public function __construct(EnvironmentInterface $environment, TranslatableFactoryInterface $translatableFactory) {
        $this->setTranslatableFactory($translatableFactory);
    }
    public function assertIsFulfilled(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : void {
        $this->environment
            ->setTimeLimit($timeout);
        $this->doAssertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout);
    }

}

Classes

Title Deprecated Summary
AbstractPrecondition @package Precondition

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal