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