11
11
12
12
namespace Symfony \Component \DependencyInjection \Loader ;
13
13
14
- use Symfony \Component \Config \Resource \FileResource ;
14
+ require_once __DIR__ .'/PhpFileLoader/functions.php ' ;
15
+
16
+ use Symfony \Component \DependencyInjection \Definition ;
17
+ use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
18
+ use Symfony \Component \DependencyInjection \Loader \PhpFileLoader \AliasConfigurator ;
19
+ use Symfony \Component \DependencyInjection \Loader \PhpFileLoader \Internal \AbstractDefaultsConfigurator ;
20
+ use Symfony \Component \DependencyInjection \Loader \PhpFileLoader \ParamConfigurator ;
21
+ use Symfony \Component \DependencyInjection \Loader \PhpFileLoader \ReferenceConfigurator ;
22
+ use Symfony \Component \DependencyInjection \Reference ;
15
23
16
24
/**
17
25
* PhpFileLoader loads service definitions from a PHP file.
23
31
*/
24
32
class PhpFileLoader extends FileLoader
25
33
{
34
+ private $ defaults ;
35
+
26
36
/**
27
37
* {@inheritdoc}
28
38
*/
@@ -35,6 +45,8 @@ public function load($resource, $type = null)
35
45
$ path = $ this ->locator ->locate ($ resource );
36
46
$ this ->setCurrentDir (dirname ($ path ));
37
47
$ this ->container ->fileExists ($ path );
48
+ $ this ->defaults = new Definition ();
49
+ $ this ->instanceof = array ();
38
50
39
51
include $ path ;
40
52
}
@@ -54,4 +66,51 @@ public function supports($resource, $type = null)
54
66
55
67
return 'php ' === $ type ;
56
68
}
69
+
70
+ /**
71
+ * @internal
72
+ */
73
+ public static function call (\Closure $ callback )
74
+ {
75
+ $ trace = debug_backtrace (DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS , 4 );
76
+ if (!isset ($ trace [3 ]['object ' ]) || !$ trace [3 ]['object ' ] instanceof self) {
77
+ throw new \ErrorException (sprintf ('Function "%s()" must be called in a "%s" context. ' , $ trace [1 ]['function ' ], __CLASS__ ), 0 , E_ERROR , $ trace [1 ]['file ' ], $ trace [1 ]['line ' ]);
78
+ }
79
+ $ callback = $ callback ->bindTo ($ trace [3 ]['object ' ], __CLASS__ );
80
+
81
+ return $ callback ($ trace [3 ]['object ' ]->defaults , $ trace [1 ]['file ' ]);
82
+ }
83
+
84
+ /**
85
+ * @internal
86
+ */
87
+ public static function processValue ($ value )
88
+ {
89
+ if (is_array ($ value )) {
90
+ foreach ($ value as $ k => $ v ) {
91
+ $ value [$ k ] = self ::processValue ($ v );
92
+ }
93
+
94
+ return $ value ;
95
+ }
96
+
97
+ if ($ value instanceof PhpFileLoader \ReferenceConfigurator) {
98
+ static $ refCast ;
99
+
100
+ if (!$ refCast ) {
101
+ $ refCast = \Closure::bind (function ($ ref ) {
102
+ return new Reference ($ ref ->id , $ ref ->invalidBehavior );
103
+ }, $ value , $ value );
104
+ }
105
+
106
+ // cast ReferenceConfigurator to Reference
107
+ return $ refCast ($ value );
108
+ }
109
+
110
+ if ($ value instanceof AbstractDefaultsConfigurator || $ value instanceof AliasConfigurator || $ value instanceof ParamConfigurator) {
111
+ throw new InvalidArgumentException (sprintf ('"%s()" can be used only at the root of service configuration files. ' , $ value ::FACTORY ));
112
+ }
113
+
114
+ return $ value ;
115
+ }
57
116
}
0 commit comments