11
11
12
12
namespace Symfony \Component \DependencyInjection \Compiler ;
13
13
14
+ use Symfony \Component \Config \Resource \ReflectionClassResource ;
14
15
use Symfony \Component \DependencyInjection \Config \AutowireServiceResource ;
15
16
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
17
use Symfony \Component \DependencyInjection \Definition ;
24
25
*/
25
26
class AutowirePass extends AbstractRecursivePass implements CompilerPassInterface
26
27
{
27
- private $ reflectionClasses = array ();
28
28
private $ definedTypes = array ();
29
29
private $ types ;
30
30
private $ ambiguousServiceTypes = array ();
@@ -43,7 +43,6 @@ public function process(ContainerBuilder $container)
43
43
spl_autoload_unregister ($ throwingAutoloader );
44
44
45
45
// Free memory and remove circular reference to container
46
- $ this ->reflectionClasses = array ();
47
46
$ this ->definedTypes = array ();
48
47
$ this ->types = null ;
49
48
$ this ->ambiguousServiceTypes = array ();
@@ -56,9 +55,13 @@ public function process(ContainerBuilder $container)
56
55
* @param \ReflectionClass $reflectionClass
57
56
*
58
57
* @return AutowireServiceResource
58
+ *
59
+ * @deprecated since version 3.3, to be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.
59
60
*/
60
61
public static function createResourceForClass (\ReflectionClass $ reflectionClass )
61
62
{
63
+ @trigger_error ('The ' .__METHOD__ .'() method is deprecated since version 3.3 and will be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead. ' , E_USER_DEPRECATED );
64
+
62
65
$ metadata = array ();
63
66
64
67
foreach ($ reflectionClass ->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ reflectionMethod ) {
@@ -79,14 +82,10 @@ protected function processValue($value, $isRoot = false)
79
82
return parent ::processValue ($ value , $ isRoot );
80
83
}
81
84
82
- if (!$ reflectionClass = $ this ->getReflectionClass ($ isRoot ? $ this -> currentId : null , $ value )) {
85
+ if (!$ reflectionClass = $ this ->container -> getReflectionClass ($ value -> getClass () )) {
83
86
return parent ::processValue ($ value , $ isRoot );
84
87
}
85
88
86
- if ($ this ->container ->isTrackingResources ()) {
87
- $ this ->container ->addResource (static ::createResourceForClass ($ reflectionClass ));
88
- }
89
-
90
89
$ autowiredMethods = $ this ->getMethodsToAutowire ($ reflectionClass , $ autowiredMethods );
91
90
$ methodCalls = $ value ->getMethodCalls ();
92
91
@@ -321,7 +320,7 @@ private function populateAvailableType($id, Definition $definition)
321
320
$ this ->types [$ type ] = $ id ;
322
321
}
323
322
324
- if (!$ reflectionClass = $ this ->getReflectionClass ($ id , $ definition )) {
323
+ if (!$ reflectionClass = $ this ->container -> getReflectionClass ($ definition-> getClass () )) {
325
324
return ;
326
325
}
327
326
@@ -414,40 +413,6 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint)
414
413
return new Reference ($ argumentId );
415
414
}
416
415
417
- /**
418
- * Retrieves the reflection class associated with the given service.
419
- *
420
- * @param string|null $id
421
- * @param Definition $definition
422
- *
423
- * @return \ReflectionClass|false
424
- */
425
- private function getReflectionClass ($ id , Definition $ definition )
426
- {
427
- if (null !== $ id && isset ($ this ->reflectionClasses [$ id ])) {
428
- return $ this ->reflectionClasses [$ id ];
429
- }
430
-
431
- // Cannot use reflection if the class isn't set
432
- if (!$ class = $ definition ->getClass ()) {
433
- return false ;
434
- }
435
-
436
- $ class = $ this ->container ->getParameterBag ()->resolveValue ($ class );
437
-
438
- try {
439
- $ reflector = new \ReflectionClass ($ class );
440
- } catch (\ReflectionException $ e ) {
441
- $ reflector = false ;
442
- }
443
-
444
- if (null !== $ id ) {
445
- $ this ->reflectionClasses [$ id ] = $ reflector ;
446
- }
447
-
448
- return $ reflector ;
449
- }
450
-
451
416
private function addServiceToAmbiguousType ($ id , $ type )
452
417
{
453
418
// keep an array of all services matching this type
@@ -459,6 +424,9 @@ private function addServiceToAmbiguousType($id, $type)
459
424
$ this ->ambiguousServiceTypes [$ type ][] = $ id ;
460
425
}
461
426
427
+ /**
428
+ * @deprecated since version 3.3, to be removed in 4.0.
429
+ */
462
430
private static function getResourceMetadataForMethod (\ReflectionMethod $ method )
463
431
{
464
432
$ methodArgumentsMetadata = array ();
0 commit comments