From e64de54a5192018c301ed01ca802b8fdca4c2b7f Mon Sep 17 00:00:00 2001 From: phpnut Date: Tue, 9 Jan 2007 22:32:48 +0000 Subject: [PATCH] Adding new methods to Configure class that is used to created a cached version of config files. Adding Configure::store() method call to bootstrap.php to create a cached file for class paths. Adding Configure::read() to load class paths into Configure instance. Adding check in loadModel() to get the class path from Configure::read('Models'); if set, if values are not set, the correct file is found and added to the cache file for faster loading. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4274 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 11 +++++++- cake/bootstrap.php | 4 ++- cake/libs/configure.php | 59 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 5 deletions(-) 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. *