public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
Initial injector support
bergie (author)
Mon Sep 01 03:26:53 -0700 2008
commit  1b590f1d9ad9e14dba69bdbe0628cc116935b2d7
tree    7b8c0a03c6254bb1c25ce204d10d6b0ef27d2e9a
parent  cdaa463c207494e7026ef85a794f2d708477fc36
...
17
18
19
 
 
20
21
22
...
188
189
190
 
 
 
 
 
 
 
 
 
 
 
 
191
192
 
193
194
195
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
198
199
...
201
202
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
205
206
207
...
17
18
19
20
21
22
23
24
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
 
206
207
208
 
 
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
0
@@ -17,6 +17,8 @@ class midcom_core_component_loader
0
     public $authors = array();
0
     private $tried_to_load = array();
0
     private $interfaces = array();
0
+ private $process_injectors = array();
0
+ private $template_injectors = array();
0
 
0
     public function __construct()
0
     {
0
@@ -188,12 +190,44 @@ class midcom_core_component_loader
0
         {
0
             $this->manifests[$manifest['component']] = $manifest;
0
         }
0
+
0
+ if (isset($manifest['process_injector']))
0
+ {
0
+ // This component has an injector for the process() phase
0
+ $this->process_injectors[$manifest['component']] = $manifest['process_injector'];
0
+ }
0
+
0
+ if (isset($manifest['template_injector']))
0
+ {
0
+ // This component has an injector for the template() phase
0
+ $this->template_injectors[$manifest['component']] = $manifest['template_injector'];
0
+ }
0
     }
0
-
0
+
0
     private function load_all_manifests()
0
     {
0
- // TODO: Cache
0
- exec('find ' . escapeshellarg(MIDCOM_ROOT) . ' -follow -type f -name ' . escapeshellarg('manifest.yml'), $manifests);
0
+ if (!class_exists('Memcache'))
0
+ {
0
+ // Uncached manifest loading is very slow
0
+ exec('find ' . escapeshellarg(MIDCOM_ROOT) . ' -follow -type f -name ' . escapeshellarg('manifest.yml'), $manifests);
0
+ foreach ($manifests as $manifest)
0
+ {
0
+ if (strpos($manifest, 'scaffold') === false)
0
+ {
0
+ $this->load_manifest($manifest);
0
+ }
0
+ }
0
+ return;
0
+ }
0
+
0
+ // TODO: Refactor to utilize cache service infrastructure
0
+ $memcache = new Memcache;
0
+ $memcache->connect('localhost');
0
+ if (!$manifests = $memcache->get('manifests'))
0
+ {
0
+ exec('find ' . escapeshellarg(MIDCOM_ROOT) . ' -follow -type f -name ' . escapeshellarg('manifest.yml'), $manifests);
0
+ $memcache->set('manifests', $manifests, false, 600);
0
+ }
0
         foreach ($manifests as $manifest)
0
         {
0
             if (strpos($manifest, 'scaffold') === false)
0
@@ -201,6 +235,37 @@ class midcom_core_component_loader
0
                 $this->load_manifest($manifest);
0
             }
0
         }
0
+ $memcache->close();
0
+ }
0
+
0
+ /**
0
+ * Injectors are component classes that manipulate the context
0
+ */
0
+ private function inject($injector_type)
0
+ {
0
+ $injector_array = "{$injector_type}_injectors";
0
+ $injector_method = "inject_{$injector_type}";
0
+ foreach ($this->$injector_array as $component => $injector_class)
0
+ {
0
+ // Ensure the component is loaded
0
+ $this->load($component);
0
+
0
+ // Instantiate the injector class
0
+ $injector = new $injector_class();
0
+
0
+ // Inject
0
+ $injector->$injector_method();
0
+ }
0
+ }
0
+
0
+ public function inject_process()
0
+ {
0
+ $this->inject('process');
0
+ }
0
+
0
+ public function inject_template()
0
+ {
0
+ $this->inject('process');
0
     }
0
 }
0
 ?>
0
\ No newline at end of file
...
173
174
175
 
 
 
176
177
178
...
173
174
175
176
177
178
179
180
181
0
@@ -173,6 +173,9 @@ class midcom_core_midcom
0
         // Set up templating and environment
0
         $_MIDCOM->templating->append_directory(MIDCOM_ROOT . '/midcom_core/templates');
0
         $this->dispatcher->populate_environment_data();
0
+
0
+ // Let injectors do their work
0
+ $this->componentloader->inject_process();
0
 
0
         // Load component
0
         try
...
386
387
388
 
 
 
389
390
391
...
386
387
388
389
390
391
392
393
394
0
@@ -386,6 +386,9 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
      */
0
     public function template($element_identifier = 'template_entry_point')
0
     {
0
+ // Let injectors do their work
0
+ $_MIDCOM->componentloader->inject_template();
0
+
0
         $this->prepare_cache();
0
         $cache_file = $this->cache_directory . '/' . $this->get_cache_identifier() . '.php';
0
 

Comments

    No one has commented yet.