[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/typo3/phar-stream-wrapper/src/Interceptor/ -> ConjunctionInterceptor.php (source)

   1  <?php
   2  declare(strict_types=1);
   3  namespace TYPO3\PharStreamWrapper\Interceptor;
   4  
   5  /*
   6   * This file is part of the TYPO3 project.
   7   *
   8   * It is free software; you can redistribute it and/or modify it under the terms
   9   * of the MIT License (MIT). For the full copyright and license information,
  10   * please read the LICENSE file that was distributed with this source code.
  11   *
  12   * The TYPO3 project - inspiring people to share!
  13   */
  14  
  15  use TYPO3\PharStreamWrapper\Assertable;
  16  use TYPO3\PharStreamWrapper\Exception;
  17  
  18  class ConjunctionInterceptor implements Assertable
  19  {
  20      /**
  21       * @var Assertable[]
  22       */
  23      private $assertions;
  24  
  25      public function __construct(array $assertions)
  26      {
  27          $this->assertAssertions($assertions);
  28          $this->assertions = $assertions;
  29      }
  30  
  31      /**
  32       * Executes assertions based on all contained assertions.
  33       *
  34       * @param string $path
  35       * @param string $command
  36       * @return bool
  37       * @throws Exception
  38       */
  39      public function assert(string $path, string $command): bool
  40      {
  41          if ($this->invokeAssertions($path, $command)) {
  42              return true;
  43          }
  44          throw new Exception(
  45              sprintf(
  46                  'Assertion failed in "%s"',
  47                  $path
  48              ),
  49              1539625084
  50          );
  51      }
  52  
  53      /**
  54       * @param Assertable[] $assertions
  55       */
  56      private function assertAssertions(array $assertions)
  57      {
  58          foreach ($assertions as $assertion) {
  59              if (!$assertion instanceof Assertable) {
  60                  throw new \InvalidArgumentException(
  61                      sprintf(
  62                          'Instance %s must implement Assertable',
  63                          get_class($assertion)
  64                      ),
  65                      1539624719
  66                  );
  67              }
  68          }
  69      }
  70  
  71      /**
  72       * @param string $path
  73       * @param string $command
  74       * @return bool
  75       */
  76      private function invokeAssertions(string $path, string $command): bool
  77      {
  78          try {
  79              foreach ($this->assertions as $assertion) {
  80                  if (!$assertion->assert($path, $command)) {
  81                      return false;
  82                  }
  83              }
  84          } catch (Exception $exception) {
  85              return false;
  86          }
  87          return true;
  88      }
  89  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer