diff --git a/cake/basics.php b/cake/basics.php index 1c2f399b3..e5f00d317 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -154,10 +154,19 @@ if (!is_null($name) && !class_exists($name)) { $className = $name; $name = Inflector::underscore($name); - $paths = Configure::getInstance(); + $models = Configure::read('Models'); + if(is_array($models)) { + if(array_key_exists($className, $models)) { + require($models[$className]['path'] . $name . '.php'); + Overloadable::overload($className); + return true; + } + } + $paths = Configure::getInstance(); foreach($paths->modelPaths as $path) { if (file_exists($path . $name . '.php')) { + Configure::store('Models', 'class.paths', array($className => array('path' => $path))); require($path . $name . '.php'); Overloadable::overload($className); return true; diff --git a/cake/bootstrap.php b/cake/bootstrap.php index a19524964..85e3cb229 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -44,6 +44,8 @@ if (!defined('PHP5')) { require LIBS . 'inflector.php'; require LIBS . 'configure.php'; $paths = Configure::getInstance(); + Configure::store(null, 'class.paths'); + Configure::load('class.paths'); /** * Enter description here... */ @@ -93,7 +95,7 @@ if (!defined('PHP5')) { } } - Configure::write('debug', DEBUG); + Configure::write('debug', DEBUG); require CAKE . 'dispatcher.php'; diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 5e83927d2..e354a86d8 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -209,19 +209,21 @@ class Configure extends Object { function load($fileName) { $_this =& Configure::getInstance(); - if(!file_exists(CONFIGS . $fileName . '.php')) { + if (file_exists(CONFIGS . $fileName . '.php')) { + include(CONFIGS . $fileName . '.php'); + } elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) { + include(CACHE . 'persistent' . DS . $fileName . '.php'); + } else { trigger_error(sprintf(__("Configure::load() - %s.php not found", true), $fileName), E_USER_WARNING); return false; } - include(CONFIGS . $fileName . '.php'); if(!isset($config)){ trigger_error(sprintf(__("Configure::load() - no variable \$config found in %s.php", true), $fileName), E_USER_WARNING); return false; } return $_this->write($config); } - /** * Used to determine the current version of CakePHP * @@ -238,6 +240,57 @@ class Configure extends Object { } return $_this->Cake['version']; } +/** + * Used to write a config file to the server. + * + * Configure::store('Model', 'class.paths', array('Users' => array('path' => 'users', 'plugin' => true))); + * + * @param string $type Type of config file to write, ex: Models, Controllers, Helpers, Components + * @param string $name file name. + * @param array $data array of values to store. + * @access public + */ + function store($type, $name, $data = array()) { + $_this =& Configure::getInstance(); + $write = true; + $content = ''; + foreach ($data as $key => $value) { + $content .= "\$config['$type']['$key'] = array("; + if(is_array($value)){ + foreach($value as $key1 => $value2){ + $content .= "'$key1' => '$value2', "; + } + } else { + $content .= "'$key' => '$value'"; + } + $content .= ");\n"; + } + if(is_null($type)) { + $write = false; + } + $_this->__writeConfig($content, $name, $write); + } +/** + * Creates a cached version of a configuration file. + * Appends values passed from Configure::store() to the cached file + * + * @param string $content + * @param string $name + * @access private + */ + function __writeConfig($content, $name, $write = true){ + $file = CACHE . 'persistent' . DS . $name . '.php'; + if(!file_exists($file)){ + cache('persistent' . DS . $name . '.php', "append($content); + } + } /** * Checks $name for dot notation to create dynamic Configure::$var as an array when needed. *