mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
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
This commit is contained in:
parent
246028e89f
commit
e64de54a51
3 changed files with 69 additions and 5 deletions
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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', "<?php\n");
|
||||
}
|
||||
if($write === true){
|
||||
if(!class_exists('File')){
|
||||
uses('File');
|
||||
}
|
||||
$fileClass = new File($file);
|
||||
$fileClass->append($content);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks $name for dot notation to create dynamic Configure::$var as an array when needed.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue