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...
*/
if (!class_exists('File')) {
uses('file');
}
/**
* Enter description here...
*

View file

@ -194,7 +194,9 @@ class ProjectTask extends Shell {
$File =& new File($path . 'config' . DS . 'core.php');
$contents = $File->read();
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();
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents);
if ($File->write($result)) {

View file

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

View file

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

View file

@ -79,7 +79,9 @@ class FileEngine extends CacheEngine {
function init($settings = array()) {
parent::init(array_merge(array('engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> false, 'serialize'=> true), $settings));
if(!isset($this->__File)) {
uses('file');
if (!class_exists('File')) {
uses('file');
}
$this->__File =& new File($this->settings['path'] . DS . 'cake');
}
$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
*/
function __list($path, $suffix = false, $extension = false) {
uses('folder');
if (!class_exists('Folder')) {
uses('folder');
}
$items = array();
$Folder =& new Folder($path);
$contents = $Folder->read(false, true);
@ -274,9 +276,11 @@ class Configure extends Object {
}
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);
} else {
error_reporting(0);
@ -538,7 +542,9 @@ class Configure extends Object {
}
if ($write === true) {
uses('file');
if (!class_exists('File')) {
uses('file');
}
$fileClass = new File($file);
if ($fileClass->writable()) {

View file

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

View file

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

View file

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

View file

@ -26,6 +26,22 @@
* @lastmodified $Date$
* @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.
*
@ -50,15 +66,9 @@ class ErrorHandler extends Object {
* @param array $messages Error messages
*/
function __construct($method, $messages) {
App::import('Controller', 'App');
App::import('Core', 'Sanitize');
$this->controller =& new AppController();
$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'));
$this->controller =& new CakeErrorController();
$allow = array('.', '/', '_', ' ', '-', '~');
if (substr(PHP_OS, 0, 3) == "WIN") {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -34,7 +34,7 @@
*/
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
*/
function cakeError($method, $messages) {
$error =& new ViewTestErrorHandler($method, $messages);
$error =& new ThemeViewTestErrorHandler($method, $messages);
return $error;
}
}