1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: 27: 28: 29: 30: 31: 32:
33: class Configure extends Object {
34: 35: 36: 37: 38: 39:
40: var $modelPaths = array();
41: 42: 43: 44: 45: 46:
47: var $behaviorPaths = array();
48: 49: 50: 51: 52: 53:
54: var $controllerPaths = array();
55: 56: 57: 58: 59: 60:
61: var $componentPaths = array();
62: 63: 64: 65: 66: 67:
68: var $viewPaths = array();
69: 70: 71: 72: 73: 74:
75: var $helperPaths = array();
76: 77: 78: 79: 80: 81:
82: var $pluginPaths = array();
83: 84: 85: 86: 87: 88:
89: var $vendorPaths = array();
90: 91: 92: 93: 94: 95:
96: var $localePaths = array();
97: 98: 99: 100: 101: 102:
103: var $shellPaths = array();
104: 105: 106: 107: 108: 109: 110:
111: var $debug = null;
112: 113: 114: 115: 116: 117:
118: var $__objects = array();
119: 120: 121: 122: 123: 124:
125: function &getInstance($boot = true) {
126: static $instance = array();
127: if (!$instance) {
128: $instance[0] =& new Configure();
129: $instance[0]->__loadBootstrap($boot);
130: }
131: return $instance[0];
132: }
133: 134: 135: 136: 137: 138: 139: 140:
141: function listObjects($type, $path = null, $cache = true) {
142: $objects = array();
143: $extension = false;
144: $name = $type;
145:
146: if ($type === 'file' && !$path) {
147: return false;
148: } elseif ($type === 'file') {
149: $extension = true;
150: $name = $type . str_replace(DS, '', $path);
151: }
152: $_this =& Configure::getInstance();
153:
154: if (empty($_this->__objects) && $cache === true) {
155: $_this->__objects = Cache::read('object_map', '_cake_core_');
156: }
157:
158: if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) {
159: $types = array(
160: 'model' => array('suffix' => '.php', 'base' => 'AppModel', 'core' => false),
161: 'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'),
162: 'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'),
163: 'component' => array('suffix' => '.php', 'base' => null),
164: 'view' => array('suffix' => '.php', 'base' => null),
165: 'helper' => array('suffix' => '.php', 'base' => 'AppHelper'),
166: 'plugin' => array('suffix' => '', 'base' => null),
167: 'vendor' => array('suffix' => '', 'base' => null),
168: 'class' => array('suffix' => '.php', 'base' => null),
169: 'file' => array('suffix' => '.php', 'base' => null)
170: );
171:
172: if (!isset($types[$type])) {
173: return false;
174: }
175: $objects = array();
176:
177: if (empty($path)) {
178: $path = $_this->{$type . 'Paths'};
179: if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
180: array_pop($path);
181: }
182: }
183: $items = array();
184:
185: foreach ((array)$path as $dir) {
186: if ($type === 'file' || $type === 'class' || strpos($dir, $type) !== false) {
187: $items = $_this->__list($dir, $types[$type]['suffix'], $extension);
188: $objects = array_merge($items, array_diff($objects, $items));
189: }
190: }
191:
192: if ($type !== 'file') {
193: foreach ($objects as $key => $value) {
194: $objects[$key] = Inflector::camelize($value);
195: }
196: }
197: if ($cache === true && !empty($objects)) {
198: $_this->__objects[$name] = $objects;
199: $_this->__resetCache(true);
200: } else {
201: return $objects;
202: }
203: }
204: return $_this->__objects[$name];
205: }
206: 207: 208: 209: 210: 211: 212:
213: function __list($path, $suffix = false, $extension = false) {
214: if (!class_exists('Folder')) {
215: require LIBS . 'folder.php';
216: }
217: $items = array();
218: $Folder =& new Folder($path);
219: $contents = $Folder->read(false, true);
220:
221: if (is_array($contents)) {
222: if (!$suffix) {
223: return $contents[0];
224: } else {
225: foreach ($contents[1] as $item) {
226: if (substr($item, - strlen($suffix)) === $suffix) {
227: if ($extension) {
228: $items[] = $item;
229: } else {
230: $items[] = substr($item, 0, strlen($item) - strlen($suffix));
231: }
232: }
233: }
234: }
235: }
236: return $items;
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: function write($config, $value = null) {
263: $_this =& Configure::getInstance();
264:
265: if (!is_array($config)) {
266: $config = array($config => $value);
267: }
268:
269: foreach ($config as $names => $value) {
270: $name = $_this->__configVarNames($names);
271:
272: switch (count($name)) {
273: case 3:
274: $_this->{$name[0]}[$name[1]][$name[2]] = $value;
275: break;
276: case 2:
277: $_this->{$name[0]}[$name[1]] = $value;
278: break;
279: case 1:
280: $_this->{$name[0]} = $value;
281: break;
282: }
283: }
284:
285: if (isset($config['debug'])) {
286: if ($_this->debug) {
287: error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
288:
289: if (function_exists('ini_set')) {
290: ini_set('display_errors', 1);
291: }
292:
293: if (!class_exists('Debugger')) {
294: require LIBS . 'debugger.php';
295: }
296: if (!class_exists('CakeLog')) {
297: require LIBS . 'cake_log.php';
298: }
299: Configure::write('log', LOG_NOTICE);
300: } else {
301: error_reporting(0);
302: Configure::write('log', LOG_NOTICE);
303: }
304: }
305: }
306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317:
318: function read($var = 'debug') {
319: $_this =& Configure::getInstance();
320:
321: if ($var === 'debug') {
322: if (!isset($_this->debug)) {
323: if (defined('DEBUG')) {
324: $_this->debug = DEBUG;
325: } else {
326: $_this->debug = 0;
327: }
328: }
329: return $_this->debug;
330: }
331: $name = $_this->__configVarNames($var);
332:
333: switch (count($name)) {
334: case 3:
335: if (isset($_this->{$name[0]}[$name[1]][$name[2]])) {
336: return $_this->{$name[0]}[$name[1]][$name[2]];
337: }
338: break;
339: case 2:
340: if (isset($_this->{$name[0]}[$name[1]])) {
341: return $_this->{$name[0]}[$name[1]];
342: }
343: break;
344: case 1:
345: if (isset($_this->{$name[0]})) {
346: return $_this->{$name[0]};
347: }
348: break;
349: }
350: return null;
351: }
352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363:
364: function delete($var = null) {
365: $_this =& Configure::getInstance();
366: $name = $_this->__configVarNames($var);
367:
368: if (isset($name[1])) {
369: unset($_this->{$name[0]}[$name[1]]);
370: } else {
371: unset($_this->{$name[0]});
372: }
373: }
374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387:
388: function load($fileName) {
389: $found = false;
390:
391: if (file_exists(CONFIGS . $fileName . '.php')) {
392: include(CONFIGS . $fileName . '.php');
393: $found = true;
394: } elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) {
395: include(CACHE . 'persistent' . DS . $fileName . '.php');
396: $found = true;
397: } else {
398: foreach (Configure::corePaths('cake') as $key => $path) {
399: if (file_exists($path . DS . 'config' . DS . $fileName . '.php')) {
400: include($path . DS . 'config' . DS . $fileName . '.php');
401: $found = true;
402: break;
403: }
404: }
405: }
406:
407: if (!$found) {
408: return false;
409: }
410:
411: if (!isset($config)) {
412: $error = __("Configure::load() - no variable \$config found in %s.php", true);
413: trigger_error(sprintf($error, $fileName), E_USER_WARNING);
414: return false;
415: }
416: return Configure::write($config);
417: }
418: 419: 420: 421: 422: 423: 424: 425: 426:
427: function version() {
428: $_this =& Configure::getInstance();
429:
430: if (!isset($_this->Cake['version'])) {
431: require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
432: $_this->write($config);
433: }
434: return $_this->Cake['version'];
435: }
436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448:
449: function store($type, $name, $data = array()) {
450: $write = true;
451: $content = '';
452:
453: foreach ($data as $key => $value) {
454: $content .= "\$config['$type']['$key'] = " . var_export($value, true) . ";\n";
455: }
456: if (is_null($type)) {
457: $write = false;
458: }
459: Configure::__writeConfig($content, $name, $write);
460: }
461: 462: 463: 464: 465: 466: 467: 468: 469:
470: function corePaths($type = null) {
471: $paths = Cache::read('core_paths', '_cake_core_');
472: if (!$paths) {
473: $paths = array();
474: $openBasedir = ini_get('open_basedir');
475: if ($openBasedir) {
476: $all = explode(PATH_SEPARATOR, $openBasedir);
477: $all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
478: } else {
479: $all = explode(PATH_SEPARATOR, ini_get('include_path'));
480: $all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
481: }
482: foreach ($all as $path) {
483: if ($path !== DS) {
484: $path = rtrim($path, DS);
485: }
486: if (empty($path) || $path === '.') {
487: continue;
488: }
489: $cake = $path . DS . 'cake' . DS;
490: $libs = $cake . 'libs' . DS;
491: if (is_dir($libs)) {
492: $paths['libs'][] = $libs;
493: $paths['model'][] = $libs . 'model' . DS;
494: $paths['behavior'][] = $libs . 'model' . DS . 'behaviors' . DS;
495: $paths['controller'][] = $libs . 'controller' . DS;
496: $paths['component'][] = $libs . 'controller' . DS . 'components' . DS;
497: $paths['view'][] = $libs . 'view' . DS;
498: $paths['helper'][] = $libs . 'view' . DS . 'helpers' . DS;
499: $paths['cake'][] = $cake;
500: $paths['vendor'][] = $path . DS . 'vendors' . DS;
501: $paths['shell'][] = $cake . 'console' . DS . 'libs' . DS;
502: break;
503: }
504: }
505: Cache::write('core_paths', array_filter($paths), '_cake_core_');
506: }
507: if ($type && isset($paths[$type])) {
508: return $paths[$type];
509: }
510: return $paths;
511: }
512: 513: 514: 515: 516: 517: 518: 519: 520: 521:
522: function __writeConfig($content, $name, $write = true) {
523: $file = CACHE . 'persistent' . DS . $name . '.php';
524:
525: if (Configure::read() > 0) {
526: $expires = "+10 seconds";
527: } else {
528: $expires = "+999 days";
529: }
530: $cache = cache('persistent' . DS . $name . '.php', null, $expires);
531:
532: if ($cache === null) {
533: cache('persistent' . DS . $name . '.php', "<?php\n\$config = array();\n", $expires);
534: }
535:
536: if ($write === true) {
537: if (!class_exists('File')) {
538: require LIBS . 'file.php';
539: }
540: $fileClass = new File($file);
541:
542: if ($fileClass->writable()) {
543: $fileClass->append($content);
544: }
545: }
546: }
547: 548: 549: 550: 551: 552: 553:
554: function __configVarNames($name) {
555: if (is_string($name)) {
556: if (strpos($name, ".")) {
557: return explode(".", $name);
558: }
559: return array($name);
560: }
561: return $name;
562: }
563: 564: 565: 566: 567: 568: 569: 570:
571: function buildPaths($paths) {
572: $_this =& Configure::getInstance();
573: $core = $_this->corePaths();
574: $basePaths = array(
575: 'model' => array(MODELS),
576: 'behavior' => array(BEHAVIORS),
577: 'controller' => array(CONTROLLERS),
578: 'component' => array(COMPONENTS),
579: 'view' => array(VIEWS),
580: 'helper' => array(HELPERS),
581: 'plugin' => array(APP . 'plugins' . DS),
582: 'vendor' => array(APP . 'vendors' . DS, VENDORS),
583: 'locale' => array(APP . 'locale' . DS),
584: 'shell' => array(),
585: 'datasource' => array(MODELS . 'datasources')
586: );
587:
588: foreach ($basePaths as $type => $default) {
589: $pathsVar = $type . 'Paths';
590: $merge = array();
591:
592: if (isset($core[$type])) {
593: $merge = $core[$type];
594: }
595: if ($type === 'model' || $type === 'controller' || $type === 'helper') {
596: $merge = array_merge(array(APP), $merge);
597: }
598:
599: if (!is_array($default)) {
600: $default = array($default);
601: }
602: $_this->{$pathsVar} = $default;
603:
604: if (isset($paths[$pathsVar]) && !empty($paths[$pathsVar])) {
605: $path = array_flip(array_flip((array_merge(
606: $_this->{$pathsVar}, (array)$paths[$pathsVar], $merge
607: ))));
608: $_this->{$pathsVar} = array_values($path);
609: } else {
610: $path = array_flip(array_flip((array_merge($_this->{$pathsVar}, $merge))));
611: $_this->{$pathsVar} = array_values($path);
612: }
613: }
614: }
615: 616: 617: 618: 619: 620: 621: 622: 623:
624: function __loadBootstrap($boot) {
625: $modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = $localePaths = $shellPaths = null;
626:
627: if ($boot) {
628: Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
629:
630: if (!include(CONFIGS . 'core.php')) {
631: 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);
632: }
633:
634: if (Configure::read('Cache.disable') !== true) {
635: $cache = Cache::config('default');
636:
637: if (empty($cache['settings'])) {
638: trigger_error('Cache not configured properly. Please check Cache::config(); in APP/config/core.php', E_USER_WARNING);
639: $cache = Cache::config('default', array('engine' => 'File'));
640: }
641: $path = $prefix = $duration = null;
642:
643: if (!empty($cache['settings']['path'])) {
644: $path = realpath($cache['settings']['path']);
645: } else {
646: $prefix = $cache['settings']['prefix'];
647: }
648:
649: if (Configure::read() >= 1) {
650: $duration = '+10 seconds';
651: } else {
652: $duration = '+999 days';
653: }
654:
655: if (Cache::config('_cake_core_') === false) {
656: Cache::config('_cake_core_', array_merge($cache['settings'], array(
657: 'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
658: 'serialize' => true, 'duration' => $duration
659: )));
660: }
661:
662: if (Cache::config('_cake_model_') === false) {
663: Cache::config('_cake_model_', array_merge($cache['settings'], array(
664: 'prefix' => $prefix . 'cake_model_', 'path' => $path . DS . 'models' . DS,
665: 'serialize' => true, 'duration' => $duration
666: )));
667: }
668: Cache::config('default');
669: }
670:
671: if (!include(CONFIGS . 'bootstrap.php')) {
672: 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);
673: }
674:
675: Configure::buildPaths(compact(
676: 'modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths',
677: 'behaviorPaths', 'pluginPaths', 'vendorPaths', 'localePaths', 'shellPaths'
678: ));
679: }
680: }
681: 682: 683: 684: 685: 686: 687:
688: function __resetCache($reset = null) {
689: static $cache = array();
690: if (!$cache && $reset === true) {
691: $cache = true;
692: }
693: return $cache;
694: }
695: 696: 697: 698: 699:
700: function __destruct() {
701: if ($this->__resetCache() === true) {
702: Cache::write('object_map', array_filter($this->__objects), '_cake_core_');
703: }
704: }
705: }
706: 707: 708: 709: 710: 711: 712: 713:
714: class App extends Object {
715: 716: 717: 718: 719: 720:
721: var $search = array();
722: 723: 724: 725: 726: 727:
728: var $return = false;
729: 730: 731: 732: 733: 734:
735: var $__map = array();
736: 737: 738: 739: 740: 741:
742: var $__paths = array();
743: 744: 745: 746: 747: 748:
749: var $__loaded = array();
750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767:
768: function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
769: $plugin = $directory = null;
770:
771: if (is_array($type)) {
772: extract($type, EXTR_OVERWRITE);
773: }
774:
775: if (is_array($parent)) {
776: extract($parent, EXTR_OVERWRITE);
777: }
778:
779: if ($name === null && $file === null) {
780: $name = $type;
781: $type = 'Core';
782: } elseif ($name === null) {
783: $type = 'File';
784: }
785:
786: if (is_array($name)) {
787: foreach ($name as $class) {
788: $tempType = $type;
789: $plugin = null;
790:
791: if (strpos($class, '.') !== false) {
792: $value = explode('.', $class);
793: $count = count($value);
794:
795: if ($count > 2) {
796: $tempType = $value[0];
797: $plugin = $value[1] . '.';
798: $class = $value[2];
799: } elseif ($count === 2 && ($type === 'Core' || $type === 'File')) {
800: $tempType = $value[0];
801: $class = $value[1];
802: } else {
803: $plugin = $value[0] . '.';
804: $class = $value[1];
805: }
806: }
807:
808: if (!App::import($tempType, $plugin . $class)) {
809: return false;
810: }
811: }
812: return true;
813: }
814:
815: if ($name != null && strpos($name, '.') !== false) {
816: list($plugin, $name) = explode('.', $name);
817: }
818: $_this =& App::getInstance();
819: $_this->return = $return;
820:
821: if (isset($ext)) {
822: $file = Inflector::underscore($name) . ".$ext";
823: }
824: $ext = $_this->__settings($type, $plugin, $parent);
825:
826: if ($name != null && !class_exists($name . $ext['class'])) {
827: if ($load = $_this->__mapped($name . $ext['class'], $type, $plugin)) {
828: if ($_this->__load($load)) {
829: $_this->__overload($type, $name . $ext['class']);
830:
831: if ($_this->return) {
832: $value = include $load;
833: return $value;
834: }
835: return true;
836: } else {
837: $_this->__remove($name . $ext['class'], $type, $plugin);
838: $_this->__resetCache(true);
839: }
840: }
841: if (!empty($search)) {
842: $_this->search = $search;
843: } elseif ($plugin) {
844: $_this->search = $_this->__paths('plugin');
845: } else {
846: $_this->search = $_this->__paths($type);
847: }
848: $find = $file;
849:
850: if ($find === null) {
851: $find = Inflector::underscore($name . $ext['suffix']).'.php';
852:
853: if ($plugin) {
854: $paths = $_this->search;
855: foreach ($paths as $key => $value) {
856: $_this->search[$key] = $value . $ext['path'];
857: }
858: $plugin = Inflector::camelize($plugin);
859: }
860: }
861:
862: if (strtolower($type) !== 'vendor' && empty($search) && $_this->__load($file)) {
863: $directory = false;
864: } else {
865: $file = $find;
866: $directory = $_this->__find($find, true);
867: }
868:
869: if ($directory !== null) {
870: $_this->__resetCache(true);
871: $_this->__map($directory . $file, $name . $ext['class'], $type, $plugin);
872: $_this->__overload($type, $name . $ext['class']);
873:
874: if ($_this->return) {
875: $value = include $directory . $file;
876: return $value;
877: }
878: return true;
879: }
880: return false;
881: }
882: return true;
883: }
884: 885: 886: 887: 888: 889:
890: function &getInstance() {
891: static $instance = array();
892: if (!$instance) {
893: $instance[0] =& new App();
894: $instance[0]->__map = Cache::read('file_map', '_cake_core_');
895: }
896: return $instance[0];
897: }
898: 899: 900: 901: 902: 903: 904: 905:
906: function __find($file, $recursive = true) {
907: if (empty($this->search)) {
908: return null;
909: } elseif (is_string($this->search)) {
910: $this->search = array($this->search);
911: }
912:
913: if (empty($this->__paths)) {
914: $this->__paths = Cache::read('dir_map', '_cake_core_');
915: }
916:
917: foreach ($this->search as $path) {
918: $path = rtrim($path, DS);
919:
920: if ($path === rtrim(APP, DS)) {
921: $recursive = false;
922: }
923: if ($recursive === false) {
924: if ($this->__load($path . DS . $file)) {
925: return $path . DS;
926: }
927: continue;
928: }
929: if (!isset($this->__paths[$path])) {
930: if (!class_exists('Folder')) {
931: require LIBS . 'folder.php';
932: }
933: $Folder =& new Folder();
934: $directories = $Folder->tree($path, false, 'dir');
935: $this->__paths[$path] = $directories;
936: }
937:
938: foreach ($this->__paths[$path] as $directory) {
939: if ($this->__load($directory . DS . $file)) {
940: return $directory . DS;
941: }
942: }
943: }
944: return null;
945: }
946: 947: 948: 949: 950: 951: 952:
953: function __load($file) {
954: if (empty($file)) {
955: return false;
956: }
957: if (!$this->return && isset($this->__loaded[$file])) {
958: return true;
959: }
960: if (file_exists($file)) {
961: if (!$this->return) {
962: require($file);
963: $this->__loaded[$file] = true;
964: }
965: return true;
966: }
967: return false;
968: }
969: 970: 971: 972: 973: 974: 975: 976: 977:
978: function __map($file, $name, $type, $plugin) {
979: if ($plugin) {
980: $plugin = Inflector::camelize($plugin);
981: $this->__map['Plugin'][$plugin][$type][$name] = $file;
982: } else {
983: $this->__map[$type][$name] = $file;
984: }
985: }
986: 987: 988: 989: 990: 991: 992: 993: 994:
995: function __mapped($name, $type, $plugin) {
996: if ($plugin) {
997: $plugin = Inflector::camelize($plugin);
998:
999: if (isset($this->__map['Plugin'][$plugin][$type]) && isset($this->__map['Plugin'][$plugin][$type][$name])) {
1000: return $this->__map['Plugin'][$plugin][$type][$name];
1001: }
1002: return false;
1003: }
1004:
1005: if (isset($this->__map[$type]) && isset($this->__map[$type][$name])) {
1006: return $this->__map[$type][$name];
1007: }
1008: return false;
1009: }
1010: 1011: 1012: 1013: 1014: 1015: 1016:
1017: function __overload($type, $name) {
1018: if (($type === 'Model' || $type === 'Helper') && strtolower($name) != 'schema') {
1019: Overloadable::overload($name);
1020: }
1021: }
1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031:
1032: function __settings($type, $plugin, $parent) {
1033: if (!$parent) {
1034: return null;
1035: }
1036:
1037: if ($plugin) {
1038: $plugin = Inflector::underscore($plugin);
1039: $name = Inflector::camelize($plugin);
1040: }
1041: $path = null;
1042: $load = strtolower($type);
1043:
1044: switch ($load) {
1045: case 'model':
1046: if (!class_exists('Model')) {
1047: App::import('Core', 'Model', false, Configure::corePaths('model'));
1048: }
1049: if (!class_exists('AppModel')) {
1050: App::import($type, 'AppModel', false, Configure::read('modelPaths'));
1051: }
1052: if ($plugin) {
1053: if (!class_exists($name . 'AppModel')) {
1054: App::import($type, $plugin . '.' . $name . 'AppModel', false, array(), $plugin . DS . $plugin . '_app_model.php');
1055: }
1056: $path = $plugin . DS . 'models' . DS;
1057: }
1058: return array('class' => null, 'suffix' => null, 'path' => $path);
1059: break;
1060: case 'behavior':
1061: if ($plugin) {
1062: $path = $plugin . DS . 'models' . DS . 'behaviors' . DS;
1063: }
1064: return array('class' => $type, 'suffix' => null, 'path' => $path);
1065: break;
1066: case 'controller':
1067: App::import($type, 'AppController', false);
1068: if ($plugin) {
1069: App::import($type, $plugin . '.' . $name . 'AppController', false, array(), $plugin . DS . $plugin . '_app_controller.php');
1070: $path = $plugin . DS . 'controllers' . DS;
1071: }
1072: return array('class' => $type, 'suffix' => $type, 'path' => $path);
1073: break;
1074: case 'component':
1075: if ($plugin) {
1076: $path = $plugin . DS . 'controllers' . DS . 'components' . DS;
1077: }
1078: return array('class' => $type, 'suffix' => null, 'path' => $path);
1079: break;
1080: case 'view':
1081: if ($plugin) {
1082: $path = $plugin . DS . 'views' . DS;
1083: }
1084: return array('class' => $type, 'suffix' => null, 'path' => $path);
1085: break;
1086: case 'helper':
1087: if (!class_exists('AppHelper')) {
1088: App::import($type, 'AppHelper', false);
1089: }
1090: if ($plugin) {
1091: $path = $plugin . DS . 'views' . DS . 'helpers' . DS;
1092: }
1093: return array('class' => $type, 'suffix' => null, 'path' => $path);
1094: break;
1095: case 'vendor':
1096: if ($plugin) {
1097: $path = $plugin . DS . 'vendors' . DS;
1098: }
1099: return array('class' => null, 'suffix' => null, 'path' => $path);
1100: break;
1101: default:
1102: $type = $suffix = $path = null;
1103: break;
1104: }
1105: return array('class' => null, 'suffix' => null, 'path' => null);
1106: }
1107: 1108: 1109: 1110: 1111: 1112: 1113:
1114: function __paths($type) {
1115: $type = strtolower($type);
1116:
1117: if ($type === 'core') {
1118: $path = Configure::corePaths();
1119: $paths = array();
1120:
1121: foreach ($path as $key => $value) {
1122: $count = count($key);
1123: for ($i = 0; $i < $count; $i++) {
1124: $paths[] = $path[$key][$i];
1125: }
1126: }
1127: return $paths;
1128: }
1129:
1130: if ($paths = Configure::read($type . 'Paths')) {
1131: return $paths;
1132: }
1133:
1134: switch ($type) {
1135: case 'plugin':
1136: return array(APP . 'plugins' . DS);
1137: case 'vendor':
1138: return array(APP . 'vendors' . DS, VENDORS, APP . 'plugins' . DS);
1139: case 'controller':
1140: return array(APP . 'controllers' . DS, APP);
1141: case 'model':
1142: return array(APP . 'models' . DS, APP);
1143: case 'view':
1144: return array(APP . 'views' . DS);
1145: }
1146: }
1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155:
1156: function __remove($name, $type, $plugin) {
1157: if ($plugin) {
1158: $plugin = Inflector::camelize($plugin);
1159: unset($this->__map['Plugin'][$plugin][$type][$name]);
1160: } else {
1161: unset($this->__map[$type][$name]);
1162: }
1163: }
1164: 1165: 1166: 1167: 1168: 1169: 1170:
1171: function __resetCache($reset = null) {
1172: static $cache = array();
1173: if (!$cache && $reset === true) {
1174: $cache = true;
1175: }
1176: return $cache;
1177: }
1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185:
1186: function __destruct() {
1187: if ($this->__resetCache() === true) {
1188: $core = Configure::corePaths('cake');
1189: unset($this->__paths[rtrim($core[0], DS)]);
1190: Cache::write('dir_map', array_filter($this->__paths), '_cake_core_');
1191: Cache::write('file_map', array_filter($this->__map), '_cake_core_');
1192: }
1193: }
1194: }
1195: ?>