From 1e231e9511144e57322a5d1b7f4f97b0d8f35346 Mon Sep 17 00:00:00 2001 From: gwoo Date: Wed, 11 Jun 2008 15:46:31 +0000 Subject: [PATCH] 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 --- app/webroot/css.php | 2 + cake/bootstrap.php | 2 +- cake/console/libs/tasks/project.php | 4 +- .../libs/templates/skel/webroot/css.php | 2 + cake/libs/cache.php | 9 +++- cake/libs/cache/file.php | 4 +- cake/libs/configure.php | 14 ++++-- cake/libs/controller/components/acl.php | 2 +- cake/libs/controller/components/cookie.php | 7 ++- cake/libs/controller/components/session.php | 4 +- cake/libs/error.php | 24 +++++++--- cake/libs/file.php | 2 +- cake/libs/inflector.php | 12 +++-- cake/libs/magic_db.php | 7 +-- cake/libs/model/behaviors/acl.php | 10 +--- cake/libs/session.php | 8 +++- cake/libs/view/helpers/rss.php | 2 +- cake/libs/view/helpers/session.php | 5 +- cake/libs/view/helpers/text.php | 2 +- cake/tests/cases/libs/view/theme.test.php | 46 +++++++++---------- 20 files changed, 100 insertions(+), 68 deletions(-) diff --git a/app/webroot/css.php b/app/webroot/css.php index 6862b855a..bf382122f 100644 --- a/app/webroot/css.php +++ b/app/webroot/css.php @@ -33,7 +33,9 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) { /** * Enter description here... */ +if (!class_exists('File')) { uses('file'); +} /** * Enter description here... * diff --git a/cake/bootstrap.php b/cake/bootstrap.php index a727b6e7c..0daffe8ec 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -44,7 +44,7 @@ if (!defined('PHP5')) { require LIBS . 'cache.php'; Configure::getInstance(); - + $url = null; App::import('Core', array('Session', 'Security', 'String', 'Dispatcher')); diff --git a/cake/console/libs/tasks/project.php b/cake/console/libs/tasks/project.php index 6d00d9d2e..bfd2bbb61 100644 --- a/cake/console/libs/tasks/project.php +++ b/cake/console/libs/tasks/project.php @@ -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)) { diff --git a/cake/console/libs/templates/skel/webroot/css.php b/cake/console/libs/templates/skel/webroot/css.php index 6862b855a..bf382122f 100644 --- a/cake/console/libs/templates/skel/webroot/css.php +++ b/cake/console/libs/templates/skel/webroot/css.php @@ -33,7 +33,9 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) { /** * Enter description here... */ +if (!class_exists('File')) { uses('file'); +} /** * Enter description here... * diff --git a/cake/libs/cache.php b/cake/libs/cache.php index 7860db657..de4e2c016 100644 --- a/cake/libs/cache.php +++ b/cake/libs/cache.php @@ -118,15 +118,20 @@ 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'); } /** diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index 394be0c73..dfb4136e7 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -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']); diff --git a/cake/libs/configure.php b/cake/libs/configure.php index de5b21027..937b36e8e 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -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()) { diff --git a/cake/libs/controller/components/acl.php b/cake/libs/controller/components/acl.php index c4aaf0181..ae07c62c9 100644 --- a/cake/libs/controller/components/acl.php +++ b/cake/libs/controller/components/acl.php @@ -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')); } diff --git a/cake/libs/controller/components/cookie.php b/cake/libs/controller/components/cookie.php index a0247843e..f7aa4566e 100644 --- a/cake/libs/controller/components/cookie.php +++ b/cake/libs/controller/components/cookie.php @@ -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 diff --git a/cake/libs/controller/components/session.php b/cake/libs/controller/components/session.php index 351baf9a6..bd8536937 100644 --- a/cake/libs/controller/components/session.php +++ b/cake/libs/controller/components/session.php @@ -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. * diff --git a/cake/libs/error.php b/cake/libs/error.php index 2d54a9cf1..9170a06d2 100644 --- a/cake/libs/error.php +++ b/cake/libs/error.php @@ -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") { diff --git a/cake/libs/file.php b/cake/libs/file.php index b6c739a40..b0d50dcb7 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -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. diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 866d5f4cb..f65cc31cb 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -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', diff --git a/cake/libs/magic_db.php b/cake/libs/magic_db.php index 451705107..db687ed35 100644 --- a/cake/libs/magic_db.php +++ b/cake/libs/magic_db.php @@ -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; } diff --git a/cake/libs/model/behaviors/acl.php b/cake/libs/model/behaviors/acl.php index 791541830..b73bc50f0 100644 --- a/cake/libs/model/behaviors/acl.php +++ b/cake/libs/model/behaviors/acl.php @@ -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); } diff --git a/cake/libs/session.php b/cake/libs/session.php index dfb31b641..87bf02c80 100644 --- a/cake/libs/session.php +++ b/cake/libs/session.php @@ -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', ''); diff --git a/cake/libs/view/helpers/rss.php b/cake/libs/view/helpers/rss.php index 91b79e5bd..a8d27c45c 100644 --- a/cake/libs/view/helpers/rss.php +++ b/cake/libs/view/helpers/rss.php @@ -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 { diff --git a/cake/libs/view/helpers/session.php b/cake/libs/view/helpers/session.php index d7c5f1439..1e866def1 100644 --- a/cake/libs/view/helpers/session.php +++ b/cake/libs/view/helpers/session.php @@ -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 diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 52fccc820..7a88c2efe 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -34,7 +34,7 @@ */ if (!class_exists('HtmlHelper')) { - uses('view' . DS . 'helpers' . DS . 'html'); + App::import('Helper', 'Html'); } /** diff --git a/cake/tests/cases/libs/view/theme.test.php b/cake/tests/cases/libs/view/theme.test.php index a12a4376f..fd3a2e740 100644 --- a/cake/tests/cases/libs/view/theme.test.php +++ b/cake/tests/cases/libs/view/theme.test.php @@ -33,21 +33,21 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { } /** * ThemePostsController class - * + * * @package cake * @subpackage cake.tests.cases.libs.view */ class ThemePostsController extends Controller { /** * name property - * + * * @var string 'ThemePosts' * @access public */ var $name = 'ThemePosts'; /** * index method - * + * * @access public * @return void */ @@ -60,14 +60,14 @@ class ThemePostsController extends Controller { } /** * ThemeViewTestErrorHandler class - * + * * @package cake * @subpackage cake.tests.cases.libs.view */ class ThemeViewTestErrorHandler extends ErrorHandler { /** * stop method - * + * * @access public * @return void */ @@ -77,16 +77,16 @@ class ThemeViewTestErrorHandler extends ErrorHandler { } /** * TestThemeView class - * + * * @package cake * @subpackage cake.tests.cases.libs.view */ class TestThemeView extends ThemeView { /** * renderElement method - * - * @param mixed $name - * @param array $params + * + * @param mixed $name + * @param array $params * @access public * @return void */ @@ -95,8 +95,8 @@ class TestThemeView extends ThemeView { } /** * getViewFileName method - * - * @param mixed $name + * + * @param mixed $name * @access public * @return void */ @@ -105,8 +105,8 @@ class TestThemeView extends ThemeView { } /** * getLayoutFileName method - * - * @param mixed $name + * + * @param mixed $name * @access public * @return void */ @@ -115,14 +115,14 @@ class TestThemeView extends ThemeView { } /** * cakeError method - * - * @param mixed $method - * @param mixed $messages + * + * @param mixed $method + * @param mixed $messages * @access public * @return void */ function cakeError($method, $messages) { - $error =& new ViewTestErrorHandler($method, $messages); + $error =& new ThemeViewTestErrorHandler($method, $messages); return $error; } } @@ -136,7 +136,7 @@ class TestThemeView extends ThemeView { class ThemeViewTest extends UnitTestCase { /** * setUp method - * + * * @access public * @return void */ @@ -150,7 +150,7 @@ class ThemeViewTest extends UnitTestCase { } /** * testPluginGetTemplate method - * + * * @access public * @return void */ @@ -175,7 +175,7 @@ class ThemeViewTest extends UnitTestCase { } /** * testGetTemplate method - * + * * @access public * @return void */ @@ -216,7 +216,7 @@ class ThemeViewTest extends UnitTestCase { } /** * testMissingView method - * + * * @access public * @return void */ @@ -240,7 +240,7 @@ class ThemeViewTest extends UnitTestCase { } /** * testMissingLayout method - * + * * @access public * @return void */ @@ -262,7 +262,7 @@ class ThemeViewTest extends UnitTestCase { } /** * tearDown method - * + * * @access public * @return void */