some cleanup, wrapping uses() in class exists

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7172 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-11 15:46:31 +00:00
parent 273dff46f1
commit 1e231e9511
20 changed files with 100 additions and 68 deletions

View file

@ -33,7 +33,9 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
/** /**
* Enter description here... * Enter description here...
*/ */
if (!class_exists('File')) {
uses('file'); uses('file');
}
/** /**
* Enter description here... * Enter description here...
* *

View file

@ -194,7 +194,9 @@ class ProjectTask extends Shell {
$File =& new File($path . 'config' . DS . 'core.php'); $File =& new File($path . 'config' . DS . 'core.php');
$contents = $File->read(); $contents = $File->read();
if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.salt\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.salt\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
uses('Security'); if (!class_exists('Security')) {
uses('Security');
}
$string = Security::generateAuthKey(); $string = Security::generateAuthKey();
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents); $result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents);
if ($File->write($result)) { if ($File->write($result)) {

View file

@ -33,7 +33,9 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
/** /**
* Enter description here... * Enter description here...
*/ */
if (!class_exists('File')) {
uses('file'); uses('file');
}
/** /**
* Enter description here... * Enter description here...
* *

View file

@ -120,13 +120,18 @@ class Cache extends Object {
$engine = $settings['engine']; $engine = $settings['engine'];
if ($name !== $_this->__name) { if ($name !== $_this->__name) {
//pr('n' . $name);
//pr('name' . $_this->__name);
if ($_this->engine($engine, $settings) === false) { if ($_this->engine($engine, $settings) === false) {
return false; return false;
} }
$_this->__name = $name; $_this->__name = $name;
}
}
$settings = $_this->__config[$name] = $_this->settings($engine); $settings = $_this->__config[$name] = $_this->settings($engine);
//pr($_this->__config);
return compact('engine', 'settings'); return compact('engine', 'settings');
} }
/** /**

View file

@ -79,7 +79,9 @@ class FileEngine extends CacheEngine {
function init($settings = array()) { function init($settings = array()) {
parent::init(array_merge(array('engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> false, 'serialize'=> true), $settings)); parent::init(array_merge(array('engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> false, 'serialize'=> true), $settings));
if(!isset($this->__File)) { if(!isset($this->__File)) {
uses('file'); if (!class_exists('File')) {
uses('file');
}
$this->__File =& new File($this->settings['path'] . DS . 'cake'); $this->__File =& new File($this->settings['path'] . DS . 'cake');
} }
$this->settings['path'] = $this->__File->Folder->cd($this->settings['path']); $this->settings['path'] = $this->__File->Folder->cd($this->settings['path']);

View file

@ -207,7 +207,9 @@ class Configure extends Object {
* @return array List of directories or files in directory * @return array List of directories or files in directory
*/ */
function __list($path, $suffix = false, $extension = false) { function __list($path, $suffix = false, $extension = false) {
uses('folder'); if (!class_exists('Folder')) {
uses('folder');
}
$items = array(); $items = array();
$Folder =& new Folder($path); $Folder =& new Folder($path);
$contents = $Folder->read(false, true); $contents = $Folder->read(false, true);
@ -274,9 +276,11 @@ class Configure extends Object {
} }
if (!class_exists('Debugger')) { if (!class_exists('Debugger')) {
require LIBS . 'debugger.php'; uses('debugger');
}
if (!class_exists('CakeLog')) {
uses('cake_log');
} }
uses('cake_log');
Configure::write('log', LOG_NOTICE); Configure::write('log', LOG_NOTICE);
} else { } else {
error_reporting(0); error_reporting(0);
@ -538,7 +542,9 @@ class Configure extends Object {
} }
if ($write === true) { if ($write === true) {
uses('file'); if (!class_exists('File')) {
uses('file');
}
$fileClass = new File($file); $fileClass = new File($file);
if ($fileClass->writable()) { if ($fileClass->writable()) {

View file

@ -244,7 +244,7 @@ class DbAcl extends AclBase {
*/ */
function __construct() { function __construct() {
parent::__construct(); parent::__construct();
uses('model' . DS . 'db_acl'); App::import('Model', 'DbAcl');
$this->Aro =& ClassRegistry::init(array('class' => 'Aro', 'alias' => 'Aro')); $this->Aro =& ClassRegistry::init(array('class' => 'Aro', 'alias' => 'Aro'));
$this->Aco =& ClassRegistry::init(array('class' => 'Aco', 'alias' => 'Aco')); $this->Aco =& ClassRegistry::init(array('class' => 'Aco', 'alias' => 'Aco'));
} }

View file

@ -29,9 +29,7 @@
/** /**
* Load Security class * Load Security class
*/ */
if (!class_exists('Security')) { App::import('Core', 'Security');
uses('Security');
}
/** /**
* Cookie Component. * Cookie Component.
* *
@ -160,8 +158,9 @@ class CookieComponent extends Object {
* @param object $controller A reference to the instantiating controller object * @param object $controller A reference to the instantiating controller object
* @access public * @access public
*/ */
function initialize(&$controller) { function initialize(&$controller, $settings) {
$this->key = Configure::read('Security.salt'); $this->key = Configure::read('Security.salt');
$this->_set($settings);
} }
/** /**
* Start CookieComponent for use in the controller * Start CookieComponent for use in the controller

View file

@ -26,7 +26,9 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
uses('session'); if (!class_exists('cakesession')) {
uses('session');
}
/** /**
* Session Component. * Session Component.
* *

View file

@ -26,6 +26,22 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
App::import('Controller', 'App');
class CakeErrorController extends AppController {
var $name = 'CakeError';
var $uses = array();
function __construct() {
parent::__construct();
$this->_set(Router::getPaths());
$this->params = Router::getParams();
$this->constructClasses();
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
}
}
/** /**
* Short description for file. * Short description for file.
* *
@ -50,15 +66,9 @@ class ErrorHandler extends Object {
* @param array $messages Error messages * @param array $messages Error messages
*/ */
function __construct($method, $messages) { function __construct($method, $messages) {
App::import('Controller', 'App');
App::import('Core', 'Sanitize'); App::import('Core', 'Sanitize');
$this->controller =& new AppController(); $this->controller =& new CakeErrorController();
$this->controller->_set(Router::getPaths());
$this->controller->params = Router::getParams();
$this->controller->constructClasses();
$this->controller->Component->initialize($this->controller);
$this->controller->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
$allow = array('.', '/', '_', ' ', '-', '~'); $allow = array('.', '/', '_', ' ', '-', '~');
if (substr(PHP_OS, 0, 3) == "WIN") { if (substr(PHP_OS, 0, 3) == "WIN") {

View file

@ -33,7 +33,7 @@ if (!class_exists('Object')) {
} }
if (!class_exists('Folder')) { if (!class_exists('Folder')) {
uses ('folder'); uses('folder');
} }
/** /**
* Convenience class for reading, writing and appending to files. * Convenience class for reading, writing and appending to files.

View file

@ -30,10 +30,12 @@
* Included libraries. * Included libraries.
* *
*/ */
if (!class_exists('Object')) { if (!class_exists('Object')) {
uses('object'); uses('object');
} }
uses('Set'); if (!class_exists('Set')) {
uses('set');
}
/** /**
* Pluralize and singularize English words. * Pluralize and singularize English words.
* *
@ -422,7 +424,7 @@ class Inflector extends Object {
*/ */
function slug($string, $replacement = '_') { function slug($string, $replacement = '_') {
if(!class_exists('String')) { if(!class_exists('String')) {
App::import('Core', 'String'); require_once LIBS . 'string.php';
} }
$map = array( $map = array(
'/à|á|å|â/' => 'a', '/à|á|å|â/' => 'a',

View file

@ -24,8 +24,9 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
if (!class_exists('File')) {
uses ('object', 'file'); uses ('object', 'file');
}
/** /**
* A class to parse and use the MagicDb for file type analysis * A class to parse and use the MagicDb for file type analysis
* *
@ -110,7 +111,7 @@ class MagicDb extends Object {
$format = array(); $format = array();
while (!empty($lines)) { while (!empty($lines)) {
$line = array_shift($lines); $line = array_shift($lines);
if ($line[0] == '#' || empty($line)) { if (isset($line[0]) && $line[0] == '#' || empty($line)) {
continue; continue;
} }

View file

@ -54,14 +54,8 @@ class AclBehavior extends ModelBehavior {
} }
$this->settings[$model->alias] = array_merge(array('type' => 'requester'), (array)$config); $this->settings[$model->alias] = array_merge(array('type' => 'requester'), (array)$config);
$type = $this->__typeMaps[$this->settings[$model->alias]['type']]; $type = $this->__typeMaps[$this->settings[$model->alias]['type']];
App::import('Model', 'DbAcl');
if (!ClassRegistry::isKeySet($type)) { $model->{$type} =& ClassRegistry::init($type);;
uses('model' . DS . 'db_acl');
$object =& new $type();
} else {
$object =& ClassRegistry::getObject($type);
}
$model->{$type} =& $object;
if (!method_exists($model, 'parentNode')) { if (!method_exists($model, 'parentNode')) {
trigger_error("Callback parentNode() not defined in {$model->alias}", E_USER_WARNING); trigger_error("Callback parentNode() not defined in {$model->alias}", E_USER_WARNING);
} }

View file

@ -33,7 +33,9 @@
* Database name for cake sessions. * Database name for cake sessions.
* *
*/ */
App::import('Core', 'Set'); if (!class_exists('Set')) {
uses('set');
}
/** /**
* Session class for Cake. * Session class for Cake.
* *
@ -486,7 +488,9 @@ class CakeSession extends Object {
break; break;
case 'cache': case 'cache':
if (!isset($_SESSION)) { if (!isset($_SESSION)) {
uses('Cache'); if (!class_exists('Cache')) {
uses('Cache');
}
if (function_exists('ini_set')) { if (function_exists('ini_set')) {
ini_set('session.use_trans_sid', 0); ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', ''); ini_set('url_rewriter.tags', '');

View file

@ -32,7 +32,7 @@
* @package cake * @package cake
* @subpackage cake.cake.libs.view.helpers * @subpackage cake.cake.libs.view.helpers
*/ */
uses('view' . DS . 'helpers' . DS . 'xml'); App::import('Helper', 'Xml');
class RssHelper extends XmlHelper { class RssHelper extends XmlHelper {

View file

@ -35,9 +35,10 @@
* @subpackage cake.cake.libs.view.helpers * @subpackage cake.cake.libs.view.helpers
* *
*/ */
if(!class_exists('cakesession')) { if (!class_exists('cakesession')) {
App::import('Core', 'Session'); uses('session');
} }
class SessionHelper extends CakeSession { class SessionHelper extends CakeSession {
/** /**
* List of helpers used by this helper * List of helpers used by this helper

View file

@ -34,7 +34,7 @@
*/ */
if (!class_exists('HtmlHelper')) { if (!class_exists('HtmlHelper')) {
uses('view' . DS . 'helpers' . DS . 'html'); App::import('Helper', 'Html');
} }
/** /**

View file

@ -122,7 +122,7 @@ class TestThemeView extends ThemeView {
* @return void * @return void
*/ */
function cakeError($method, $messages) { function cakeError($method, $messages) {
$error =& new ViewTestErrorHandler($method, $messages); $error =& new ThemeViewTestErrorHandler($method, $messages);
return $error; return $error;
} }
} }