@@ -32,7 +32,66 @@ public function __construct(array $extensionClasses = [], array $userConfig = []
3232 {
3333 $ this ->extensionClasses = $ extensionClasses ;
3434 $ this ->userConfig = $ userConfig ;
35- $ this ->init ();
35+ }
36+
37+ /**
38+ * Configure the container. This method will call the `configure()` method
39+ * on each extension. Extensions must use this opportunity to register their
40+ * services and define any default config.
41+ *
42+ * This method must be called before `build()`.
43+ */
44+ public function init ()
45+ {
46+ $ extensions = [];
47+
48+ if (empty ($ this ->extensionClasses ) && empty ($ this ->userConfig )) {
49+ return ;
50+ }
51+
52+ foreach ($ this ->extensionClasses as $ extensionClass ) {
53+ if (!class_exists ($ extensionClass )) {
54+ throw new \InvalidArgumentException (sprintf (
55+ 'Extension class "%s" does not exist ' ,
56+ $ extensionClass
57+ ));
58+ }
59+
60+ $ extension = new $ extensionClass ();
61+
62+ if (!$ extension instanceof ExtensionInterface) {
63+ throw new \InvalidArgumentException (sprintf (
64+ // add any manually specified extensions
65+ 'Extension "%s" must implement the PhpBench \\Extension interface ' ,
66+ get_class ($ extension )
67+ ));
68+ }
69+
70+ $ extensions [] = $ extension ;
71+
72+ $ this ->config = array_merge (
73+ $ this ->config ,
74+ $ extension ->getDefaultConfig ()
75+ );
76+ }
77+
78+ $ diff = array_diff (array_keys ($ this ->userConfig ), array_keys ($ this ->config ));
79+
80+ if ($ diff ) {
81+ throw new \InvalidArgumentException (sprintf (
82+ 'Unknown configuration keys: "%s". Permitted keys: "%s" ' ,
83+ implode ('", " ' , $ diff ), implode ('", " ' , array_keys ($ this ->config ))
84+ ));
85+ }
86+
87+ $ this ->config = array_merge (
88+ $ this ->config ,
89+ $ this ->userConfig
90+ );
91+
92+ foreach ($ extensions as $ extension ) {
93+ $ extension ->load ($ this );
94+ }
3695 }
3796
3897 /**
@@ -177,61 +236,4 @@ public function hasParameter($name)
177236 {
178237 return array_key_exists ($ name , $ this ->config );
179238 }
180-
181- private function init ()
182- {
183- $ extensions = [];
184-
185- if (empty ($ this ->extensionClasses ) && empty ($ this ->userConfig )) {
186- return ;
187- }
188-
189- foreach ($ this ->extensionClasses as $ extensionClass ) {
190- if (!class_exists ($ extensionClass )) {
191- throw new \InvalidArgumentException (sprintf (
192- 'Extension class "%s" does not exist ' ,
193- $ extensionClass
194- ));
195- }
196-
197- $ extension = new $ extensionClass ();
198-
199- if (!$ extension instanceof ExtensionInterface) {
200- throw new \InvalidArgumentException (sprintf (
201- // add any manually specified extensions
202- 'Extension "%s" must implement the PhpBench \\Extension interface ' ,
203- get_class ($ extension )
204- ));
205- }
206-
207- $ extensions [] = $ extension ;
208-
209- $ this ->config = array_merge (
210- $ this ->config ,
211- $ extension ->getDefaultConfig ()
212- );
213- }
214-
215- $ diff = array_diff (array_keys ($ this ->userConfig ), array_keys ($ this ->config ));
216-
217- if ($ diff ) {
218- throw new \InvalidArgumentException (sprintf (
219- 'Unknown configuration keys: "%s". Permitted keys: "%s" ' ,
220- implode ('", " ' , $ diff ), implode ('", " ' , array_keys ($ this ->config ))
221- ));
222- }
223-
224- $ this ->config = array_merge (
225- $ this ->config ,
226- $ this ->userConfig
227- );
228-
229- foreach ($ extensions as $ extension ) {
230- $ extension ->load ($ this );
231- }
232-
233- foreach ($ extensions as $ extension ) {
234- $ extension ->build ($ this );
235- }
236- }
237239}
0 commit comments