‪TYPO3CMS  10.4
AutowireInjectMethodsPass.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass;
21 use Symfony\Component\DependencyInjection\Definition;
22 
26 class ‪AutowireInjectMethodsPass extends AbstractRecursivePass
27 {
33  protected function ‪processValue($value, $isRoot = false)
34  {
35  $value = parent::processValue($value, $isRoot);
36 
37  if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
38  return $value;
39  }
40  if (!$reflectionClass = $this->container->getReflectionClass($value->getClass(), false)) {
41  return $value;
42  }
43 
44  $alreadyCalledMethods = [];
45 
46  foreach ($value->getMethodCalls() as [$method]) {
47  $alreadyCalledMethods[strtolower($method)] = true;
48  }
49 
50  $addInitCall = false;
51 
52  foreach ($reflectionClass->getMethods() as $reflectionMethod) {
53  $r = $reflectionMethod;
54 
55  if ($r->isConstructor() || isset($alreadyCalledMethods[strtolower($r->name)])) {
56  continue;
57  }
58 
59  if ($reflectionMethod->isPublic() && strpos($reflectionMethod->name, 'inject') === 0) {
60  if ($reflectionMethod->name === 'injectSettings') {
61  continue;
62  }
63 
64  $value->addMethodCall($reflectionMethod->name);
65  }
66 
67  if ($reflectionMethod->name === 'initializeObject' && $reflectionMethod->isPublic()) {
68  $addInitCall = true;
69  }
70  }
71 
72  if ($addInitCall) {
73  // Add call to initializeObject() which is required by classes that need to perform
74  // constructions tasks after the inject* method based injection of dependencies.
75  $value->addMethodCall('initializeObject');
76  }
77 
78  return $value;
79  }
80 }
‪TYPO3\CMS\Core\DependencyInjection\AutowireInjectMethodsPass\processValue
‪mixed processValue($value, $isRoot=false)
Definition: AutowireInjectMethodsPass.php:33
‪TYPO3\CMS\Core\DependencyInjection
Definition: AutowireInjectMethodsPass.php:18
‪TYPO3\CMS\Core\DependencyInjection\AutowireInjectMethodsPass
Definition: AutowireInjectMethodsPass.php:27