[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Compiler/ -> AutowireRequiredMethodsPass.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\DependencyInjection\Compiler;
  13  
  14  use Symfony\Component\DependencyInjection\Definition;
  15  
  16  /**
  17   * Looks for definitions with autowiring enabled and registers their corresponding "@required" methods as setters.
  18   *
  19   * @author Nicolas Grekas <p@tchwork.com>
  20   */
  21  class AutowireRequiredMethodsPass extends AbstractRecursivePass
  22  {
  23      /**
  24       * {@inheritdoc}
  25       */
  26      protected function processValue($value, $isRoot = false)
  27      {
  28          $value = parent::processValue($value, $isRoot);
  29  
  30          if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
  31              return $value;
  32          }
  33          if (!$reflectionClass = $this->container->getReflectionClass($value->getClass(), false)) {
  34              return $value;
  35          }
  36  
  37          $alreadyCalledMethods = [];
  38  
  39          foreach ($value->getMethodCalls() as list($method)) {
  40              $alreadyCalledMethods[strtolower($method)] = true;
  41          }
  42  
  43          foreach ($reflectionClass->getMethods() as $reflectionMethod) {
  44              $r = $reflectionMethod;
  45  
  46              if ($r->isConstructor() || isset($alreadyCalledMethods[strtolower($r->name)])) {
  47                  continue;
  48              }
  49  
  50              while (true) {
  51                  if (false !== $doc = $r->getDocComment()) {
  52                      if (false !== stripos($doc, '@required') && preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@required(?:\s|\*/$)#i', $doc)) {
  53                          $value->addMethodCall($reflectionMethod->name);
  54                          break;
  55                      }
  56                      if (false === stripos($doc, '@inheritdoc') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+(?:\{@inheritdoc\}|@inheritdoc)(?:\s|\*/$)#i', $doc)) {
  57                          break;
  58                      }
  59                  }
  60                  try {
  61                      $r = $r->getPrototype();
  62                  } catch (\ReflectionException $e) {
  63                      break; // method has no prototype
  64                  }
  65              }
  66          }
  67  
  68          return $value;
  69      }
  70  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1