[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Assertion/ -> CanProxyAssertion.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  namespace ProxyManager\ProxyGenerator\Assertion;
  20  
  21  use BadMethodCallException;
  22  use ProxyManager\Exception\InvalidProxiedClassException;
  23  use ReflectionClass;
  24  use ReflectionMethod;
  25  
  26  /**
  27   * Assertion that verifies that a class can be proxied
  28   *
  29   * @author Marco Pivetta <ocramius@gmail.com>
  30   * @license MIT
  31   */
  32  final class CanProxyAssertion
  33  {
  34      /**
  35       * Disabled constructor: not meant to be instantiated
  36       *
  37       * @throws BadMethodCallException
  38       */
  39      public function __construct()
  40      {
  41          throw new BadMethodCallException('Unsupported constructor.');
  42      }
  43  
  44      /**
  45       * @param ReflectionClass $originalClass
  46       * @param bool            $allowInterfaces
  47       *
  48       * @throws InvalidProxiedClassException
  49       */
  50      public static function assertClassCanBeProxied(ReflectionClass $originalClass, $allowInterfaces = true)
  51      {
  52          self::isNotFinal($originalClass);
  53          self::hasNoAbstractProtectedMethods($originalClass);
  54  
  55          if (! $allowInterfaces) {
  56              self::isNotInterface($originalClass);
  57          }
  58      }
  59  
  60      /**
  61       * @param ReflectionClass $originalClass
  62       *
  63       * @throws InvalidProxiedClassException
  64       */
  65      private static function isNotFinal(ReflectionClass $originalClass)
  66      {
  67          if ($originalClass->isFinal()) {
  68              throw InvalidProxiedClassException::finalClassNotSupported($originalClass);
  69          }
  70      }
  71  
  72      /**
  73       * @param ReflectionClass $originalClass
  74       *
  75       * @throws InvalidProxiedClassException
  76       */
  77      private static function hasNoAbstractProtectedMethods(ReflectionClass $originalClass)
  78      {
  79          $protectedAbstract = array_filter(
  80              $originalClass->getMethods(),
  81              function (ReflectionMethod $method) {
  82                  return $method->isAbstract() && $method->isProtected();
  83              }
  84          );
  85  
  86          if ($protectedAbstract) {
  87              throw InvalidProxiedClassException::abstractProtectedMethodsNotSupported($originalClass);
  88          }
  89      }
  90  
  91      /**
  92       * @param ReflectionClass $originalClass
  93       *
  94       * @throws InvalidProxiedClassException
  95       */
  96      private static function isNotInterface(ReflectionClass $originalClass)
  97      {
  98          if ($originalClass->isInterface()) {
  99              throw InvalidProxiedClassException::interfaceNotSupported($originalClass);
 100          }
 101      }
 102  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1