component.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Component extends Object {
00035
00036
00037
00038
00039
00040
00041 var $__controller = null;
00042
00043
00044
00045 function __construct() {
00046 }
00047
00048
00049
00050
00051
00052
00053 function init(&$controller) {
00054 $this->__controller =& $controller;
00055
00056 if ($this->__controller->components !== false) {
00057 $loaded = array();
00058 $this->__controller->components = array_merge(array('Session'), $this->__controller->components);
00059 $loaded = $this->__loadComponents($loaded, $this->__controller->components);
00060
00061 foreach (array_keys($loaded)as $component) {
00062 $tempComponent =& $loaded[$component];
00063
00064 if (isset($tempComponent->components) && is_array($tempComponent->components)) {
00065 foreach ($tempComponent->components as $subComponent) {
00066 $this->__controller->{$component}->{$subComponent} =& $loaded[$subComponent];
00067 }
00068 }
00069 if (is_callable(array($tempComponent, 'initialize'))) {
00070 $tempComponent->initialize($controller);
00071 }
00072 }
00073 }
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 function &__loadComponents(&$loaded, $components) {
00085 foreach ($components as $component) {
00086 $parts = preg_split('/\/|\./', $component);
00087
00088 if (count($parts) === 1) {
00089 $plugin = $this->__controller->plugin;
00090 } else {
00091 $plugin = Inflector::underscore($parts['0']);
00092 $component = $parts[count($parts) - 1];
00093 }
00094
00095 $componentCn = $component . 'Component';
00096
00097 if (in_array($component, array_keys($loaded)) !== true) {
00098
00099 if (!class_exists($componentCn)) {
00100
00101 if (is_null($plugin) || !loadPluginComponent($plugin, $component)) {
00102
00103 if (!loadComponent($component)) {
00104 $this->cakeError('missingComponentFile', array(array(
00105 'className' => $this->__controller->name,
00106 'component' => $component,
00107 'file' => Inflector::underscore($component) . '.php',
00108 'base' => $this->__controller->base)));
00109 exit();
00110 }
00111 }
00112
00113 if (!class_exists($componentCn)) {
00114 $this->cakeError('missingComponentClass', array(array(
00115 'className' => $this->__controller->name,
00116 'component' => $component,
00117 'file' => Inflector::underscore($component) . '.php',
00118 'base' => $this->__controller->base)));
00119 exit();
00120 }
00121 }
00122
00123 if ($componentCn == 'SessionComponent') {
00124 $param = strip_plugin($this->__controller->base, $this->__controller->plugin) . '/';
00125 } else {
00126 $param = null;
00127 }
00128 $this->__controller->{$component} =& new $componentCn($param);
00129 $loaded[$component] =& $this->__controller->{$component};
00130
00131 if (isset($this->__controller->{$component}->components) && is_array($this->__controller->{$component}->components)) {
00132 $loaded =& $this->__loadComponents($loaded, $this->__controller->{$component}->components);
00133 }
00134 }
00135 }
00136 return $loaded;
00137 }
00138 }
00139 ?>