Replacing some of the App::import by App::uses

This commit is contained in:
José Lorenzo Rodríguez 2010-12-08 23:15:18 -04:30
parent 848461f7a0
commit b8344ecd33
43 changed files with 127 additions and 147 deletions

View file

@ -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

View file

@ -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.

View file

@ -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.
*
@ -151,11 +153,11 @@ class BakeShell extends Shell {
$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));
}
@ -176,7 +178,8 @@ class BakeShell extends Shell {
$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();
}

View file

@ -56,11 +56,11 @@ class ConsoleShell extends Shell {
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:');

View file

@ -108,7 +108,8 @@ class ControllerTask extends BakeTask {
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);
@ -273,7 +274,8 @@ class ControllerTask extends BakeTask {
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();
}

View file

@ -353,7 +353,7 @@ class DbConfigTask extends Shell {
* @return void
*/
public function getConfig() {
App::import('Model', 'ConnectionManager', false);
App::uses('ConnectionManager', 'Model');
$useDbConfig = 'default';
$configs = get_class_vars($this->databaseClassName);

View file

@ -19,6 +19,7 @@
*/
App::uses('BakeTask', 'Console/Command/Task');
App::uses('Model', 'Model');
/**
* Task class for creating and updating fixtures files.
@ -186,9 +187,7 @@ class FixtureTask extends BakeTask {
* @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);
@ -394,7 +393,6 @@ class FixtureTask extends BakeTask {
} 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,

View file

@ -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.
@ -74,7 +75,6 @@ class ModelTask extends BakeTask {
*
*/
public function execute() {
App::import('Model', 'Model', false);
parent::execute();
if (empty($this->args)) {

View file

@ -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

View file

@ -191,7 +191,8 @@ class ViewTask extends BakeTask {
$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();
@ -272,17 +273,18 @@ class ViewTask extends BakeTask {
$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();

View file

@ -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
@ -79,7 +80,6 @@ class ConsoleErrorHandler extends ErrorHandler {
$stderr->write(__("<error>%s Error:</error> %s\n", $name, $message));
if (Configure::read('debug') == 0) {
App::import('Core', 'CakeLog');
CakeLog::write($log, $message);
}
}

View file

@ -662,7 +662,7 @@ class IniAcl extends Object implements AclInterface {
* @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));
}

View file

@ -433,9 +433,9 @@ class EmailComponent extends Component {
$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);
@ -810,7 +810,7 @@ class EmailComponent extends Component {
* @access private
*/
function _smtp() {
App::import('Core', 'CakeSocket');
App::uses('CakeSocket', 'Network');
$defaults = array(
'host' => 'localhost',

View file

@ -542,7 +542,8 @@ class RequestHandlerComponent extends Component {
);
if (!$isAdded) {
if (App::import('Helper', $helper)) {
App::uses($helper . 'Helper', 'Helper');
if (class_exists($helper . 'Helper')) {
$controller->helpers[] = $helper;
}
}

View file

@ -789,9 +789,9 @@ class Controller extends Object {
$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;

View file

@ -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
*
@ -261,7 +261,7 @@ class App {
'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

View file

@ -113,7 +113,7 @@ class ErrorHandler {
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();

View file

@ -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.
*
@ -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')) {

View file

@ -101,7 +101,7 @@ class I18n {
/**
* 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)

View file

@ -1078,7 +1078,7 @@ class Multibyte {
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_');

View file

@ -94,12 +94,7 @@ class BehaviorCollection extends ObjectCollection {
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',

View file

@ -207,9 +207,8 @@ class CakeSchema extends Object {
));
$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();
@ -234,7 +233,8 @@ class CakeSchema extends Object {
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);

View file

@ -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
@ -763,7 +765,6 @@ class DboSource extends DataSource {
return;
}
if (PHP_SAPI != 'cli') {
App::import('Core', 'View');
$controller = null;
$View = new View($controller, false);
$View->set('logs', array($this->configKeyName => $log));

View file

@ -585,7 +585,7 @@ class Set {
if (is_string($path) && strpos($path, '{') !== false) {
$path = String::tokenize($path, '.', '{', '}');
} else {
} elseif (is_string($path)) {
$path = explode('.', $path);
}
$tmp = array();

View file

@ -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>

View file

@ -670,9 +670,7 @@ if (!function_exists('sortByKey')) {
* @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));

View file

@ -17,8 +17,9 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once CAKE . 'basics.php';
App::import('Core', 'Folder');
App::uses('Folder', 'Utility');
/**
* BasicsTest class

View file

@ -18,8 +18,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'TaskCollection', false);
App::import('Shell', 'Shell', false);
App::uses('TaskCollection', 'Console');
App::uses('Shell', 'Console');
class TaskCollectionTest extends CakeTestCase {
/**

View file

@ -17,10 +17,10 @@
* @since CakePHP v 1.2.0.7726
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', 'Acl');
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('AclShell', 'Console/Command');
/**
* AclShellTest class

View file

@ -17,11 +17,10 @@
* @since CakePHP v 1.2.0.7726
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', 'Api');
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('ApiShell', 'Console/Command');
/**
* ApiShellTest class

View file

@ -18,14 +18,14 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', 'Bake', false);
App::import('Shell', 'tasks/model', false);
App::import('Shell', 'tasks/controller', false);
App::import('Shell', 'tasks/db_config', false);
App::import('Core', 'Controller');
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('BakeShell', 'Console/Command');
App::uses('ModelTask', 'Console/Command/Task');
App::uses('ControllerTask', 'Console/Command/Task');
App::uses('DbConfigTask', 'Console/Command/Task');
App::uses('Controller', 'Controller');
if (!class_exists('UsersController')) {
class UsersController extends Controller {
@ -76,7 +76,7 @@ class BakeShellTest extends CakeTestCase {
* @return void
*/
public function testAllWithModelName() {
App::import('Model', 'User');
App::uses('User', 'Model');
$userExists = class_exists('User');
if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
return;

View file

@ -17,7 +17,7 @@
* @since CakePHP v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'CommandList', false);
App::import('CommandListShell', 'Console/Command');
class TestStringOutput extends ConsoleOutput {

View file

@ -17,13 +17,10 @@
* @since CakePHP v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', 'Schema', false);
App::import('Model', 'CakeSchema', false);
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('CakeSchema', 'Model');
/**
* Test for Schema database management

View file

@ -19,10 +19,10 @@
* @since CakePHP v 1.2.0.7726
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'Folder');
App::import('Shell', 'Shell', false);
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('Folder', 'Utility');
/**
* ShellTestShell class

View file

@ -17,33 +17,27 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'ClassRegistry');
App::import('View', 'Helper', false);
App::import('Shell', 'Shell', false);
App::import('Shell', array(
'tasks/project',
'tasks/controller',
'tasks/model',
'tasks/template',
'tasks/test'
));
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('CakeSchema', 'Model');
App::uses('ClassRegistry', 'Utility');
App::uses('Helper', 'View/Helper');
App::uses('ProjectTask', 'Console/Command/Task');
App::uses('ControllerTask', 'Console/Command/Task');
App::uses('ModelTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('TestTask', 'Console/Command/Task');
App::uses('Model', 'Model');
$imported = App::import('Model', 'BakeArticle');
$imported = $imported || App::import('Model', 'BakeComment');
$imported = $imported || App::import('Model', 'BakeTag');
if (!$imported) {
if (class_exists('BakeArticle')) {
define('ARTICLE_MODEL_CREATED', true);
App::import('Core', 'Model');
class BakeArticle extends Model {
public $name = 'BakeArticle';
public $hasMany = array('BakeComment');
public $hasAndBelongsToMany = array('BakeTag');
}
}
/**

View file

@ -17,11 +17,10 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', 'tasks/DbConfig');
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('DbConfigTask', 'Console/Command/Task');
class TEST_DATABASE_CONFIG {
public $default = array(

View file

@ -19,11 +19,11 @@
* @since CakePHP v 1.2.0.7726
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'Folder');
App::import('Shell', 'Shell', false);
App::import('Shell', 'tasks/Extract', false);
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('Folder', 'Utility');
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('ExtractTask', 'Console/Command/Task');
/**
* ExtractTaskTest class

View file

@ -17,14 +17,12 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', array(
'tasks/fixture',
'tasks/template',
'tasks/db_config'
));
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('FixtureTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('DbConfigTask', 'Console/Command/Task');
/**
* FixtureTaskTest class

View file

@ -19,14 +19,12 @@
* @since CakePHP v 1.2.6
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', array(
'tasks/model',
'tasks/fixture',
'tasks/template'
));
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('FixtureTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('ModelTask', 'Console/Command/Task');
/**
* ModelTaskTest class

View file

@ -19,15 +19,12 @@
* @since CakePHP v 1.3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', array(
'tasks/plugin',
'tasks/model'
));
App::import('Core', array('File'));
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('PluginTask', 'Console/Command/Task');
App::uses('ModelTask', 'Console/Command/Task');
App::import('File', 'Utility');
/**
* PluginTaskPlugin class

View file

@ -19,12 +19,11 @@
* @since CakePHP v 1.3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', 'tasks/project');
App::import('Core', 'File');
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('ProjecTask', 'Console/Command/Task');
App::import('File', 'Utility');
/**
* ProjectTask Test class

View file

@ -20,11 +20,10 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', 'tasks/template');
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('TemplateTask', 'Console/Command/Task');
/**
* TemplateTaskTest class
*

View file

@ -19,16 +19,13 @@
* @since CakePHP v 1.2.0.7726
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Shell', array(
'tasks/test',
'tasks/template'
));
App::import('Controller', 'Controller', false);
App::import('Model', 'Model', false);
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('TestTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('Controller', 'Controller');
App::uses('Model', 'Model');
/**
* Test Article model