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 Configure extends Object {
00035
00036
00037
00038
00039
00040
00041 var $modelPaths = array();
00042
00043
00044
00045
00046
00047
00048 var $behaviorPaths = array();
00049
00050
00051
00052
00053
00054
00055 var $controllerPaths = array();
00056
00057
00058
00059
00060
00061
00062 var $componentPaths = array();
00063
00064
00065
00066
00067
00068
00069 var $viewPaths = array();
00070
00071
00072
00073
00074
00075
00076 var $helperPaths = array();
00077
00078
00079
00080
00081
00082
00083 var $pluginPaths = array();
00084
00085
00086
00087
00088
00089
00090 var $vendorPaths = array();
00091
00092
00093
00094
00095
00096
00097 var $localePaths = array();
00098
00099
00100
00101
00102
00103
00104 var $shellPaths = array();
00105
00106
00107
00108
00109
00110
00111
00112 var $debug = null;
00113
00114
00115
00116
00117
00118
00119 var $__cache = false;
00120
00121
00122
00123
00124
00125
00126 var $__objects = array();
00127
00128
00129
00130
00131
00132
00133 function &getInstance($boot = true) {
00134 static $instance = array();
00135 if (!$instance) {
00136 $instance[0] =& new Configure();
00137 $instance[0]->__loadBootstrap($boot);
00138 }
00139 return $instance[0];
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149 function listObjects($type, $path = null, $cache = true) {
00150 $objects = array();
00151 $extension = false;
00152 $name = $type;
00153
00154 if ($type === 'file' && !$path) {
00155 return false;
00156 } elseif ($type === 'file') {
00157 $extension = true;
00158 $name = $type . str_replace(DS, '', $path);
00159 }
00160 $_this =& Configure::getInstance();
00161
00162 if (empty($_this->__objects) && $cache === true) {
00163 $_this->__objects = Cache::read('object_map', '_cake_core_');
00164 }
00165
00166 if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) {
00167 $types = array(
00168 'model' => array('suffix' => '.php', 'base' => 'AppModel', 'core' => false),
00169 'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'),
00170 'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'),
00171 'component' => array('suffix' => '.php', 'base' => null),
00172 'view' => array('suffix' => '.php', 'base' => null),
00173 'helper' => array('suffix' => '.php', 'base' => 'AppHelper'),
00174 'plugin' => array('suffix' => '', 'base' => null),
00175 'vendor' => array('suffix' => '', 'base' => null),
00176 'class' => array('suffix' => '.php', 'base' => null),
00177 'file' => array('suffix' => '.php', 'base' => null)
00178 );
00179
00180 if (!isset($types[$type])) {
00181 return false;
00182 }
00183 $objects = array();
00184
00185 if (empty($path)) {
00186 $path = $_this->{$type . 'Paths'};
00187 if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
00188 array_pop($path);
00189 }
00190 }
00191 $items = array();
00192
00193 foreach ((array)$path as $dir) {
00194 if ($type === 'file' || $type === 'class' || strpos($dir, $type) !== false) {
00195 $items = $_this->__list($dir, $types[$type]['suffix'], $extension);
00196 $objects = array_merge($items, array_diff($objects, $items));
00197 }
00198 }
00199
00200 if ($type !== 'file') {
00201 foreach ($objects as $key => $value) {
00202 $objects[$key] = Inflector::camelize($value);
00203 }
00204 }
00205 if ($cache === true && !empty($objects)) {
00206 $_this->__objects[$name] = $objects;
00207 $_this->__cache = true;
00208 } else {
00209 return $objects;
00210 }
00211 }
00212 return $_this->__objects[$name];
00213 }
00214
00215
00216
00217
00218
00219
00220
00221 function __list($path, $suffix = false, $extension = false) {
00222 if (!class_exists('Folder')) {
00223 require LIBS . 'folder.php';
00224 }
00225 $items = array();
00226 $Folder =& new Folder($path);
00227 $contents = $Folder->read(false, true);
00228
00229 if (is_array($contents)) {
00230 if (!$suffix) {
00231 return $contents[0];
00232 } else {
00233 foreach ($contents[1] as $item) {
00234 if (substr($item, - strlen($suffix)) === $suffix) {
00235 if ($extension) {
00236 $items[] = $item;
00237 } else {
00238 $items[] = substr($item, 0, strlen($item) - strlen($suffix));
00239 }
00240 }
00241 }
00242 }
00243 }
00244 return $items;
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 function write($config, $value = null) {
00271 $_this =& Configure::getInstance();
00272
00273 if (!is_array($config)) {
00274 $config = array($config => $value);
00275 }
00276
00277 foreach ($config as $names => $value) {
00278 $name = $_this->__configVarNames($names);
00279
00280 switch (count($name)) {
00281 case 3:
00282 $_this->{$name[0]}[$name[1]][$name[2]] = $value;
00283 break;
00284 case 2:
00285 $_this->{$name[0]}[$name[1]] = $value;
00286 break;
00287 case 1:
00288 $_this->{$name[0]} = $value;
00289 break;
00290 }
00291 }
00292
00293 if (isset($config['debug'])) {
00294 if ($_this->debug) {
00295 error_reporting(E_ALL);
00296
00297 if (function_exists('ini_set')) {
00298 ini_set('display_errors', 1);
00299 }
00300
00301 if (!class_exists('Debugger')) {
00302 require LIBS . 'debugger.php';
00303 }
00304 if (!class_exists('CakeLog')) {
00305 require LIBS . 'cake_log.php';
00306 }
00307 Configure::write('log', LOG_NOTICE);
00308 } else {
00309 error_reporting(0);
00310 Configure::write('log', LOG_NOTICE);
00311 }
00312 }
00313 }
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 function read($var = 'debug') {
00327 $_this =& Configure::getInstance();
00328
00329 if ($var === 'debug') {
00330 if (!isset($_this->debug)) {
00331 if (defined('DEBUG')) {
00332 $_this->debug = DEBUG;
00333 } else {
00334 $_this->debug = 0;
00335 }
00336 }
00337 return $_this->debug;
00338 }
00339 $name = $_this->__configVarNames($var);
00340
00341 switch (count($name)) {
00342 case 3:
00343 if (isset($_this->{$name[0]}[$name[1]][$name[2]])) {
00344 return $_this->{$name[0]}[$name[1]][$name[2]];
00345 }
00346 break;
00347 case 2:
00348 if (isset($_this->{$name[0]}[$name[1]])) {
00349 return $_this->{$name[0]}[$name[1]];
00350 }
00351 break;
00352 case 1:
00353 if (isset($_this->{$name[0]})) {
00354 return $_this->{$name[0]};
00355 }
00356 break;
00357 }
00358 return null;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 function delete($var = null) {
00373 $_this =& Configure::getInstance();
00374 $name = $_this->__configVarNames($var);
00375
00376 if (count($name) > 1) {
00377 unset($_this->{$name[0]}[$name[1]]);
00378 } else {
00379 unset($_this->{$name[0]});
00380 }
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 function load($fileName) {
00397 $found = false;
00398
00399 if (file_exists(CONFIGS . $fileName . '.php')) {
00400 include(CONFIGS . $fileName . '.php');
00401 $found = true;
00402 } elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) {
00403 include(CACHE . 'persistent' . DS . $fileName . '.php');
00404 $found = true;
00405 } else {
00406 foreach (Configure::corePaths('cake') as $key => $path) {
00407 if (file_exists($path . DS . 'config' . DS . $fileName . '.php')) {
00408 include($path . DS . 'config' . DS . $fileName . '.php');
00409 $found = true;
00410 break;
00411 }
00412 }
00413 }
00414
00415 if (!$found) {
00416 return false;
00417 }
00418
00419 if (!isset($config)) {
00420 $error = __("Configure::load() - no variable \$config found in %s.php", true);
00421 trigger_error(sprintf($error, $fileName), E_USER_WARNING);
00422 return false;
00423 }
00424 return Configure::write($config);
00425 }
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 function version() {
00436 $_this =& Configure::getInstance();
00437
00438 if (!isset($_this->Cake['version'])) {
00439 require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
00440 $_this->write($config);
00441 }
00442 return $_this->Cake['version'];
00443 }
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 function store($type, $name, $data = array()) {
00458 $write = true;
00459 $content = '';
00460
00461 foreach ($data as $key => $value) {
00462 $content .= "\$config['$type']['$key']";
00463
00464 if (is_array($value)) {
00465 $content .= " = array(";
00466
00467 foreach ($value as $key1 => $value2) {
00468 $value2 = addslashes($value2);
00469 $content .= "'$key1' => '$value2', ";
00470 }
00471 $content .= ");\n";
00472 } else {
00473 $value = addslashes($value);
00474 $content .= " = '$value';\n";
00475 }
00476 }
00477 if (is_null($type)) {
00478 $write = false;
00479 }
00480 Configure::__writeConfig($content, $name, $write);
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 function corePaths($type = null) {
00492 $paths = Cache::read('core_paths', '_cake_core_');
00493 if (!$paths) {
00494 $paths = array();
00495 $openBasedir = ini_get('open_basedir');
00496 if ($openBasedir) {
00497 $all = explode(PATH_SEPARATOR, $openBasedir);
00498 $all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
00499 } else {
00500 $all = explode(PATH_SEPARATOR, ini_get('include_path'));
00501 $all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
00502 }
00503 foreach ($all as $path) {
00504 if ($path !== DS) {
00505 $path = rtrim($path, DS);
00506 }
00507 if (empty($path) || $path === '.') {
00508 continue;
00509 }
00510 $cake = $path . DS . 'cake' . DS;
00511 $libs = $cake . 'libs' . DS;
00512 if (is_dir($libs)) {
00513 $paths['libs'][] = $libs;
00514 $paths['model'][] = $libs . 'model' . DS;
00515 $paths['behavior'][] = $libs . 'model' . DS . 'behaviors' . DS;
00516 $paths['controller'][] = $libs . 'controller' . DS;
00517 $paths['component'][] = $libs . 'controller' . DS . 'components' . DS;
00518 $paths['view'][] = $libs . 'view' . DS;
00519 $paths['helper'][] = $libs . 'view' . DS . 'helpers' . DS;
00520 $paths['cake'][] = $cake;
00521 $paths['vendor'][] = $path . DS . 'vendors' . DS;
00522 $paths['shell'][] = $cake . 'console' . DS . 'libs' . DS;
00523 break;
00524 }
00525 }
00526 Cache::write('core_paths', array_filter($paths), '_cake_core_');
00527 }
00528 if ($type && isset($paths[$type])) {
00529 return $paths[$type];
00530 }
00531 return $paths;
00532 }
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543 function __writeConfig($content, $name, $write = true) {
00544 $file = CACHE . 'persistent' . DS . $name . '.php';
00545
00546 if (Configure::read() > 0) {
00547 $expires = "+10 seconds";
00548 } else {
00549 $expires = "+999 days";
00550 }
00551 $cache = cache('persistent' . DS . $name . '.php', null, $expires);
00552
00553 if ($cache === null) {
00554 cache('persistent' . DS . $name . '.php', "<?php\n\$config = array();\n", $expires);
00555 }
00556
00557 if ($write === true) {
00558 if (!class_exists('File')) {
00559 require LIBS . 'file.php';
00560 }
00561 $fileClass = new File($file);
00562
00563 if ($fileClass->writable()) {
00564 $fileClass->append($content);
00565 }
00566 }
00567 }
00568
00569
00570
00571
00572
00573
00574
00575 function __configVarNames($name) {
00576 if (is_string($name)) {
00577 if (strpos($name, ".")) {
00578 return explode(".", $name);
00579 }
00580 return array($name);
00581 }
00582 return $name;
00583 }
00584
00585
00586
00587
00588
00589
00590
00591
00592 function buildPaths($paths) {
00593 $_this =& Configure::getInstance();
00594 $core = $_this->corePaths();
00595 $basePaths = array(
00596 'model' => array(MODELS),
00597 'behavior' => array(BEHAVIORS),
00598 'controller' => array(CONTROLLERS),
00599 'component' => array(COMPONENTS),
00600 'view' => array(VIEWS),
00601 'helper' => array(HELPERS),
00602 'plugin' => array(APP . 'plugins' . DS),
00603 'vendor' => array(APP . 'vendors' . DS, VENDORS),
00604 'locale' => array(APP . 'locale' . DS),
00605 'shell' => array(),
00606 'datasource' => array(MODELS . 'datasources')
00607 );
00608
00609 foreach ($basePaths as $type => $default) {
00610 $pathsVar = $type . 'Paths';
00611 $merge = array();
00612
00613 if (isset($core[$type])) {
00614 $merge = $core[$type];
00615 }
00616 if ($type === 'model' || $type === 'controller' || $type === 'helper') {
00617 $merge = array_merge(array(APP), $merge);
00618 }
00619
00620 if (!is_array($default)) {
00621 $default = array($default);
00622 }
00623 $_this->{$pathsVar} = $default;
00624
00625 if (isset($paths[$pathsVar]) && !empty($paths[$pathsVar])) {
00626 $path = array_flip(array_flip((array_merge(
00627 $_this->{$pathsVar}, (array)$paths[$pathsVar], $merge
00628 ))));
00629 $_this->{$pathsVar} = array_values($path);
00630 } else {
00631 $path = array_flip(array_flip((array_merge($_this->{$pathsVar}, $merge))));
00632 $_this->{$pathsVar} = array_values($path);
00633 }
00634 }
00635 }
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645 function __loadBootstrap($boot) {
00646 $modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = $localePaths = $shellPaths = null;
00647
00648 if ($boot) {
00649 Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
00650
00651 if (!include(CONFIGS . 'core.php')) {
00652 trigger_error(sprintf(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
00653 }
00654
00655 if (!include(CONFIGS . 'bootstrap.php')) {
00656 trigger_error(sprintf(__("Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
00657 }
00658
00659 if (Configure::read('Cache.disable') !== true) {
00660 $cache = Cache::config('default');
00661
00662 if (empty($cache['settings'])) {
00663 trigger_error('Cache not configured properly. Please check Cache::config(); in APP/config/core.php', E_USER_WARNING);
00664 $cache = Cache::config('default', array('engine' => 'File'));
00665 }
00666 $path = $prefix = $duration = null;
00667
00668 if (!empty($cache['settings']['path'])) {
00669 $path = realpath($cache['settings']['path']);
00670 } else {
00671 $prefix = $cache['settings']['prefix'];
00672 }
00673
00674 if (Configure::read() >= 1) {
00675 $duration = '+10 seconds';
00676 } else {
00677 $duration = '+999 days';
00678 }
00679
00680 if (Cache::config('_cake_core_') === false) {
00681 Cache::config('_cake_core_', array_merge($cache['settings'], array(
00682 'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
00683 'serialize' => true, 'duration' => $duration
00684 )));
00685 }
00686
00687 if (Cache::config('_cake_model_') === false) {
00688 Cache::config('_cake_model_', array_merge($cache['settings'], array(
00689 'prefix' => $prefix . 'cake_model_', 'path' => $path . DS . 'models' . DS,
00690 'serialize' => true, 'duration' => $duration
00691 )));
00692 }
00693 Cache::config('default');
00694 }
00695 Configure::buildPaths(compact(
00696 'modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths',
00697 'behaviorPaths', 'pluginPaths', 'vendorPaths', 'localePaths', 'shellPaths'
00698 ));
00699 }
00700 }
00701
00702
00703
00704
00705
00706 function __destruct() {
00707 if ($this->__cache) {
00708 Cache::write('object_map', array_filter($this->__objects), '_cake_core_');
00709 }
00710 }
00711 }
00712
00713
00714
00715
00716
00717
00718
00719
00720 class App extends Object {
00721
00722
00723
00724
00725
00726
00727 var $search = array();
00728
00729
00730
00731
00732
00733
00734 var $return = false;
00735
00736
00737
00738
00739
00740
00741 var $__cache = false;
00742
00743
00744
00745
00746
00747
00748 var $__map = array();
00749
00750
00751
00752
00753
00754
00755 var $__paths = array();
00756
00757
00758
00759
00760
00761
00762 var $__loaded = array();
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781 function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
00782 $plugin = $directory = null;
00783
00784 if (is_array($type)) {
00785 extract($type, EXTR_OVERWRITE);
00786 }
00787
00788 if (is_array($parent)) {
00789 extract($parent, EXTR_OVERWRITE);
00790 }
00791
00792 if ($name === null && $file === null) {
00793 $name = $type;
00794 $type = 'Core';
00795 } elseif ($name === null) {
00796 $type = 'File';
00797 }
00798
00799 if (is_array($name)) {
00800 foreach ($name as $class) {
00801 $tempType = $type;
00802 $plugin = null;
00803
00804 if (strpos($class, '.') !== false) {
00805 $value = explode('.', $class);
00806 $count = count($value);
00807
00808 if ($count > 2) {
00809 $tempType = $value[0];
00810 $plugin = $value[1] . '.';
00811 $class = $value[2];
00812 } elseif ($count === 2 && ($type === 'Core' || $type === 'File')) {
00813 $tempType = $value[0];
00814 $class = $value[1];
00815 } else {
00816 $plugin = $value[0] . '.';
00817 $class = $value[1];
00818 }
00819 }
00820
00821 if (!App::import($tempType, $plugin . $class)) {
00822 return false;
00823 }
00824 }
00825 return true;
00826 }
00827
00828 if ($name != null && strpos($name, '.') !== false) {
00829 list($plugin, $name) = explode('.', $name);
00830 }
00831 $_this =& App::getInstance();
00832 $_this->return = $return;
00833
00834 if (isset($ext)) {
00835 $file = Inflector::underscore($name) . ".$ext";
00836 }
00837 $ext = $_this->__settings($type, $plugin, $parent);
00838
00839 if ($name != null && !class_exists($name . $ext['class'])) {
00840 if ($load = $_this->__mapped($name . $ext['class'], $type, $plugin)) {
00841 if ($_this->__load($load)) {
00842 $_this->__overload($type, $name . $ext['class']);
00843
00844 if ($_this->return) {
00845 $value = include $load;
00846 return $value;
00847 }
00848 return true;
00849 } else {
00850 $_this->__remove($name . $ext['class'], $type, $plugin);
00851 $_this->__cache = true;
00852 }
00853 }
00854 if (!empty($search)) {
00855 $_this->search = $search;
00856 } elseif ($plugin) {
00857 $_this->search = $_this->__paths('plugin');
00858 } else {
00859 $_this->search = $_this->__paths($type);
00860 }
00861 $find = $file;
00862
00863 if ($find === null) {
00864 $find = Inflector::underscore($name . $ext['suffix']).'.php';
00865
00866 if ($plugin) {
00867 $paths = $_this->search;
00868 foreach ($paths as $key => $value) {
00869 $_this->search[$key] = $value . $ext['path'];
00870 }
00871 $plugin = Inflector::camelize($plugin);
00872 }
00873 }
00874
00875 if (strtolower($type) !== 'vendor' && empty($search) && $_this->__load($file)) {
00876 $directory = false;
00877 } else {
00878 $file = $find;
00879 $directory = $_this->__find($find, true);
00880 }
00881
00882 if ($directory !== null) {
00883 $_this->__cache = true;
00884 $_this->__map($directory . $file, $name . $ext['class'], $type, $plugin);
00885 $_this->__overload($type, $name . $ext['class']);
00886
00887 if ($_this->return) {
00888 $value = include $directory . $file;
00889 return $value;
00890 }
00891 return true;
00892 }
00893 return false;
00894 }
00895 return true;
00896 }
00897
00898
00899
00900
00901
00902
00903 function &getInstance() {
00904 static $instance = array();
00905 if (!$instance) {
00906 $instance[0] =& new App();
00907 $instance[0]->__map = Cache::read('file_map', '_cake_core_');
00908 }
00909 return $instance[0];
00910 }
00911
00912
00913
00914
00915
00916
00917
00918
00919 function __find($file, $recursive = true) {
00920 if (empty($this->search)) {
00921 return null;
00922 } elseif (is_string($this->search)) {
00923 $this->search = array($this->search);
00924 }
00925
00926 if (empty($this->__paths)) {
00927 $this->__paths = Cache::read('dir_map', '_cake_core_');
00928 }
00929
00930 foreach ($this->search as $path) {
00931 $path = rtrim($path, DS);
00932
00933 if ($path === rtrim(APP, DS)) {
00934 $recursive = false;
00935 }
00936 if ($recursive === false) {
00937 if ($this->__load($path . DS . $file)) {
00938 return $path . DS;
00939 }
00940 continue;
00941 }
00942 if (!isset($this->__paths[$path])) {
00943 if (!class_exists('Folder')) {
00944 require LIBS . 'folder.php';
00945 }
00946 $Folder =& new Folder();
00947 $directories = $Folder->tree($path, false, 'dir');
00948 $this->__paths[$path] = $directories;
00949 }
00950
00951 foreach ($this->__paths[$path] as $directory) {
00952 if ($this->__load($directory . DS . $file)) {
00953 return $directory . DS;
00954 }
00955 }
00956 }
00957 return null;
00958 }
00959
00960
00961
00962
00963
00964
00965
00966 function __load($file) {
00967 if (empty($file)) {
00968 return false;
00969 }
00970 if (!$this->return && isset($this->__loaded[$file])) {
00971 return true;
00972 }
00973 if (file_exists($file)) {
00974 if (!$this->return) {
00975 require($file);
00976 $this->__loaded[$file] = true;
00977 }
00978 return true;
00979 }
00980 return false;
00981 }
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991 function __map($file, $name, $type, $plugin) {
00992 if ($plugin) {
00993 $plugin = Inflector::camelize($plugin);
00994 $this->__map['Plugin'][$plugin][$type][$name] = $file;
00995 } else {
00996 $this->__map[$type][$name] = $file;
00997 }
00998 }
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008 function __mapped($name, $type, $plugin) {
01009 if ($plugin) {
01010 $plugin = Inflector::camelize($plugin);
01011
01012 if (isset($this->__map['Plugin'][$plugin][$type]) && isset($this->__map['Plugin'][$plugin][$type][$name])) {
01013 return $this->__map['Plugin'][$plugin][$type][$name];
01014 }
01015 return false;
01016 }
01017
01018 if (isset($this->__map[$type]) && isset($this->__map[$type][$name])) {
01019 return $this->__map[$type][$name];
01020 }
01021 return false;
01022 }
01023
01024
01025
01026
01027
01028
01029
01030 function __overload($type, $name) {
01031 if (($type === 'Model' || $type === 'Helper') && strtolower($name) != 'schema') {
01032 Overloadable::overload($name);
01033 }
01034 }
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045 function __settings($type, $plugin, $parent) {
01046 if (!$parent) {
01047 return null;
01048 }
01049
01050 if ($plugin) {
01051 $plugin = Inflector::underscore($plugin);
01052 $name = Inflector::camelize($plugin);
01053 }
01054 $path = null;
01055 $load = strtolower($type);
01056
01057 switch ($load) {
01058 case 'model':
01059 if (!class_exists('Model')) {
01060 App::import('Core', 'Model', false, Configure::corePaths('model'));
01061 }
01062 if (!class_exists('AppModel')) {
01063 App::import($type, 'AppModel', false, Configure::read('modelPaths'));
01064 }
01065 if ($plugin) {
01066 if (!class_exists($name . 'AppModel')) {
01067 App::import($type, $plugin . '.' . $name . 'AppModel', false, array(), $plugin . DS . $plugin . '_app_model.php');
01068 }
01069 $path = $plugin . DS . 'models' . DS;
01070 }
01071 return array('class' => null, 'suffix' => null, 'path' => $path);
01072 break;
01073 case 'behavior':
01074 if ($plugin) {
01075 $path = $plugin . DS . 'models' . DS . 'behaviors' . DS;
01076 }
01077 return array('class' => $type, 'suffix' => null, 'path' => $path);
01078 break;
01079 case 'controller':
01080 App::import($type, 'AppController', false);
01081 if ($plugin) {
01082 App::import($type, $plugin . '.' . $name . 'AppController', false, array(), $plugin . DS . $plugin . '_app_controller.php');
01083 $path = $plugin . DS . 'controllers' . DS;
01084 }
01085 return array('class' => $type, 'suffix' => $type, 'path' => $path);
01086 break;
01087 case 'component':
01088 if ($plugin) {
01089 $path = $plugin . DS . 'controllers' . DS . 'components' . DS;
01090 }
01091 return array('class' => $type, 'suffix' => null, 'path' => $path);
01092 break;
01093 case 'view':
01094 if ($plugin) {
01095 $path = $plugin . DS . 'views' . DS;
01096 }
01097 return array('class' => $type, 'suffix' => null, 'path' => $path);
01098 break;
01099 case 'helper':
01100 if (!class_exists('AppHelper')) {
01101 App::import($type, 'AppHelper', false);
01102 }
01103 if ($plugin) {
01104 $path = $plugin . DS . 'views' . DS . 'helpers' . DS;
01105 }
01106 return array('class' => $type, 'suffix' => null, 'path' => $path);
01107 break;
01108 case 'vendor':
01109 if ($plugin) {
01110 $path = $plugin . DS . 'vendors' . DS;
01111 }
01112 return array('class' => null, 'suffix' => null, 'path' => $path);
01113 break;
01114 default:
01115 $type = $suffix = $path = null;
01116 break;
01117 }
01118 return array('class' => null, 'suffix' => null, 'path' => null);
01119 }
01120
01121
01122
01123
01124
01125
01126
01127 function __paths($type) {
01128 $type = strtolower($type);
01129
01130 if ($type === 'core') {
01131 $path = Configure::corePaths();
01132 $paths = array();
01133
01134 foreach ($path as $key => $value) {
01135 $count = count($key);
01136 for ($i = 0; $i < $count; $i++) {
01137 $paths[] = $path[$key][$i];
01138 }
01139 }
01140 return $paths;
01141 }
01142
01143 if ($paths = Configure::read($type . 'Paths')) {
01144 return $paths;
01145 }
01146
01147 switch ($type) {
01148 case 'plugin':
01149 return array(APP . 'plugins' . DS);
01150 case 'vendor':
01151 return array(APP . 'vendors' . DS, VENDORS, APP . 'plugins' . DS);
01152 case 'controller':
01153 return array(APP . 'controllers' . DS, APP);
01154 case 'model':
01155 return array(APP . 'models' . DS, APP);
01156 case 'view':
01157 return array(APP . 'views' . DS);
01158 }
01159 }
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169 function __remove($name, $type, $plugin) {
01170 if ($plugin) {
01171 $plugin = Inflector::camelize($plugin);
01172 unset($this->__map['Plugin'][$plugin][$type][$name]);
01173 } else {
01174 unset($this->__map[$type][$name]);
01175 }
01176 }
01177
01178
01179
01180
01181
01182
01183
01184
01185 function __destruct() {
01186 if ($this->__cache) {
01187 $core = Configure::corePaths('cake');
01188 unset($this->__paths[rtrim($core[0], DS)]);
01189 Cache::write('dir_map', array_filter($this->__paths), '_cake_core_');
01190 Cache::write('file_map', array_filter($this->__map), '_cake_core_');
01191 }
01192 }
01193 }
01194 ?>