[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/typo3/phar-stream-wrapper/src/Interceptor/ -> PharExtensionInterceptor.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  use TYPO3\PharStreamWrapper\Manager;
  18  
  19  class PharExtensionInterceptor implements Assertable
  20  {
  21      /**
  22       * Determines whether the base file name has a ".phar" suffix.
  23       *
  24       * @param string $path
  25       * @param string $command
  26       * @return bool
  27       * @throws Exception
  28       */
  29      public function assert(string $path, string $command): bool
  30      {
  31          if ($this->baseFileContainsPharExtension($path)) {
  32              return true;
  33          }
  34          throw new Exception(
  35              sprintf(
  36                  'Unexpected file extension in "%s"',
  37                  $path
  38              ),
  39              1535198703
  40          );
  41      }
  42  
  43      /**
  44       * @param string $path
  45       * @return bool
  46       */
  47      private function baseFileContainsPharExtension(string $path): bool
  48      {
  49          $invocation = Manager::instance()->resolve($path);
  50          if ($invocation === null) {
  51              return false;
  52          }
  53          $fileExtension = pathinfo($invocation->getBaseName(), PATHINFO_EXTENSION);
  54          return strtolower($fileExtension) === 'phar';
  55      }
  56  }


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