You are here

class ConjunctionInterceptor in Drupal 7

Hierarchy

Expanded class hierarchy of ConjunctionInterceptor

File

misc/typo3/phar-stream-wrapper/src/Interceptor/ConjunctionInterceptor.php, line 17

Namespace

TYPO3\PharStreamWrapper\Interceptor
View source
class ConjunctionInterceptor implements Assertable {

  /**
   * @var Assertable[]
   */
  private $assertions;
  public function __construct(array $assertions) {
    $this
      ->assertAssertions($assertions);
    $this->assertions = $assertions;
  }

  /**
   * Executes assertions based on all contained assertions.
   *
   * @param string $path
   * @param string $command
   * @return bool
   * @throws Exception
   */
  public function assert($path, $command) {
    if ($this
      ->invokeAssertions($path, $command)) {
      return true;
    }
    throw new Exception(sprintf('Assertion failed in "%s"', $path), 1539625084);
  }

  /**
   * @param Assertable[] $assertions
   */
  private function assertAssertions(array $assertions) {
    foreach ($assertions as $assertion) {
      if (!$assertion instanceof Assertable) {
        throw new \InvalidArgumentException(sprintf('Instance %s must implement Assertable', get_class($assertion)), 1539624719);
      }
    }
  }

  /**
   * @param string $path
   * @param string $command
   * @return bool
   */
  private function invokeAssertions($path, $command) {
    try {
      foreach ($this->assertions as $assertion) {
        if (!$assertion
          ->assert($path, $command)) {
          return false;
        }
      }
    } catch (Exception $exception) {
      return false;
    }
    return true;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConjunctionInterceptor::$assertions private property
ConjunctionInterceptor::assert public function Executes assertions based on all contained assertions. Overrides Assertable::assert
ConjunctionInterceptor::assertAssertions private function
ConjunctionInterceptor::invokeAssertions private function
ConjunctionInterceptor::__construct public function