Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replacing some of the App::import by App::uses
  • Loading branch information
lorenzo committed Dec 9, 2010
1 parent 848461f commit b8344ec
Show file tree
Hide file tree
Showing 43 changed files with 131 additions and 151 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Console/Command/AclShell.php
Expand Up @@ -17,8 +17,8 @@
* @since CakePHP(tm) v 1.2.0.5012
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Component', 'Acl');
App::import('Model', 'DbAcl');
App::uses('AclComponent', 'Controller/Component');
App::uses('DbAcl', 'Model');

/**
* Shell for ACL management. This console is known to have issues with zend.ze1_compatibility_mode
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/ApiShell.php
Expand Up @@ -19,7 +19,7 @@
* @since CakePHP(tm) v 1.2.0.5012
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'File');
App::uses('File', 'Utility');

/**
* API shell to show method signatures of CakePHP core classes.
Expand Down
9 changes: 6 additions & 3 deletions lib/Cake/Console/Command/BakeShell.php
Expand Up @@ -22,6 +22,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('Model', 'Model');

/**
* Bake is a command-line code generation utility for automating programmer chores.
*
Expand Down Expand Up @@ -151,11 +153,11 @@ public function all() {

$modelExists = false;
$model = $this->_modelName($name);
if (App::import('Model', $model)) {
App::uses($model, 'Model');
if (class_exists($model)) {
$object = new $model();
$modelExists = true;
} else {
App::import('Model', 'Model', false);
$object = new Model(array('name' => $name, 'ds' => $this->connection));
}

Expand All @@ -176,7 +178,8 @@ public function all() {
$this->Controller->bakeTest($controller);
}
}
if (App::import('Controller', $controller)) {
App::uses($controller . 'Controller', 'Controller')
if (class_exists($controller . 'Controller')) {
$this->View->args = array($controller);
$this->View->execute();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/ConsoleShell.php
Expand Up @@ -56,11 +56,11 @@ public function initialize() {
App::uses('Dispatcher', 'Routing');
$this->Dispatcher = new Dispatcher();
$this->models = App::objects('model');
App::import('Model', $this->models);

foreach ($this->models as $model) {
$class = Inflector::camelize(str_replace('.php', '', $model));
$this->models[$model] = $class;
App::uses($class, 'Model');
$this->{$class} = new $class();
}
$this->out('Model classes:');
Expand Down
6 changes: 4 additions & 2 deletions lib/Cake/Console/Command/Task/ControllerTask.php
Expand Up @@ -108,7 +108,8 @@ public function all() {
foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$controller = $this->_controllerName($model);
if (App::import('Model', $model)) {
App::uses($model, 'Model');
if (!class_exists($model)) {
$actions = $this->bakeActions($controller);
if ($this->bake($controller, $actions) && $unitTestExists) {
$this->bakeTest($controller);
Expand Down Expand Up @@ -273,7 +274,8 @@ public function bakeActions($controllerName, $admin = null, $wannaUseSession = t
if ($plugin) {
$modelImport = $plugin . '.' . $modelImport;
}
if (!App::import('Model', $modelImport)) {
App::uses($modelImport, 'Model');
if (!class_exists($modelImport)) {
$this->err(__('You must have a model for this class to build basic methods. Please try again.'));
$this->_stop();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/DbConfigTask.php
Expand Up @@ -353,7 +353,7 @@ public function bake($configs) {
* @return void
*/
public function getConfig() {
App::import('Model', 'ConnectionManager', false);
App::uses('ConnectionManager', 'Model');

$useDbConfig = 'default';
$configs = get_class_vars($this->databaseClassName);
Expand Down
6 changes: 2 additions & 4 deletions lib/Cake/Console/Command/Task/FixtureTask.php
Expand Up @@ -19,6 +19,7 @@
*/

App::uses('BakeTask', 'Console/Command/Task');
App::uses('Model', 'Model');

/**
* Task class for creating and updating fixtures files.
Expand Down Expand Up @@ -186,9 +187,7 @@ public function importOptions($modelName) {
* @return string Baked fixture content
*/
public function bake($model, $useTable = false, $importOptions = array()) {
if (!class_exists('CakeSchema')) {
App::import('Model', 'CakeSchema', false);
}
App::uses('CakeSchema', 'Model');
$table = $schema = $records = $import = $modelImport = $recordImport = null;
if (!$useTable) {
$useTable = Inflector::tableize($model);
Expand Down Expand Up @@ -394,7 +393,6 @@ protected function _getRecordsFromTable($modelName, $useTable = null) {
} else {
$condition = 'WHERE 1=1 LIMIT ' . (isset($this->params['count']) ? $this->params['count'] : 10);
}
App::import('Model', 'Model', false);
$modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
$records = $modelObject->find('all', array(
'conditions' => $condition,
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/ModelTask.php
Expand Up @@ -20,6 +20,7 @@

App::uses('BakeTask', 'Console/Command/Task');
App::uses('ConnectionManager', 'Model');
App::uses('Model', 'Model');

/**
* Task class for creating and updating model files.
Expand Down Expand Up @@ -74,7 +75,6 @@ class ModelTask extends BakeTask {
*
*/
public function execute() {
App::import('Model', 'Model', false);
parent::execute();

if (empty($this->args)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Console/Command/Task/PluginTask.php
Expand Up @@ -17,7 +17,8 @@
* @since CakePHP(tm) v 1.2
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'File');

App::uses('File', 'Utility');

/**
* Task class for creating a plugin
Expand Down
14 changes: 8 additions & 6 deletions lib/Cake/Console/Command/Task/ViewTask.php
Expand Up @@ -191,7 +191,8 @@ public function all() {
$model = $this->_modelName($table);
$this->controllerName = $this->_controllerName($model);
$this->controllerPath = Inflector::underscore($this->controllerName);
if (App::import('Model', $model)) {
App::uses($model, 'Model');
if (class_exists($model)) {
$vars = $this->__loadController();
if (!$actions) {
$actions = $this->_methodsToBake();
Expand Down Expand Up @@ -272,17 +273,18 @@ private function __loadController() {
$this->err(__('Controller not found'));
}

$import = $this->controllerName;
$plugin = null;
if ($this->plugin) {
$import = $this->plugin . '.' . $this->controllerName;
$plugin = $this->plugin . '.';
}

if (!App::import('Controller', $import)) {
$file = $this->controllerPath . '_controller.php';
$controllerClassName = $this->controllerName . 'Controller';
App::uses($controllerName, $plugin . 'Controller');
if (!class_exists($controllerClassName)) {
$file = $controllerClassName . '.php';
$this->err(__("The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", $file));
$this->_stop();
}
$controllerClassName = $this->controllerName . 'Controller';
$controllerObj = new $controllerClassName();
$controllerObj->plugin = $this->plugin;
$controllerObj->constructClasses();
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/ConsoleErrorHandler.php
Expand Up @@ -19,6 +19,7 @@
*/
App::uses('ErrorHandler', 'Error');
App::uses('ConsoleOutput', 'Console');
App::uses('CakeLog', 'Log');

/**
* Error Handler for Cake console. Does simple printing of the
Expand Down Expand Up @@ -79,7 +80,6 @@ public static function handleError($code, $description, $file = null, $line = nu
$stderr->write(__("<error>%s Error:</error> %s\n", $name, $message));

if (Configure::read('debug') == 0) {
App::import('Core', 'CakeLog');
CakeLog::write($log, $message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/AclComponent.php
Expand Up @@ -662,7 +662,7 @@ public function check($aro, $aco, $aco_action = null) {
* @return array INI section structure
*/
public function readConfigFile($filename) {
App::import('Core', 'config/IniReader');
App::uses('IniReader', 'Configure');
$iniFile = new IniReader(dirname($filename) . DS);
return $iniFile->read(basename($filename));
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Controller/Component/EmailComponent.php
Expand Up @@ -433,9 +433,9 @@ function _render($content) {
$viewClass = $this->Controller->view;

if ($viewClass != 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass);
list($plugin, $viewClass) = pluginSplit($viewClass, true);
$viewClass = $viewClass . 'View';
App::import('View', $this->Controller->view);
App::uses($viewClass, $plugin . 'View');
}

$View = new $viewClass($this->Controller, false);
Expand Down Expand Up @@ -810,7 +810,7 @@ function _mail() {
* @access private
*/
function _smtp() {
App::import('Core', 'CakeSocket');
App::uses('CakeSocket', 'Network');

$defaults = array(
'host' => 'localhost',
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -542,7 +542,8 @@ public function renderAs(&$controller, $type, $options = array()) {
);

if (!$isAdded) {
if (App::import('Helper', $helper)) {
App::uses($helper . 'Helper', 'Helper');
if (class_exists($helper . 'Helper')) {
$controller->helpers[] = $helper;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -789,9 +789,9 @@ public function render($action = null, $layout = null, $file = null) {

$viewClass = $this->view;
if ($this->view != 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass);
list($plugin, $viewClass) = pluginSplit($viewClass, true);
$viewClass = $viewClass . 'View';
App::import('View', $this->view);
App::uses($viewClass, $plugin . 'View');
}

$this->request->params['models'] = $this->modelNames;
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Core/App.php
Expand Up @@ -23,8 +23,8 @@
* ### Adding paths
*
* You can add paths to the search indexes App uses to find classes using `App::build()`. Adding
* additional controller paths for example would alter where CakePHP looks for controllers when you
* call App::import('Controller', 'Posts'); This allows you to split your application up across the filesystem.
* additional controller paths for example would alter where CakePHP looks for controllers.
* This allows you to split your application up across the filesystem.
*
* ### Inspecting loaded paths
*
Expand Down Expand Up @@ -261,7 +261,7 @@ public static function build($paths = array(), $reset = false) {
'View' => array(VIEWS),
'View/Helper' => array(HELPERS),
'locales' => array(APP . 'locale' . DS),
'shells' => array(
'Console' => array(
APP . 'console' . DS . 'shells' . DS,
APP . 'vendors' . DS . 'shells' . DS,
VENDORS . 'shells' . DS
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Error/ErrorHandler.php
Expand Up @@ -113,7 +113,7 @@ public static function handleException(Exception $exception) {
CakeLog::write(LOG_ERR, '[' . get_class($exception) . '] ' . $exception->getMessage());
}
if ($config['renderer'] !== 'ExceptionRenderer') {
App::import('Lib', $config['renderer']);
App::uses($config['renderer'], 'Error');
}
$error = new $config['renderer']($exception);
$error->render();
Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/Error/ExceptionRenderer.php
Expand Up @@ -20,6 +20,9 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::import('Sanitize', 'Utility');

/**
* Exception Renderer.
*
Expand Down Expand Up @@ -88,8 +91,6 @@ class ExceptionRenderer {
* @param array $messages Error messages
*/
function __construct(Exception $exception) {
App::import('Core', 'Sanitize');

$this->controller = $this->_getController($exception);

if (method_exists($this->controller, 'apperror')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/I18n.php
Expand Up @@ -101,7 +101,7 @@ public static function &getInstance() {

/**
* Used by the translation functions in basics.php
* Can also be used like I18n::translate(); but only if the App::import('I18n'); has been used to load the class.
* Returns a translated string based on current language and translation files stored in locale folder
*
* @param string $singular String to translate
* @param string $plural Plural string (if any)
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/Multibyte.php
Expand Up @@ -1078,7 +1078,7 @@ private static function __find($char, $type = 'lower') {
return null;
}
if (!Configure::configured('_cake_core_')) {
App::import('Core', 'config/PhpReader');
App::uses('PhpReader', 'Configure');
Configure::config('_cake_core_', new PhpReader(CAKE . 'config' . DS));
}
Configure::load('unicode' . DS . 'casefolding' . DS . $range, '_cake_core_');
Expand Down
7 changes: 1 addition & 6 deletions lib/Cake/Model/BehaviorCollection.php
Expand Up @@ -94,12 +94,7 @@ public function load($behavior, $config = array()) {
list($plugin, $name) = pluginSplit($behavior);
$class = $name . 'Behavior';

if (!App::import('Behavior', $behavior)) {
throw new MissingBehaviorFileException(array(
'file' => Inflector::underscore($behavior) . '.php',
'class' => $class
));
}
App::uses($class, 'Model/Behavior');
if (!class_exists($class)) {
throw new MissingBehaviorClassException(array(
'file' => Inflector::underscore($behavior) . '.php',
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Model/CakeSchema.php
Expand Up @@ -207,9 +207,8 @@ public function read($options = array()) {
));
$db = ConnectionManager::getDataSource($connection);

App::import('Model', 'AppModel');
if (isset($this->plugin)) {
App::import('Model', Inflector::camelize($this->plugin) . 'AppModel');
App::uses(Inflector::camelize($this->plugin) . 'AppModel', $this->plugin . '.Model');
}

$tables = array();
Expand All @@ -234,7 +233,8 @@ public function read($options = array()) {
if (isset($this->plugin)) {
$importModel = $this->plugin . '.' . $model;
}
if (!App::import('Model', $importModel)) {
App::uses($importModel, 'Model');
if (!class_exists($importModel)) {
continue;
}
$vars = get_class_vars($model);
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -17,7 +17,9 @@
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('String', 'Utility');
App::uses('View', 'View');

/**
* DboSource
Expand Down Expand Up @@ -763,7 +765,6 @@ public function showLog($sorted = false) {
return;
}
if (PHP_SAPI != 'cli') {
App::import('Core', 'View');
$controller = null;
$View = new View($controller, false);
$View->set('logs', array($this->configKeyName => $log));
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Set.php
Expand Up @@ -585,7 +585,7 @@ public static function classicExtract($data, $path = null) {

if (is_string($path) && strpos($path, '{') !== false) {
$path = String::tokenize($path, '.', '{', '}');
} else {
} elseif (is_string($path)) {
$path = explode('.', $path);
}
$tmp = array();
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/pages/home.ctp
Expand Up @@ -24,7 +24,7 @@ endif;
<a href="http://cakephp.org/changelogs/1.3.6"><?php __('Read the changelog'); ?> </a>
<?php
if (Configure::read('debug') > 0):
Debugger::checkSecurityKeys();
//Debugger::checkSecurityKeys();
endif;
?>
<p>
Expand Down
4 changes: 1 addition & 3 deletions lib/Cake/basics.php
Expand Up @@ -670,9 +670,7 @@ function __c($msg, $category, $args = null) {
* @param string $message Message to write to log
*/
function LogError($message) {
if (!class_exists('CakeLog')) {
App::import('Core', 'CakeLog');
}
App::uses('CakeLog', 'Log');
$bad = array("\n", "\r", "\t");
$good = ' ';
CakeLog::write('error', str_replace($bad, $good, $message));
Expand Down

0 comments on commit b8344ec

Please sign in to comment.