[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ -> ClassNameInflector.php (source)

   1  <?php
   2  /*
   3   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   4   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   5   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   6   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   7   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   8   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   9   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14   *
  15   * This software consists of voluntary contributions made by many individuals
  16   * and is licensed under the MIT license.
  17   */
  18  
  19  declare(strict_types=1);
  20  
  21  namespace ProxyManager\Inflector;
  22  
  23  use ProxyManager\Inflector\Util\ParameterHasher;
  24  
  25  /**
  26   * {@inheritDoc}
  27   *
  28   * @author Marco Pivetta <ocramius@gmail.com>
  29   * @license MIT
  30   */
  31  final class ClassNameInflector implements ClassNameInflectorInterface
  32  {
  33      /**
  34       * @var string
  35       */
  36      protected $proxyNamespace;
  37  
  38      /**
  39       * @var int
  40       */
  41      private $proxyMarkerLength;
  42  
  43      /**
  44       * @var string
  45       */
  46      private $proxyMarker;
  47  
  48      /**
  49       * @var \ProxyManager\Inflector\Util\ParameterHasher
  50       */
  51      private $parameterHasher;
  52  
  53      /**
  54       * @param string $proxyNamespace
  55       */
  56      public function __construct(string $proxyNamespace)
  57      {
  58          $this->proxyNamespace    = $proxyNamespace;
  59          $this->proxyMarker       = '\\' . static::PROXY_MARKER . '\\';
  60          $this->proxyMarkerLength = strlen($this->proxyMarker);
  61          $this->parameterHasher   = new ParameterHasher();
  62      }
  63  
  64      /**
  65       * {@inheritDoc}
  66       */
  67      public function getUserClassName(string $className) : string
  68      {
  69          $className = ltrim($className, '\\');
  70  
  71          if (false === $position = strrpos($className, $this->proxyMarker)) {
  72              return $className;
  73          }
  74  
  75          return substr(
  76              $className,
  77              $this->proxyMarkerLength + $position,
  78              strrpos($className, '\\') - ($position + $this->proxyMarkerLength)
  79          );
  80      }
  81  
  82      /**
  83       * {@inheritDoc}
  84       */
  85      public function getProxyClassName(string $className, array $options = []) : string
  86      {
  87          return $this->proxyNamespace
  88              . $this->proxyMarker
  89              . $this->getUserClassName($className)
  90              . '\\Generated' . $this->parameterHasher->hashParameters($options);
  91      }
  92  
  93      /**
  94       * {@inheritDoc}
  95       */
  96      public function isProxyClassName(string $className) : bool
  97      {
  98          return false !== strrpos($className, $this->proxyMarker);
  99      }
 100  }


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1