configure.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
00035
00036
00037 class Configure extends Object {
00038
00039
00040
00041
00042
00043
00044 var $viewPaths = array();
00045
00046
00047
00048
00049
00050
00051 var $controllerPaths = array();
00052
00053
00054
00055
00056
00057
00058 var $modelPaths = array();
00059
00060
00061
00062
00063
00064
00065 var $helperPaths = array();
00066
00067
00068
00069
00070
00071
00072 var $componentPaths = array();
00073
00074
00075
00076
00077
00078
00079 var $debug = null;
00080
00081
00082
00083
00084
00085
00086 function &getInstance() {
00087 static $instance = array();
00088 if (!$instance) {
00089 $instance[0] =& new Configure;
00090 $instance[0]->__loadBootstrap();
00091 }
00092 return $instance[0];
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 function write($config, $value = null) {
00108 $_this =& Configure::getInstance();
00109
00110 if (!is_array($config) && $value !== null) {
00111 $name = $_this->__configVarNames($config);
00112
00113 if (count($name) > 1) {
00114 $_this->{$name[0]}[$name[1]] = $value;
00115 } else {
00116 $_this->{$name[0]} = $value;
00117 }
00118 } else {
00119
00120 foreach ($config as $names => $value) {
00121 $name = $_this->__configVarNames($names);
00122 if (count($name) > 1) {
00123 $_this->{$name[0]}[$name[1]] = $value;
00124 } else {
00125 $_this->{$name[0]} = $value;
00126 }
00127 }
00128 }
00129
00130 if ($config == 'debug' || (is_array($config) && in_array('debug', $config))) {
00131 if ($_this->debug) {
00132 error_reporting(E_ALL);
00133
00134 if (function_exists('ini_set')) {
00135 ini_set('display_errors', 1);
00136 }
00137 } else {
00138 error_reporting(0);
00139 }
00140 }
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 function read($var = 'debug') {
00154 $_this =& Configure::getInstance();
00155 if ($var === 'debug') {
00156 if (!isset($_this->debug)) {
00157 $_this->debug = DEBUG;
00158 }
00159 return $_this->debug;
00160 }
00161
00162 $name = $_this->__configVarNames($var);
00163 if (count($name) > 1) {
00164 if (isset($_this->{$name[0]}[$name[1]])) {
00165 return $_this->{$name[0]}[$name[1]];
00166 }
00167 return null;
00168 } else {
00169 if (isset($_this->{$name[0]})) {
00170 return $_this->{$name[0]};
00171 }
00172 return null;
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 function delete($var = null) {
00187 $_this =& Configure::getInstance();
00188
00189 $name = $_this->__configVarNames($var);
00190 if (count($name) > 1) {
00191 unset($_this->{$name[0]}[$name[1]]);
00192 } else {
00193 unset($_this->{$name[0]});
00194 }
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 function load($fileName) {
00209 $_this =& Configure::getInstance();
00210
00211 if (!file_exists(CONFIGS . $fileName . '.php')) {
00212 trigger_error("Configure::load() - $fileName.php not found", E_USER_WARNING);
00213 return false;
00214 }
00215 include(CONFIGS . $fileName . '.php');
00216 if (!isset($config)) {
00217 trigger_error("Configure::load() - no variable \$config found in $fileName.php", E_USER_WARNING);
00218 return false;
00219 }
00220 return $_this->write($config);
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 function version() {
00232 $_this =& Configure::getInstance();
00233 if (!isset($_this->Cake['version'])) {
00234 require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
00235 $_this->write($config);
00236 }
00237 return $_this->Cake['version'];
00238 }
00239
00240
00241
00242
00243
00244
00245
00246 function __configVarNames($name) {
00247 if (is_string($name)) {
00248 if (strpos($name, ".")) {
00249 $name = explode(".", $name);
00250 } else {
00251 $name = array($name);
00252 }
00253 }
00254 return $name;
00255 }
00256
00257
00258
00259
00260
00261
00262 function __buildModelPaths($modelPaths) {
00263 $_this =& Configure::getInstance();
00264 $_this->modelPaths[] = MODELS;
00265 if (isset($modelPaths)) {
00266 foreach ($modelPaths as $value) {
00267 $_this->modelPaths[] = $value;
00268 }
00269 }
00270 }
00271
00272
00273
00274
00275
00276
00277 function __buildViewPaths($viewPaths) {
00278 $_this =& Configure::getInstance();
00279 $_this->viewPaths[] = VIEWS;
00280 if (isset($viewPaths)) {
00281 foreach ($viewPaths as $value) {
00282 $_this->viewPaths[] = $value;
00283 }
00284 }
00285 }
00286
00287
00288
00289
00290
00291
00292 function __buildControllerPaths($controllerPaths) {
00293 $_this =& Configure::getInstance();
00294 $_this->controllerPaths[] = CONTROLLERS;
00295 if (isset($controllerPaths)) {
00296 foreach ($controllerPaths as $value) {
00297 $_this->controllerPaths[] = $value;
00298 }
00299 }
00300 }
00301
00302
00303
00304
00305
00306
00307 function __buildHelperPaths($helperPaths) {
00308 $_this =& Configure::getInstance();
00309 $_this->helperPaths[] = HELPERS;
00310 if (isset($helperPaths)) {
00311 foreach ($helperPaths as $value) {
00312 $_this->helperPaths[] = $value;
00313 }
00314 }
00315 }
00316
00317
00318
00319
00320
00321
00322 function __buildComponentPaths($componentPaths) {
00323 $_this =& Configure::getInstance();
00324 $_this->componentPaths[] = COMPONENTS;
00325 if (isset($componentPaths)) {
00326 foreach ($componentPaths as $value) {
00327 $_this->componentPaths[] = $value;
00328 }
00329 }
00330 }
00331
00332
00333
00334
00335
00336
00337
00338 function __loadBootstrap() {
00339 $_this =& Configure::getInstance();
00340 $_this->write('Session.checkAgent', true);
00341 $modelPaths = null;
00342 $viewPaths = null;
00343 $controllerPaths = null;
00344 $helperPaths = null;
00345 $componentPaths = null;
00346 require APP_PATH . 'config' . DS . 'bootstrap.php';
00347 $_this->__buildModelPaths($modelPaths);
00348 $_this->__buildViewPaths($viewPaths);
00349 $_this->__buildControllerPaths($controllerPaths);
00350 $_this->__buildHelperPaths($helperPaths);
00351 $_this->__buildComponentPaths($componentPaths);
00352 }
00353 }
00354 ?>