[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/ -> ProxiedMethodsFilter.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace ProxyManager\ProxyGenerator\Util;
   6  
   7  use ReflectionClass;
   8  use ReflectionMethod;
   9  
  10  /**
  11   * Utility class used to filter methods that can be proxied
  12   *
  13   * @author Marco Pivetta <ocramius@gmail.com>
  14   * @license MIT
  15   */
  16  final class ProxiedMethodsFilter
  17  {
  18      /**
  19       * @var string[]
  20       */
  21      private static $defaultExcluded = [
  22          '__get',
  23          '__set',
  24          '__isset',
  25          '__unset',
  26          '__clone',
  27          '__sleep',
  28          '__wakeup',
  29      ];
  30  
  31      /**
  32       * @param ReflectionClass $class    reflection class from which methods should be extracted
  33       * @param string[]        $excluded methods to be ignored
  34       *
  35       * @return ReflectionMethod[]
  36       */
  37      public static function getProxiedMethods(ReflectionClass $class, array $excluded = null) : array
  38      {
  39          return self::doFilter($class, (null === $excluded) ? self::$defaultExcluded : $excluded);
  40      }
  41  
  42      /**
  43       * @param ReflectionClass $class    reflection class from which methods should be extracted
  44       * @param string[]        $excluded methods to be ignored
  45       *
  46       * @return ReflectionMethod[]
  47       */
  48      public static function getAbstractProxiedMethods(ReflectionClass $class, array $excluded = null) : array
  49      {
  50          return self::doFilter($class, (null === $excluded) ? self::$defaultExcluded : $excluded, true);
  51      }
  52  
  53      /**
  54       * @param ReflectionClass $class
  55       * @param string[]        $excluded
  56       * @param bool            $requireAbstract
  57       *
  58       * @return ReflectionMethod[]
  59       */
  60      private static function doFilter(ReflectionClass $class, array $excluded, bool $requireAbstract = false) : array
  61      {
  62          $ignored = array_flip(array_map('strtolower', $excluded));
  63  
  64          return array_filter(
  65              $class->getMethods(ReflectionMethod::IS_PUBLIC),
  66              function (ReflectionMethod $method) use ($ignored, $requireAbstract) : bool {
  67                  return (! $requireAbstract || $method->isAbstract()) && ! (
  68                      \array_key_exists(strtolower($method->getName()), $ignored)
  69                      || self::methodCannotBeProxied($method)
  70                  );
  71              }
  72          );
  73      }
  74  
  75      /**
  76       * Checks whether the method cannot be proxied
  77       */
  78      private static function methodCannotBeProxied(ReflectionMethod $method) : bool
  79      {
  80          return $method->isConstructor() || $method->isFinal() || $method->isStatic();
  81      }
  82  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1