GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
Move service loading to magic getters in MidCOM core
bergie (author)
Thu Apr 24 21:02:53 -0700 2008
commit  83fab97c704ed023bae58d0f18a2ec58d08ad21a
tree    f0c835413c9f59b33b0fa5fd66f83f568567ba23
parent  2fcc41a60d75dfafbed4e763b9dbf545deae41cd
...
20
21
22
23
24
25
26
 
 
27
28
29
...
55
56
57
58
 
59
60
 
61
62
63
64
 
65
66
67
...
20
21
22
 
 
 
 
23
24
25
26
27
...
53
54
55
 
56
57
 
58
59
60
61
 
62
63
64
65
0
@@ -20,10 +20,8 @@ class midcom_core_controllers_comet
0
     
0
     public function action_messages($route_id, &$data, $args)
0
     {
0
- $uimessages = $_MIDCOM->serviceloader->load('uimessages');
0
-
0
- if ( !$uimessages->supports('comet')
0
- || !$uimessages->can_view())
0
+ if ( !$_MIDCOM->uimessages->supports('comet')
0
+ || !$_MIDCOM->uimessages->can_view())
0
         {
0
             return;
0
         }
0
@@ -55,13 +53,13 @@ class midcom_core_controllers_comet
0
         while (true)
0
         {
0
             $messages = '';
0
- if ($uimessages->has_messages())
0
+ if ($_MIDCOM->uimessages->has_messages())
0
             {
0
- $messages = $uimessages->render_as('comet');
0
+ $messages = $_MIDCOM->uimessages->render_as('comet');
0
             }
0
             else
0
             {
0
- $uimessages->add(array(
0
+ $_MIDCOM->uimessages->add(array(
0
                     'title' => 'Otsikko from comet',
0
                     'message' => 'viesti from comet...'
0
                 ));
...
13
14
15
16
17
18
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
79
80
81
82
83
84
85
86
87
88
89
 
90
91
92
...
98
99
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
102
103
...
13
14
15
 
 
 
16
17
18
19
 
 
20
21
 
22
23
24
 
25
26
27
...
53
54
55
 
 
 
 
 
 
 
 
56
 
 
 
 
57
58
59
...
61
62
63
 
 
 
 
 
 
 
 
64
65
66
67
...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
0
@@ -13,21 +13,15 @@
0
  */
0
 class midcom_core_midcom
0
 {
0
- // Services
0
- public $authentication;
0
- public $authorization;
0
+ // Services that are always available
0
     public $configuration;
0
     public $componentloader;
0
     public $dispatcher;
0
- public $templating;
0
- public $l10n;
0
 
0
     // Helpers
0
- public $navigation;
0
     public $context;
0
     public $timer = false;
0
     
0
-
0
     public function __construct($dispatcher = 'midgard')
0
     {
0
         // Register autoloader so we get all MidCOM classes loaded automatically
0
@@ -59,19 +53,7 @@ class midcom_core_midcom
0
             require_once 'Benchmark/Timer.php';
0
             $this->timer = new Benchmark_Timer(true);
0
         }
0
-
0
- // Load the preferred authentication implementation
0
- $services_authentication_implementation = $this->configuration->get('services_authentication');
0
- $this->authentication = new $services_authentication_implementation();
0
-
0
- // Load the preferred authorization implementation
0
- $services_authorization_implementation = $this->configuration->get('services_authorization');
0
- $this->authorization = new $services_authorization_implementation();
0
         
0
- // Load the preferred templating implementation
0
- $services_templating_implementation = $this->configuration->get('services_templating');
0
- $this->templating = new $services_templating_implementation();
0
-
0
         // Load the component loader
0
         $this->componentloader = new midcom_core_component_loader();
0
         
0
@@ -79,14 +61,7 @@ class midcom_core_midcom
0
         $this->context = new midcom_core_helpers_context();
0
         
0
         //Load the service loader
0
- $this->serviceloader = new midcom_core_services_loader();
0
-
0
- // Load the navigation helper
0
- //$this->navigation = new midcom_core_helpers_navigation();
0
-
0
- // Load the localization
0
- $services_l10n_implementation = $this->configuration->get('services_l10n');
0
- $this->l10n = new $services_l10n_implementation();
0
+ //$this->serviceloader = new midcom_core_services_loader();
0
 
0
         // Load the head helper
0
         $this->head = new midcom_core_helpers_head
0
@@ -98,6 +73,48 @@ class midcom_core_midcom
0
     }
0
     
0
     /**
0
+ * Helper for service initialization. Usually called via getters
0
+ *
0
+ * @param string $service Name of service to load
0
+ */
0
+ private function load_service($service)
0
+ {
0
+ if (isset($this->$service))
0
+ {
0
+ return;
0
+ }
0
+
0
+ $interface_file = MIDCOM_ROOT . "/midcom_core/services/{$service}.php";
0
+ if (!file_exists($interface_file))
0
+ {
0
+ throw new Exception("Service {$service} not installed");
0
+ }
0
+
0
+ if (!class_exists("midcom_core_services_{$service}"))
0
+ {
0
+ //echo "midcom_core_services_{$name}\n<br />";
0
+ //include($interface_file);
0
+ }
0
+
0
+ $service_implementation = $_MIDCOM->configuration->get("services_{$service}");
0
+ if (!$service_implementation)
0
+ {
0
+ throw new Exception("No implementation defined for service {$service}");
0
+ }
0
+
0
+ $this->$service = new $service_implementation();
0
+ }
0
+
0
+ /**
0
+ * Magic getter for service loading
0
+ */
0
+ public function __get($key)
0
+ {
0
+ $this->load_service($key);
0
+ return $this->$key;
0
+ }
0
+
0
+ /**
0
      * Automatically load missing class files
0
      *
0
      * @param string $class_name Name of a missing PHP class
...
96
97
98
99
 
100
101
102
...
96
97
98
 
99
100
101
102
0
@@ -96,7 +96,7 @@ class midcom_core_services_sessioning
0
         }
0
         
0
         // Load the preferred sessioning implementation
0
- $this->sessioning =& $_MIDCOM->serviceloader->load('sessioning');
0
+ $this->sessioning =& $_MIDCOM->sessioning;
0
     }
0
     
0
     /**
...
430
431
432
433
434
435
 
 
436
437
 
438
439
440
...
509
510
511
512
513
 
514
515
516
517
...
430
431
432
 
 
 
433
434
435
 
436
437
438
439
...
508
509
510
 
 
511
512
513
514
515
0
@@ -430,11 +430,10 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
                 }
0
                 
0
                 $tal->uimessages = false;
0
- $uimessages = $_MIDCOM->serviceloader->load('uimessages');
0
- if ( $uimessages->has_messages()
0
- && $uimessages->can_view())
0
+ if ( $_MIDCOM->uimessages->has_messages()
0
+ && $_MIDCOM->uimessages->can_view())
0
                 {
0
- $tal->uimessages = $uimessages->render();
0
+ $tal->uimessages = $_MIDCOM->uimessages->render();
0
                 }
0
 
0
                 if ($_MIDCOM->timer)
0
@@ -509,8 +508,7 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
         }
0
         
0
         ///TODO: Connect this to some signal that tells the MidCOM execution has ended.
0
- $uimessages = $_MIDCOM->serviceloader->load('uimessages');
0
- $uimessages->store();
0
+ $_MIDCOM->uimessages->store();
0
     }
0
 }
0
 ?>
0
\ No newline at end of file
...
50
51
52
53
54
55
56
57
58
59
60
61
 
62
63
64
...
50
51
52
 
 
 
 
 
 
 
 
 
53
54
55
56
0
@@ -50,15 +50,7 @@ class midcom_core_services_uimessages_baseclass
0
         $this->load_configuration();
0
         
0
         $classname = null;
0
- if (array_key_exists('type', $this->configuration))
0
- {
0
- $classname = "midcom_core_services_uimessages_{$this->configuration['type']}";
0
- $this->implementation = new $classname($this->configuration);
0
- }
0
- else
0
- {
0
- $this->implementation =& $_MIDCOM->serviceloader->load('uimessages', &$this->configuration);
0
- }
0
+ $this->implementation =& $_MIDCOM->uimessages;
0
     }
0
     
0
     private function load_configuration()

Comments

    No one has commented yet.