mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge branch '2.0-class-loading' of github.com:cakephp/cakephp into 2.0-class-loading
This commit is contained in:
commit
64e71de52a
810 changed files with 3861 additions and 3558 deletions
|
@ -28,15 +28,15 @@
|
||||||
* You can specify multiple configurations for production, development and testing.
|
* You can specify multiple configurations for production, development and testing.
|
||||||
*
|
*
|
||||||
* driver => The name of a supported driver; valid options are as follows:
|
* driver => The name of a supported driver; valid options are as follows:
|
||||||
* mysql - MySQL 4 & 5,
|
* Datasabe/Mysql - MySQL 4 & 5,
|
||||||
* sqlite - SQLite (PHP5 only),
|
* Datasabe/Sqlite - SQLite (PHP5 only),
|
||||||
* postgres - PostgreSQL 7 and higher,
|
* Datasabe/Postgres - PostgreSQL 7 and higher,
|
||||||
* mssql - Microsoft SQL Server 2000 and higher,
|
* Datasabe/Mssql - Microsoft SQL Server 2000 and higher,
|
||||||
* oracle - Oracle 8 and higher
|
* Datasabe/Oracle - Oracle 8 and higher
|
||||||
*
|
*
|
||||||
* You can add custom database drivers (or override existing drivers) by adding the
|
* You can add custom database drivers (or override existing drivers) by adding the
|
||||||
* appropriate file to app/models/datasources/dbo. Drivers should be named 'dbo_x.php',
|
* appropriate file to app/models/datasources/database. Drivers should be named 'MyDriver.php',
|
||||||
* where 'x' is the name of the database.
|
*
|
||||||
*
|
*
|
||||||
* persistent => true / false
|
* persistent => true / false
|
||||||
* Determines whether or not the database should use a persistent connection
|
* Determines whether or not the database should use a persistent connection
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
class DATABASE_CONFIG {
|
class DATABASE_CONFIG {
|
||||||
|
|
||||||
public $default = array(
|
public $default = array(
|
||||||
'driver' => 'mysql',
|
'datasource' => 'Database/Mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
||||||
|
@ -69,7 +69,7 @@ class DATABASE_CONFIG {
|
||||||
);
|
);
|
||||||
|
|
||||||
public $test = array(
|
public $test = array(
|
||||||
'driver' => 'mysql',
|
'datasource' => 'Database/Mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
||||||
|
|
|
@ -19,6 +19,6 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'cake' . DIRECTORY_SEPARATOR . 'console' . DIRECTORY_SEPARATOR . 'shell_dispatcher.php');
|
require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'lib'. DIRECTORY_SEPARATOR . 'Cake' . DIRECTORY_SEPARATOR . 'Console' . DIRECTORY_SEPARATOR . 'ShellDispatcher.php');
|
||||||
|
|
||||||
return ShellDispatcher::run($argv);
|
return ShellDispatcher::run($argv);
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||||
define('CAKE_CORE_INCLUDE_PATH', ROOT);
|
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
define('APP_PATH', ROOT . DS . APP_DIR . DS);
|
define('APP_PATH', ROOT . DS . APP_DIR . DS);
|
||||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||||
}
|
}
|
||||||
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
|
if (!include(CORE_PATH . 'Cake' . DS . 'bootstrap.php')) {
|
||||||
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
|
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,6 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
require LIBS . 'dispatcher.php';
|
App::uses('Dispatcher', 'Routing');
|
||||||
$Dispatcher = new Dispatcher();
|
$Dispatcher = new Dispatcher();
|
||||||
$Dispatcher->dispatch(new CakeRequest());
|
$Dispatcher->dispatch(new CakeRequest());
|
||||||
|
|
|
@ -45,11 +45,11 @@ ini_set('display_errors', 1);
|
||||||
define('APP_DIR', basename(dirname(dirname(__FILE__))));
|
define('APP_DIR', basename(dirname(dirname(__FILE__))));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
|
* The absolute path to the "Cake" directory, WITHOUT a trailing DS.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||||
define('CAKE_CORE_INCLUDE_PATH', ROOT);
|
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,21 +67,14 @@ if (!defined('CORE_PATH')) {
|
||||||
define('APP_PATH', ROOT . DS . APP_DIR . DS);
|
define('APP_PATH', ROOT . DS . APP_DIR . DS);
|
||||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||||
}
|
}
|
||||||
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
|
if (!include(CORE_PATH . 'Cake' . DS . 'bootstrap.php')) {
|
||||||
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
|
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$corePath = App::core('cake');
|
|
||||||
if (isset($corePath[0])) {
|
|
||||||
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
|
|
||||||
} else {
|
|
||||||
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Configure::read('debug') < 1) {
|
if (Configure::read('debug') < 1) {
|
||||||
die(__('Debug setting does not allow access to this url.'));
|
die(__('Debug setting does not allow access to this url.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once CAKE_TESTS_LIB . 'cake_test_suite_dispatcher.php';
|
require_once CAKE_TESTS_LIB . 'CakeTestSuiteDispatcher.php';
|
||||||
|
|
||||||
CakeTestSuiteDispatcher::run();
|
CakeTestSuiteDispatcher::run();
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Basic Cake functionality.
|
|
||||||
*
|
|
||||||
* Handles loading of core files needed on every request
|
|
||||||
*
|
|
||||||
* PHP 5
|
|
||||||
*
|
|
||||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
||||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
||||||
*
|
|
||||||
* Licensed under The MIT License
|
|
||||||
* Redistributions of files must retain the above copyright notice.
|
|
||||||
*
|
|
||||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
||||||
* @link http://cakephp.org CakePHP(tm) Project
|
|
||||||
* @package cake
|
|
||||||
* @since CakePHP(tm) v 0.2.9
|
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
||||||
*/
|
|
||||||
if (!defined('E_DEPRECATED')) {
|
|
||||||
define('E_DEPRECATED', 8192);
|
|
||||||
}
|
|
||||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
|
||||||
|
|
||||||
require CORE_PATH . 'cake' . DS . 'basics.php';
|
|
||||||
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
|
|
||||||
require LIBS . 'error' . DS . 'exceptions.php';
|
|
||||||
require LIBS . 'object.php';
|
|
||||||
require LIBS . 'object_collection.php';
|
|
||||||
require LIBS . 'inflector.php';
|
|
||||||
require LIBS . 'app.php';
|
|
||||||
require LIBS . 'configure.php';
|
|
||||||
require LIBS . 'set.php';
|
|
||||||
require LIBS . 'cache.php';
|
|
||||||
require LIBS . 'error' . DS . 'error_handler.php';
|
|
||||||
|
|
||||||
Configure::bootstrap(isset($boot) ? $boot : true);
|
|
||||||
|
|
|
@ -1,908 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* App class
|
|
||||||
*
|
|
||||||
* PHP 5
|
|
||||||
*
|
|
||||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
||||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
||||||
*
|
|
||||||
* Licensed under The MIT License
|
|
||||||
* Redistributions of files must retain the above copyright notice.
|
|
||||||
*
|
|
||||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
||||||
* @link http://cakephp.org CakePHP(tm) Project
|
|
||||||
* @package cake.libs
|
|
||||||
* @since CakePHP(tm) v 1.2.0.6001
|
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* App is responsible for path managment, class location and class loading.
|
|
||||||
*
|
|
||||||
* ### 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.
|
|
||||||
*
|
|
||||||
* ### Inspecting loaded paths
|
|
||||||
*
|
|
||||||
* You can inspect the currently loaded paths using `App::path('controller')` for example to see loaded
|
|
||||||
* controller paths.
|
|
||||||
*
|
|
||||||
* ### Locating plugins and themes
|
|
||||||
*
|
|
||||||
* Plugins and Themes can be located with App as well. Using App::pluginPath('DebugKit') for example, will
|
|
||||||
* give you the full path to the DebugKit plugin. App::themePath('purple'), would give the full path to the
|
|
||||||
* `purple` theme.
|
|
||||||
*
|
|
||||||
* ### Inspecting known objects
|
|
||||||
*
|
|
||||||
* You can find out which objects App knows about using App::objects('controller') for example to find
|
|
||||||
* which application controllers App knows about.
|
|
||||||
*
|
|
||||||
* @link http://book.cakephp.org/view/933/The-App-Class
|
|
||||||
* @package cake.libs
|
|
||||||
*/
|
|
||||||
class App {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of object types and their properties
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $types = array(
|
|
||||||
'class' => array('suffix' => '.php', 'extends' => null, 'core' => true),
|
|
||||||
'file' => array('suffix' => '.php', 'extends' => null, 'core' => true),
|
|
||||||
'model' => array('suffix' => '.php', 'extends' => 'AppModel', 'core' => false),
|
|
||||||
'behavior' => array('suffix' => '.php', 'extends' => 'ModelBehavior', 'core' => true),
|
|
||||||
'controller' => array('suffix' => '_controller.php', 'extends' => 'AppController', 'core' => true),
|
|
||||||
'component' => array('suffix' => '.php', 'extends' => null, 'core' => true),
|
|
||||||
'lib' => array('suffix' => '.php', 'extends' => null, 'core' => true),
|
|
||||||
'view' => array('suffix' => '.php', 'extends' => null, 'core' => true),
|
|
||||||
'helper' => array('suffix' => '.php', 'extends' => 'AppHelper', 'core' => true),
|
|
||||||
'vendor' => array('suffix' => '', 'extends' => null, 'core' => true),
|
|
||||||
'shell' => array('suffix' => '.php', 'extends' => 'Shell', 'core' => true),
|
|
||||||
'plugin' => array('suffix' => '', 'extends' => null, 'core' => true)
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where model files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $models = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where behavior files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $behaviors = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where controller files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $controllers = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where component files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $components = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where datasource files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $datasources = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where libs files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $libs = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where view files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $views = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where helper files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $helpers = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where plugins reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $plugins = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where vendor packages reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $vendors = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where locale files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $locales = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of additional path(s) where console shell files reside.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $shells = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Paths to search for files.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $search = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not to return the file that is loaded.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
public static $return = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if $__maps and $__paths cache should be written.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
private static $__cache = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds key/value pairs of $type => file path.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private static $__map = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds paths for deep searching of files.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private static $__paths = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds loaded files.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private static $__loaded = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds and key => value array of object types.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private static $__objects = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to read information stored path
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
*
|
|
||||||
* `App::path('models'); will return all paths for models`
|
|
||||||
*
|
|
||||||
* @param string $type type of path
|
|
||||||
* @return string array
|
|
||||||
*/
|
|
||||||
public static function path($type) {
|
|
||||||
if (!isset(self::${$type})) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
return self::${$type};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build path references. Merges the supplied $paths
|
|
||||||
* with the base paths and the default core paths.
|
|
||||||
*
|
|
||||||
* @param array $paths paths defines in config/bootstrap.php
|
|
||||||
* @param boolean $reset true will set paths, false merges paths [default] false
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function build($paths = array(), $reset = false) {
|
|
||||||
$defaults = array(
|
|
||||||
'models' => array(MODELS),
|
|
||||||
'behaviors' => array(BEHAVIORS),
|
|
||||||
'datasources' => array(MODELS . 'datasources'),
|
|
||||||
'controllers' => array(CONTROLLERS),
|
|
||||||
'components' => array(COMPONENTS),
|
|
||||||
'libs' => array(APPLIBS),
|
|
||||||
'views' => array(VIEWS),
|
|
||||||
'helpers' => array(HELPERS),
|
|
||||||
'locales' => array(APP . 'locale' . DS),
|
|
||||||
'shells' => array(
|
|
||||||
APP . 'console' . DS . 'shells' . DS,
|
|
||||||
APP . 'vendors' . DS . 'shells' . DS,
|
|
||||||
VENDORS . 'shells' . DS
|
|
||||||
),
|
|
||||||
'vendors' => array(APP . 'vendors' . DS, VENDORS),
|
|
||||||
'plugins' => array(APP . 'plugins' . DS)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($reset == true) {
|
|
||||||
foreach ($paths as $type => $new) {
|
|
||||||
self::${$type} = (array)$new;
|
|
||||||
}
|
|
||||||
return $paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
$core = self::core();
|
|
||||||
$app = array('models' => true, 'controllers' => true, 'helpers' => true);
|
|
||||||
|
|
||||||
foreach ($defaults as $type => $default) {
|
|
||||||
$merge = array();
|
|
||||||
|
|
||||||
if (isset($app[$type])) {
|
|
||||||
$merge = array(APP);
|
|
||||||
}
|
|
||||||
if (isset($core[$type])) {
|
|
||||||
$merge = array_merge($merge, (array)$core[$type]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty(self::${$type}) || empty($paths)) {
|
|
||||||
self::${$type} = $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($paths[$type])) {
|
|
||||||
$path = array_flip(array_flip(array_merge(
|
|
||||||
(array)$paths[$type], self::${$type}, $merge
|
|
||||||
)));
|
|
||||||
} else {
|
|
||||||
$path = array_flip(array_flip(array_merge(self::${$type}, $merge)));
|
|
||||||
}
|
|
||||||
self::${$type} = array_values($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the path that a plugin is on. Searches through the defined plugin paths.
|
|
||||||
*
|
|
||||||
* @param string $plugin CamelCased/lower_cased plugin name to find the path of.
|
|
||||||
* @return string full path to the plugin.
|
|
||||||
*/
|
|
||||||
public static function pluginPath($plugin) {
|
|
||||||
$pluginDir = Inflector::underscore($plugin);
|
|
||||||
for ($i = 0, $length = count(self::$plugins); $i < $length; $i++) {
|
|
||||||
if (is_dir(self::$plugins[$i] . $pluginDir)) {
|
|
||||||
return self::$plugins[$i] . $pluginDir . DS ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return self::$plugins[0] . $pluginDir . DS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the path that a theme is on. Search through the defined theme paths.
|
|
||||||
*
|
|
||||||
* @param string $theme lower_cased theme name to find the path of.
|
|
||||||
* @return string full path to the theme.
|
|
||||||
*/
|
|
||||||
public static function themePath($theme) {
|
|
||||||
$themeDir = 'themed' . DS . Inflector::underscore($theme);
|
|
||||||
for ($i = 0, $length = count(self::$views); $i < $length; $i++) {
|
|
||||||
if (is_dir(self::$views[$i] . $themeDir)) {
|
|
||||||
return self::$views[$i] . $themeDir . DS ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return self::$views[0] . $themeDir . DS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a key/value list of all paths where core libs are found.
|
|
||||||
* Passing $type only returns the values for a given value of $key.
|
|
||||||
*
|
|
||||||
* @param string $type valid values are: 'model', 'behavior', 'controller', 'component',
|
|
||||||
* 'view', 'helper', 'datasource', 'libs', and 'cake'
|
|
||||||
* @return array numeric keyed array of core lib paths
|
|
||||||
*/
|
|
||||||
public static function core($type = null) {
|
|
||||||
static $paths = false;
|
|
||||||
if (!$paths) {
|
|
||||||
$paths = array();
|
|
||||||
$libs = dirname(__FILE__) . DS;
|
|
||||||
$cake = dirname($libs) . DS;
|
|
||||||
$path = dirname($cake) . DS;
|
|
||||||
|
|
||||||
$paths['cake'][] = $cake;
|
|
||||||
$paths['libs'][] = $libs;
|
|
||||||
$paths['models'][] = $libs . 'model' . DS;
|
|
||||||
$paths['datasources'][] = $libs . 'model' . DS . 'datasources' . DS;
|
|
||||||
$paths['behaviors'][] = $libs . 'model' . DS . 'behaviors' . DS;
|
|
||||||
$paths['controllers'][] = $libs . 'controller' . DS;
|
|
||||||
$paths['components'][] = $libs . 'controller' . DS . 'components' . DS;
|
|
||||||
$paths['views'][] = $libs . 'view' . DS;
|
|
||||||
$paths['helpers'][] = $libs . 'view' . DS . 'helpers' . DS;
|
|
||||||
$paths['plugins'][] = $path . 'plugins' . DS;
|
|
||||||
$paths['vendors'][] = $path . 'vendors' . DS;
|
|
||||||
$paths['shells'][] = $cake . 'console' . DS . 'shells' . DS;
|
|
||||||
// Provide BC path to vendors/shells
|
|
||||||
$paths['shells'][] = $path . 'vendors' . DS . 'shells' . DS;
|
|
||||||
}
|
|
||||||
if ($type && isset($paths[$type])) {
|
|
||||||
return $paths[$type];
|
|
||||||
}
|
|
||||||
return $paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array of objects of the given type.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
*
|
|
||||||
* `App::objects('plugin');` returns `array('DebugKit', 'Blog', 'User');`
|
|
||||||
*
|
|
||||||
* You can also search only within a plugin's objects by using the plugin dot
|
|
||||||
* syntax (these objects are not cached):
|
|
||||||
*
|
|
||||||
* `App::objects('MyPlugin.model');` returns `array('Post', 'Comment');`
|
|
||||||
*
|
|
||||||
* @param string $type Type of object, i.e. 'model', 'controller', 'helper', or 'plugin'
|
|
||||||
* @param mixed $path Optional Scan only the path given. If null, paths for the chosen
|
|
||||||
* type will be used.
|
|
||||||
* @param boolean $cache Set to false to rescan objects of the chosen type. Defaults to true.
|
|
||||||
* @return mixed Either false on incorrect / miss. Or an array of found objects.
|
|
||||||
*/
|
|
||||||
public static function objects($type, $path = null, $cache = true) {
|
|
||||||
$objects = array();
|
|
||||||
$extension = false;
|
|
||||||
list($plugin, $type) = pluginSplit($type);
|
|
||||||
$name = $type;
|
|
||||||
|
|
||||||
if ($plugin) {
|
|
||||||
$path = Inflector::pluralize($type);
|
|
||||||
if ($path == 'helpers') {
|
|
||||||
$path = 'views' . DS .$path;
|
|
||||||
} elseif ($path == 'behaviors') {
|
|
||||||
$path = 'models' . DS .$path;
|
|
||||||
} elseif ($path == 'components') {
|
|
||||||
$path = 'controllers' . DS .$path;
|
|
||||||
}
|
|
||||||
$path = self::pluginPath($plugin) . $path;
|
|
||||||
$cache = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type === 'file' && !$path) {
|
|
||||||
return false;
|
|
||||||
} elseif ($type === 'file') {
|
|
||||||
$extension = true;
|
|
||||||
$name = $type . str_replace(DS, '', $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty(self::$__objects) && $cache === true) {
|
|
||||||
self::$__objects = Cache::read('object_map', '_cake_core_');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset(self::$__objects[$name]) || $cache !== true) {
|
|
||||||
$types = self::$types;
|
|
||||||
|
|
||||||
if (!isset($types[$type])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$objects = array();
|
|
||||||
|
|
||||||
if (empty($path)) {
|
|
||||||
$path = self::${"{$type}s"};
|
|
||||||
if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
|
|
||||||
array_pop($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$items = array();
|
|
||||||
|
|
||||||
foreach ((array)$path as $dir) {
|
|
||||||
if ($dir != APP) {
|
|
||||||
$items = self::__list($dir, $types[$type]['suffix'], $extension);
|
|
||||||
$objects = array_merge($items, array_diff($objects, $items));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type !== 'file') {
|
|
||||||
foreach ($objects as $key => $value) {
|
|
||||||
$objects[$key] = Inflector::camelize($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($cache === true) {
|
|
||||||
self::$__cache = true;
|
|
||||||
}
|
|
||||||
if ($plugin) {
|
|
||||||
return $objects;
|
|
||||||
}
|
|
||||||
self::$__objects[$name] = $objects;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$__objects[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows you to modify the object listings that App maintains inside of it
|
|
||||||
* Useful for testing
|
|
||||||
*
|
|
||||||
* @param string $type Type of object listing you are changing
|
|
||||||
* @param array $values The values $type should be set to.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function setObjects($type, $values) {
|
|
||||||
self::$__objects[$type] = $values;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds classes based on $name or specific file(s) to search. Calling App::import() will
|
|
||||||
* not construct any classes contained in the files. It will only find and require() the file.
|
|
||||||
*
|
|
||||||
* @link http://book.cakephp.org/view/934/Using-App-import
|
|
||||||
* @param mixed $type The type of Class if passed as a string, or all params can be passed as
|
|
||||||
* an single array to $type,
|
|
||||||
* @param string $name Name of the Class or a unique name for the file
|
|
||||||
* @param mixed $parent boolean true if Class Parent should be searched, accepts key => value
|
|
||||||
* array('parent' => $parent ,'file' => $file, 'search' => $search, 'ext' => '$ext');
|
|
||||||
* $ext allows setting the extension of the file name
|
|
||||||
* based on Inflector::underscore($name) . ".$ext";
|
|
||||||
* @param array $search paths to search for files, array('path 1', 'path 2', 'path 3');
|
|
||||||
* @param string $file full name of the file to search for including extension
|
|
||||||
* @param boolean $return, return the loaded file, the file must have a return
|
|
||||||
* statement in it to work: return $variable;
|
|
||||||
* @return boolean true if Class is already in memory or if file is found and loaded, false if not
|
|
||||||
*/
|
|
||||||
public static function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
|
|
||||||
$plugin = $directory = null;
|
|
||||||
|
|
||||||
if (is_array($type)) {
|
|
||||||
extract($type, EXTR_OVERWRITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($parent)) {
|
|
||||||
extract($parent, EXTR_OVERWRITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($name === null && $file === null) {
|
|
||||||
$name = $type;
|
|
||||||
$type = 'Core';
|
|
||||||
} elseif ($name === null) {
|
|
||||||
$type = 'File';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($name)) {
|
|
||||||
foreach ($name as $class) {
|
|
||||||
$tempType = $type;
|
|
||||||
$plugin = null;
|
|
||||||
|
|
||||||
if (strpos($class, '.') !== false) {
|
|
||||||
$value = explode('.', $class);
|
|
||||||
$count = count($value);
|
|
||||||
|
|
||||||
if ($count > 2) {
|
|
||||||
$tempType = $value[0];
|
|
||||||
$plugin = $value[1] . '.';
|
|
||||||
$class = $value[2];
|
|
||||||
} elseif ($count === 2 && ($type === 'Core' || $type === 'File')) {
|
|
||||||
$tempType = $value[0];
|
|
||||||
$class = $value[1];
|
|
||||||
} else {
|
|
||||||
$plugin = $value[0] . '.';
|
|
||||||
$class = $value[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!App::import($tempType, $plugin . $class, $parent)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($name != null && strpos($name, '.') !== false) {
|
|
||||||
list($plugin, $name) = explode('.', $name);
|
|
||||||
$plugin = Inflector::camelize($plugin);
|
|
||||||
}
|
|
||||||
self::$return = $return;
|
|
||||||
|
|
||||||
if (isset($ext)) {
|
|
||||||
$file = Inflector::underscore($name) . ".{$ext}";
|
|
||||||
}
|
|
||||||
$ext = self::__settings($type, $plugin, $parent);
|
|
||||||
$className = $name;
|
|
||||||
if (strpos($className, '/') !== false) {
|
|
||||||
$className = substr($className, strrpos($className, '/') + 1);
|
|
||||||
}
|
|
||||||
if ($name != null && !class_exists($className . $ext['class'])) {
|
|
||||||
if ($load = self::__mapped($name . $ext['class'], $type, $plugin)) {
|
|
||||||
if (self::__load($load)) {
|
|
||||||
if (self::$return) {
|
|
||||||
return include($load);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
self::__remove($name . $ext['class'], $type, $plugin);
|
|
||||||
self::$__cache = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!empty($search)) {
|
|
||||||
self::$search = $search;
|
|
||||||
} elseif ($plugin) {
|
|
||||||
self::$search = self::__paths('plugin');
|
|
||||||
} else {
|
|
||||||
self::$search = self::__paths($type);
|
|
||||||
}
|
|
||||||
$find = $file;
|
|
||||||
|
|
||||||
if ($find === null) {
|
|
||||||
$find = Inflector::underscore($name . $ext['suffix']).'.php';
|
|
||||||
|
|
||||||
if ($plugin) {
|
|
||||||
$paths = self::$search;
|
|
||||||
foreach ($paths as $key => $value) {
|
|
||||||
self::$search[$key] = $value . $ext['path'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strtolower($type) !== 'vendor' && empty($search) && self::__load($file)) {
|
|
||||||
$directory = false;
|
|
||||||
} else {
|
|
||||||
$file = $find;
|
|
||||||
$directory = self::__find($find, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($directory !== null) {
|
|
||||||
self::$__cache = true;
|
|
||||||
self::__map($directory . $file, $name . $ext['class'], $type, $plugin);
|
|
||||||
|
|
||||||
if (self::$return) {
|
|
||||||
return include($directory . $file);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the cache for App, registers a shutdown function.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function init() {
|
|
||||||
self::$__map = (array)Cache::read('file_map', '_cake_core_');
|
|
||||||
register_shutdown_function(array('App', 'shutdown'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Locates the $file in $__paths, searches recursively.
|
|
||||||
*
|
|
||||||
* @param string $file full file name
|
|
||||||
* @param boolean $recursive search $__paths recursively
|
|
||||||
* @return mixed boolean on fail, $file directory path on success
|
|
||||||
*/
|
|
||||||
private static function __find($file, $recursive = true) {
|
|
||||||
static $appPath = false;
|
|
||||||
|
|
||||||
if (empty(self::$search)) {
|
|
||||||
return null;
|
|
||||||
} elseif (is_string(self::$search)) {
|
|
||||||
self::$search = array(self::$search);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty(self::$__paths)) {
|
|
||||||
self::$__paths = Cache::read('dir_map', '_cake_core_');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (self::$search as $path) {
|
|
||||||
if ($appPath === false) {
|
|
||||||
$appPath = rtrim(APP, DS);
|
|
||||||
}
|
|
||||||
$path = rtrim($path, DS);
|
|
||||||
|
|
||||||
if ($path === $appPath) {
|
|
||||||
$recursive = false;
|
|
||||||
}
|
|
||||||
if ($recursive === false) {
|
|
||||||
if (self::__load($path . DS . $file)) {
|
|
||||||
return $path . DS;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset(self::$__paths[$path])) {
|
|
||||||
if (!class_exists('Folder')) {
|
|
||||||
require LIBS . 'folder.php';
|
|
||||||
}
|
|
||||||
$Folder = new Folder();
|
|
||||||
$directories = $Folder->tree($path, array('.svn', '.git', 'CVS', 'tests', 'templates'), 'dir');
|
|
||||||
sort($directories);
|
|
||||||
self::$__paths[$path] = $directories;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (self::$__paths[$path] as $directory) {
|
|
||||||
if (self::__load($directory . DS . $file)) {
|
|
||||||
return $directory . DS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to load $file.
|
|
||||||
*
|
|
||||||
* @param string $file full path to file including file name
|
|
||||||
* @return boolean
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private static function __load($file) {
|
|
||||||
if (empty($file)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!self::$return && isset(self::$__loaded[$file])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (file_exists($file)) {
|
|
||||||
if (!self::$return) {
|
|
||||||
require($file);
|
|
||||||
self::$__loaded[$file] = true;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps the $name to the $file.
|
|
||||||
*
|
|
||||||
* @param string $file full path to file
|
|
||||||
* @param string $name unique name for this map
|
|
||||||
* @param string $type type object being mapped
|
|
||||||
* @param string $plugin camelized if object is from a plugin, the name of the plugin
|
|
||||||
* @return void
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private static function __map($file, $name, $type, $plugin) {
|
|
||||||
if ($plugin) {
|
|
||||||
self::$__map['Plugin'][$plugin][$type][$name] = $file;
|
|
||||||
} else {
|
|
||||||
self::$__map[$type][$name] = $file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a file's complete path.
|
|
||||||
*
|
|
||||||
* @param string $name unique name
|
|
||||||
* @param string $type type object
|
|
||||||
* @param string $plugin camelized if object is from a plugin, the name of the plugin
|
|
||||||
* @return mixed, file path if found, false otherwise
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private static function __mapped($name, $type, $plugin) {
|
|
||||||
if ($plugin) {
|
|
||||||
if (isset(self::$__map['Plugin'][$plugin][$type]) && isset(self::$__map['Plugin'][$plugin][$type][$name])) {
|
|
||||||
return self::$__map['Plugin'][$plugin][$type][$name];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset(self::$__map[$type]) && isset(self::$__map[$type][$name])) {
|
|
||||||
return self::$__map[$type][$name];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads parent classes based on $type.
|
|
||||||
* Returns a prefix or suffix needed for loading files.
|
|
||||||
*
|
|
||||||
* @param string $type type of object
|
|
||||||
* @param string $plugin camelized name of plugin
|
|
||||||
* @param boolean $parent false will not attempt to load parent
|
|
||||||
* @return array
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private static function __settings($type, $plugin, $parent) {
|
|
||||||
if (!$parent) {
|
|
||||||
return array('class' => null, 'suffix' => null, 'path' => null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($plugin) {
|
|
||||||
$pluginPath = Inflector::underscore($plugin);
|
|
||||||
}
|
|
||||||
$path = null;
|
|
||||||
$load = strtolower($type);
|
|
||||||
|
|
||||||
switch ($load) {
|
|
||||||
case 'model':
|
|
||||||
if (!class_exists('Model')) {
|
|
||||||
require LIBS . 'model' . DS . 'model.php';
|
|
||||||
}
|
|
||||||
if (!class_exists('AppModel')) {
|
|
||||||
App::import($type, 'AppModel', false);
|
|
||||||
}
|
|
||||||
if ($plugin) {
|
|
||||||
if (!class_exists($plugin . 'AppModel')) {
|
|
||||||
App::import($type, $plugin . '.' . $plugin . 'AppModel', false, array(), $pluginPath . DS . $pluginPath . '_app_model.php');
|
|
||||||
}
|
|
||||||
$path = $pluginPath . DS . 'models' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => null, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'behavior':
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'models' . DS . 'behaviors' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'datasource':
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'models' . DS . 'datasources' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
|
||||||
case 'controller':
|
|
||||||
App::import($type, 'AppController', false);
|
|
||||||
if ($plugin) {
|
|
||||||
App::import($type, $plugin . '.' . $plugin . 'AppController', false, array(), $pluginPath . DS . $pluginPath . '_app_controller.php');
|
|
||||||
$path = $pluginPath . DS . 'controllers' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => $type, 'suffix' => $type, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'component':
|
|
||||||
App::import('Core', 'Component', false);
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'controllers' . DS . 'components' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'lib':
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'libs' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => null, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'view':
|
|
||||||
App::import('View', 'View', false);
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'views' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'helper':
|
|
||||||
if (!class_exists('AppHelper')) {
|
|
||||||
App::import($type, 'AppHelper', false);
|
|
||||||
}
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'views' . DS . 'helpers' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'shell':
|
|
||||||
if (!class_exists('Shell')) {
|
|
||||||
App::import($type, 'Shell', false);
|
|
||||||
}
|
|
||||||
if (!class_exists('AppShell')) {
|
|
||||||
App::import($type, 'AppShell', false);
|
|
||||||
}
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'console' . DS . 'shells' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
case 'vendor':
|
|
||||||
if ($plugin) {
|
|
||||||
$path = $pluginPath . DS . 'vendors' . DS;
|
|
||||||
}
|
|
||||||
return array('class' => null, 'suffix' => null, 'path' => $path);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$type = $suffix = $path = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return array('class' => null, 'suffix' => null, 'path' => null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns default search paths.
|
|
||||||
*
|
|
||||||
* @param string $type type of object to be searched
|
|
||||||
* @return array list of paths
|
|
||||||
*/
|
|
||||||
private static function __paths($type) {
|
|
||||||
$type = strtolower($type);
|
|
||||||
$paths = array();
|
|
||||||
|
|
||||||
if ($type === 'core') {
|
|
||||||
return App::core('libs');
|
|
||||||
}
|
|
||||||
if (isset(self::${$type . 's'})) {
|
|
||||||
return self::${$type . 's'};
|
|
||||||
}
|
|
||||||
return $paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes file location from map if the file has been deleted.
|
|
||||||
*
|
|
||||||
* @param string $name name of object
|
|
||||||
* @param string $type type of object
|
|
||||||
* @param string $plugin camelized name of plugin
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private static function __remove($name, $type, $plugin) {
|
|
||||||
if ($plugin) {
|
|
||||||
unset(self::$__map['Plugin'][$plugin][$type][$name]);
|
|
||||||
} else {
|
|
||||||
unset(self::$__map[$type][$name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array of filenames of PHP files in the given directory.
|
|
||||||
*
|
|
||||||
* @param string $path Path to scan for files
|
|
||||||
* @param string $suffix if false, return only directories. if string, match and return files
|
|
||||||
* @return array List of directories or files in directory
|
|
||||||
*/
|
|
||||||
private static function __list($path, $suffix = false, $extension = false) {
|
|
||||||
if (!class_exists('Folder')) {
|
|
||||||
require LIBS . 'folder.php';
|
|
||||||
}
|
|
||||||
$items = array();
|
|
||||||
$Folder = new Folder($path);
|
|
||||||
$contents = $Folder->read(false, true);
|
|
||||||
|
|
||||||
if (is_array($contents)) {
|
|
||||||
if (!$suffix) {
|
|
||||||
return $contents[0];
|
|
||||||
} else {
|
|
||||||
foreach ($contents[1] as $item) {
|
|
||||||
if (substr($item, - strlen($suffix)) === $suffix) {
|
|
||||||
if ($extension) {
|
|
||||||
$items[] = $item;
|
|
||||||
} else {
|
|
||||||
$items[] = substr($item, 0, strlen($item) - strlen($suffix));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Object destructor.
|
|
||||||
*
|
|
||||||
* Writes cache file if changes have been made to the $__map or $__paths
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function shutdown() {
|
|
||||||
if (self::$__cache) {
|
|
||||||
$core = App::core('cake');
|
|
||||||
unset(self::$__paths[rtrim($core[0], DS)]);
|
|
||||||
Cache::write('dir_map', array_filter(self::$__paths), '_cake_core_');
|
|
||||||
Cache::write('file_map', array_filter(self::$__map), '_cake_core_');
|
|
||||||
Cache::write('object_map', self::$__objects, '_cake_core_');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,568 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AppImportTest class
|
|
||||||
*
|
|
||||||
* @package cake.tests.cases.libs
|
|
||||||
*/
|
|
||||||
class AppImportTest extends CakeTestCase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testBuild method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testBuild() {
|
|
||||||
$old = App::path('models');
|
|
||||||
$expected = array(
|
|
||||||
APP . 'models' . DS,
|
|
||||||
APP,
|
|
||||||
LIBS . 'model' . DS
|
|
||||||
);
|
|
||||||
$this->assertEqual($expected, $old);
|
|
||||||
|
|
||||||
App::build(array('models' => array('/path/to/models/')));
|
|
||||||
|
|
||||||
$new = App::path('models');
|
|
||||||
|
|
||||||
$expected = array(
|
|
||||||
'/path/to/models/',
|
|
||||||
APP . 'models' . DS,
|
|
||||||
APP,
|
|
||||||
LIBS . 'model' . DS
|
|
||||||
);
|
|
||||||
$this->assertEqual($expected, $new);
|
|
||||||
|
|
||||||
App::build(); //reset defaults
|
|
||||||
$defaults = App::path('models');
|
|
||||||
$this->assertEqual($old, $defaults);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testBuildWithReset method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testBuildWithReset() {
|
|
||||||
$old = App::path('models');
|
|
||||||
$expected = array(
|
|
||||||
APP . 'models' . DS,
|
|
||||||
APP,
|
|
||||||
LIBS . 'model' . DS
|
|
||||||
);
|
|
||||||
$this->assertEqual($expected, $old);
|
|
||||||
|
|
||||||
App::build(array('models' => array('/path/to/models/')), true);
|
|
||||||
|
|
||||||
$new = App::path('models');
|
|
||||||
|
|
||||||
$expected = array(
|
|
||||||
'/path/to/models/'
|
|
||||||
);
|
|
||||||
$this->assertEqual($expected, $new);
|
|
||||||
|
|
||||||
App::build(); //reset defaults
|
|
||||||
$defaults = App::path('models');
|
|
||||||
$this->assertEqual($old, $defaults);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testCore method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testCore() {
|
|
||||||
$model = App::core('models');
|
|
||||||
$this->assertEqual(array(LIBS . 'model' . DS), $model);
|
|
||||||
|
|
||||||
$view = App::core('views');
|
|
||||||
$this->assertEqual(array(LIBS . 'view' . DS), $view);
|
|
||||||
|
|
||||||
$controller = App::core('controllers');
|
|
||||||
$this->assertEqual(array(LIBS . 'controller' . DS), $controller);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testListObjects method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testListObjects() {
|
|
||||||
$result = App::objects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs', false);
|
|
||||||
$this->assertTrue(in_array('Xml', $result));
|
|
||||||
$this->assertTrue(in_array('Cache', $result));
|
|
||||||
$this->assertTrue(in_array('HttpSocket', $result));
|
|
||||||
|
|
||||||
$result = App::objects('behavior', null, false);
|
|
||||||
$this->assertTrue(in_array('Tree', $result));
|
|
||||||
|
|
||||||
$result = App::objects('controller', null, false);
|
|
||||||
$this->assertTrue(in_array('Pages', $result));
|
|
||||||
|
|
||||||
$result = App::objects('component', null, false);
|
|
||||||
$this->assertTrue(in_array('Auth', $result));
|
|
||||||
|
|
||||||
$result = App::objects('view', null, false);
|
|
||||||
$this->assertTrue(in_array('Media', $result));
|
|
||||||
|
|
||||||
$result = App::objects('helper', null, false);
|
|
||||||
$this->assertTrue(in_array('Html', $result));
|
|
||||||
|
|
||||||
$result = App::objects('model', null, false);
|
|
||||||
$notExpected = array('AppModel', 'ModelBehavior', 'ConnectionManager', 'DbAcl', 'Model', 'CakeSchema');
|
|
||||||
foreach ($notExpected as $class) {
|
|
||||||
$this->assertFalse(in_array($class, $result));
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = App::objects('file');
|
|
||||||
$this->assertFalse($result);
|
|
||||||
|
|
||||||
$result = App::objects('file', 'non_existing_configure');
|
|
||||||
$expected = array();
|
|
||||||
$this->assertEqual($result, $expected);
|
|
||||||
|
|
||||||
$result = App::objects('NonExistingType');
|
|
||||||
$this->assertFalse($result);
|
|
||||||
|
|
||||||
App::build(array(
|
|
||||||
'plugins' => array(
|
|
||||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS
|
|
||||||
)
|
|
||||||
));
|
|
||||||
$result = App::objects('plugin', null, false);
|
|
||||||
$this->assertTrue(in_array('Cache', $result));
|
|
||||||
$this->assertTrue(in_array('Log', $result));
|
|
||||||
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests listing objects within a plugin
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testListObjectsInPlugin() {
|
|
||||||
App::build(array(
|
|
||||||
'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
|
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
|
||||||
));
|
|
||||||
|
|
||||||
$oldCache = App::$models;
|
|
||||||
$result = App::objects('TestPlugin.model');
|
|
||||||
$this->assertTrue(in_array('TestPluginPost', $result));
|
|
||||||
$this->assertEquals($oldCache, App::$models);
|
|
||||||
|
|
||||||
$result = App::objects('TestPlugin.behavior');
|
|
||||||
$this->assertTrue(in_array('TestPluginPersisterOne', $result));
|
|
||||||
|
|
||||||
$result = App::objects('TestPlugin.helper');
|
|
||||||
$expected = array('OtherHelper', 'PluggedHelper', 'TestPluginApp');
|
|
||||||
$this->assertEquals($result, $expected);
|
|
||||||
|
|
||||||
$result = App::objects('TestPlugin.component');
|
|
||||||
$this->assertTrue(in_array('OtherComponent', $result));
|
|
||||||
|
|
||||||
$result = App::objects('TestPluginTwo.behavior');
|
|
||||||
$this->assertEquals($result, array());
|
|
||||||
|
|
||||||
$result = App::objects('model', null, false);
|
|
||||||
$this->assertTrue(in_array('Comment', $result));
|
|
||||||
$this->assertTrue(in_array('Post', $result));
|
|
||||||
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test that pluginPath can find paths for plugins.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testPluginPath() {
|
|
||||||
App::build(array(
|
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
|
||||||
));
|
|
||||||
$path = App::pluginPath('test_plugin');
|
|
||||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
|
|
||||||
$this->assertEqual($path, $expected);
|
|
||||||
|
|
||||||
$path = App::pluginPath('TestPlugin');
|
|
||||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
|
|
||||||
$this->assertEqual($path, $expected);
|
|
||||||
|
|
||||||
$path = App::pluginPath('TestPluginTwo');
|
|
||||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS;
|
|
||||||
$this->assertEqual($path, $expected);
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test that pluginPath can find paths for plugins.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testThemePath() {
|
|
||||||
App::build(array(
|
|
||||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
|
|
||||||
));
|
|
||||||
$path = App::themePath('test_theme');
|
|
||||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
|
|
||||||
$this->assertEqual($path, $expected);
|
|
||||||
|
|
||||||
$path = App::themePath('TestTheme');
|
|
||||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
|
|
||||||
$this->assertEqual($path, $expected);
|
|
||||||
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testClassLoading method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testClassLoading() {
|
|
||||||
$file = App::import();
|
|
||||||
$this->assertTrue($file);
|
|
||||||
|
|
||||||
$file = App::import('Model', 'Model', false);
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('Model'));
|
|
||||||
|
|
||||||
$file = App::import('Controller', 'Controller', false);
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('Controller'));
|
|
||||||
|
|
||||||
$file = App::import('Component', 'Component', false);
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('Component'));
|
|
||||||
|
|
||||||
$file = App::import('Shell', 'Shell', false);
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('Shell'));
|
|
||||||
|
|
||||||
$file = App::import('Lib', 'config/PhpReader');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('PhpReader'));
|
|
||||||
|
|
||||||
$file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
|
|
||||||
$file = App::import('Model', 'AppModel', false);
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('AppModel'));
|
|
||||||
|
|
||||||
$file = App::import('WrongType', null, true, array(), '');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
|
|
||||||
$file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
|
|
||||||
$file = App::import('Core', 'NonExistingPlugin.NonExistingModel', false);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
|
|
||||||
$file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
|
|
||||||
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel'), false);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
|
|
||||||
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel.AnotherChild'), false);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
|
|
||||||
if (!class_exists('AppController')) {
|
|
||||||
$classes = array_flip(get_declared_classes());
|
|
||||||
|
|
||||||
$this->assertFalse(isset($classes['PagesController']));
|
|
||||||
$this->assertFalse(isset($classes['AppController']));
|
|
||||||
|
|
||||||
$file = App::import('Controller', 'Pages');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('PagesController'));
|
|
||||||
|
|
||||||
$classes = array_flip(get_declared_classes());
|
|
||||||
|
|
||||||
$this->assertTrue(isset($classes['PagesController']));
|
|
||||||
$this->assertTrue(isset($classes['AppController']));
|
|
||||||
|
|
||||||
$file = App::import('Behavior', 'Containable');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('ContainableBehavior'));
|
|
||||||
|
|
||||||
$file = App::import('Component', 'RequestHandler');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('RequestHandlerComponent'));
|
|
||||||
|
|
||||||
$file = App::import('Helper', 'Form');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('FormHelper'));
|
|
||||||
|
|
||||||
$file = App::import('Model', 'NonExistingModel');
|
|
||||||
$this->assertFalse($file);
|
|
||||||
|
|
||||||
$file = App::import('Datasource', 'DboSource');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
$this->assertTrue(class_exists('DboSource'));
|
|
||||||
}
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test import() with plugins
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testPluginImporting() {
|
|
||||||
App::build(array(
|
|
||||||
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
|
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
|
||||||
));
|
|
||||||
|
|
||||||
$result = App::import('Controller', 'TestPlugin.Tests');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('TestPluginAppController'));
|
|
||||||
$this->assertTrue(class_exists('TestsController'));
|
|
||||||
|
|
||||||
$result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('TestPluginLibrary'));
|
|
||||||
|
|
||||||
$result = App::import('Lib', 'Library');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('Library'));
|
|
||||||
|
|
||||||
$result = App::import('Helper', 'TestPlugin.OtherHelper');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('OtherHelperHelper'));
|
|
||||||
|
|
||||||
$result = App::import('Helper', 'TestPlugin.TestPluginApp');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('TestPluginAppHelper'));
|
|
||||||
|
|
||||||
$result = App::import('Datasource', 'TestPlugin.TestSource');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('TestSource'));
|
|
||||||
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test that building helper paths actually works.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @link http://cakephp.lighthouseapp.com/projects/42648/tickets/410
|
|
||||||
*/
|
|
||||||
function testImportingHelpersFromAlternatePaths() {
|
|
||||||
App::build();
|
|
||||||
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
|
|
||||||
App::import('Helper', 'Banana');
|
|
||||||
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper was not found because the path does not exist.');
|
|
||||||
|
|
||||||
App::build(array(
|
|
||||||
'helpers' => array(
|
|
||||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'helpers' . DS
|
|
||||||
)
|
|
||||||
));
|
|
||||||
App::build(array('vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH)));
|
|
||||||
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
|
|
||||||
App::import('Helper', 'Banana');
|
|
||||||
$this->assertTrue(class_exists('BananaHelper'), 'BananaHelper was not loaded.');
|
|
||||||
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testFileLoading method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testFileLoading () {
|
|
||||||
$file = App::import('File', 'RealFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
|
|
||||||
$file = App::import('File', 'NoFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
|
|
||||||
$this->assertFalse($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testFileLoadingWithArray method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testFileLoadingWithArray() {
|
|
||||||
$type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
|
|
||||||
'file' => TEST_CAKE_CORE_INCLUDE_PATH . DS . 'config' . DS . 'config.php');
|
|
||||||
$file = App::import($type);
|
|
||||||
$this->assertTrue($file);
|
|
||||||
|
|
||||||
$type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
|
|
||||||
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
|
|
||||||
$file = App::import($type);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testFileLoadingReturnValue method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testFileLoadingReturnValue () {
|
|
||||||
$file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
|
|
||||||
$this->assertTrue(!empty($file));
|
|
||||||
|
|
||||||
$this->assertTrue(isset($file['Cake.version']));
|
|
||||||
|
|
||||||
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
|
|
||||||
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
|
|
||||||
$file = App::import($type);
|
|
||||||
$this->assertTrue(!empty($file));
|
|
||||||
|
|
||||||
$this->assertTrue(isset($file['Cake.version']));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testLoadingWithSearch method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testLoadingWithSearch () {
|
|
||||||
$file = App::import('File', 'NewName', false, array(TEST_CAKE_CORE_INCLUDE_PATH ), 'config.php');
|
|
||||||
$this->assertTrue($file);
|
|
||||||
|
|
||||||
$file = App::import('File', 'AnotherNewName', false, array(LIBS), 'config.php');
|
|
||||||
$this->assertFalse($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testLoadingWithSearchArray method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testLoadingWithSearchArray () {
|
|
||||||
$type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(TEST_CAKE_CORE_INCLUDE_PATH ));
|
|
||||||
$file = App::import($type);
|
|
||||||
$this->assertTrue($file);
|
|
||||||
|
|
||||||
$type = array('type' => 'File', 'name' => 'AnotherRandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(LIBS));
|
|
||||||
$file = App::import($type);
|
|
||||||
$this->assertFalse($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testMultipleLoading method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testMultipleLoading() {
|
|
||||||
if (class_exists('I18n', false) || class_exists('CakeSocket', false)) {
|
|
||||||
$this->markTestSkipped('Cannot test loading of classes that exist.');
|
|
||||||
}
|
|
||||||
$toLoad = array('I18n', 'CakeSocket');
|
|
||||||
|
|
||||||
$classes = array_flip(get_declared_classes());
|
|
||||||
$this->assertFalse(isset($classes['i18n']));
|
|
||||||
$this->assertFalse(isset($classes['CakeSocket']));
|
|
||||||
|
|
||||||
$load = App::import($toLoad);
|
|
||||||
$this->assertTrue($load);
|
|
||||||
|
|
||||||
$classes = array_flip(get_declared_classes());
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertTrue(isset($classes['I18n']));
|
|
||||||
|
|
||||||
$load = App::import(array('I18n', 'SomeNotFoundClass', 'CakeSocket'));
|
|
||||||
$this->assertFalse($load);
|
|
||||||
|
|
||||||
$load = App::import($toLoad);
|
|
||||||
$this->assertTrue($load);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This test only works if you have plugins/my_plugin set up.
|
|
||||||
* plugins/my_plugin/models/my_plugin.php and other_model.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
function testMultipleLoadingByType() {
|
|
||||||
$classes = array_flip(get_declared_classes());
|
|
||||||
$this->assertFalse(isset($classes['OtherPlugin']));
|
|
||||||
$this->assertFalse(isset($classes['MyPlugin']));
|
|
||||||
|
|
||||||
|
|
||||||
$load = App::import('Model', array('MyPlugin.OtherPlugin', 'MyPlugin.MyPlugin'));
|
|
||||||
$this->assertTrue($load);
|
|
||||||
|
|
||||||
$classes = array_flip(get_declared_classes());
|
|
||||||
$this->assertTrue(isset($classes['OtherPlugin']));
|
|
||||||
$this->assertTrue(isset($classes['MyPlugin']));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
function testLoadingVendor() {
|
|
||||||
App::build(array(
|
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
|
||||||
'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
|
|
||||||
), true);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$result = App::import('Vendor', 'TestPlugin.TestPluginAsset', array('ext' => 'css'));
|
|
||||||
$text = ob_get_clean();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEqual($text, 'this is the test plugin asset css file');
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$result = App::import('Vendor', 'TestAsset', array('ext' => 'css'));
|
|
||||||
$text = ob_get_clean();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEqual($text, 'this is the test asset css file');
|
|
||||||
|
|
||||||
$result = App::import('Vendor', 'TestPlugin.SamplePlugin');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('SamplePluginClassTestName'));
|
|
||||||
|
|
||||||
$result = App::import('Vendor', 'ConfigureTestVendorSample');
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertTrue(class_exists('ConfigureTestVendorSample'));
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$result = App::import('Vendor', 'SomeName', array('file' => 'some.name.php'));
|
|
||||||
$text = ob_get_clean();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEqual($text, 'This is a file with dot in file name');
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$result = App::import('Vendor', 'TestHello', array('file' => 'Test'.DS.'hello.php'));
|
|
||||||
$text = ob_get_clean();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEqual($text, 'This is the hello.php file in Test directory');
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$result = App::import('Vendor', 'MyTest', array('file' => 'Test'.DS.'MyTest.php'));
|
|
||||||
$text = ob_get_clean();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEqual($text, 'This is the MyTest.php file');
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$result = App::import('Vendor', 'Welcome');
|
|
||||||
$text = ob_get_clean();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEqual($text, 'This is the welcome.php file in vendors directory');
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$result = App::import('Vendor', 'TestPlugin.Welcome');
|
|
||||||
$text = ob_get_clean();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class TestLocalDriver extends TestSource {
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
App::uses('Inflector', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache provides a consistent interface to Caching in your application. It allows you
|
* Cache provides a consistent interface to Caching in your application. It allows you
|
||||||
* to use several different Cache engines, without coupling your application to a specific
|
* to use several different Cache engines, without coupling your application to a specific
|
||||||
|
@ -133,9 +135,10 @@ class Cache {
|
||||||
protected static function _buildEngine($name) {
|
protected static function _buildEngine($name) {
|
||||||
$config = self::$_config[$name];
|
$config = self::$_config[$name];
|
||||||
|
|
||||||
list($plugin, $class) = pluginSplit($config['engine']);
|
list($plugin, $class) = pluginSplit($config['engine'], true);
|
||||||
$cacheClass = $class . 'Engine';
|
$cacheClass = $class . 'Engine';
|
||||||
if (!class_exists($cacheClass) && self::_loadEngine($class, $plugin) === false) {
|
App::uses($cacheClass, $plugin . 'Cache/Engine');
|
||||||
|
if (!class_exists($cacheClass)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$cacheClass = $class . 'Engine';
|
$cacheClass = $class . 'Engine';
|
||||||
|
@ -177,26 +180,6 @@ class Cache {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to find and include a file for a cache engine and returns object instance
|
|
||||||
*
|
|
||||||
* @param $name Name of the engine (without 'Engine')
|
|
||||||
* @return mixed $engine object or null
|
|
||||||
*/
|
|
||||||
protected static function _loadEngine($name, $plugin = null) {
|
|
||||||
if ($plugin) {
|
|
||||||
return App::import('Lib', $plugin . '.cache' . DS . $name, false);
|
|
||||||
} else {
|
|
||||||
$core = App::core();
|
|
||||||
$path = $core['libs'][0] . 'cache' . DS . strtolower($name) . '.php';
|
|
||||||
if (file_exists($path)) {
|
|
||||||
require $path;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return App::import('Lib', 'cache' . DS . $name, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporarily change the settings on a cache config. The settings will persist for the next write
|
* Temporarily change the settings on a cache config. The settings will persist for the next write
|
||||||
* operation (write, decrement, increment, clear). Any reads that are done before the write, will
|
* operation (write, decrement, increment, clear). Any reads that are done before the write, will
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a placeholder class.
|
* This is a placeholder class.
|
||||||
* Create the same file in app/console/shells/app_shell.php
|
* Create the same file in app/console/shells/AppShell.php
|
||||||
*
|
*
|
||||||
* Add your application-wide methods in the class below, your shells
|
* Add your application-wide methods in the class below, your shells
|
||||||
* will inherit them.
|
* will inherit them.
|
|
@ -16,8 +16,8 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Component', 'Acl');
|
App::uses('AclComponent', 'Controller/Component');
|
||||||
App::import('Model', 'DbAcl');
|
App::uses('DbAcl', 'Model');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shell for ACL management. This console is known to have issues with zend.ze1_compatibility_mode
|
* Shell for ACL management. This console is known to have issues with zend.ze1_compatibility_mode
|
|
@ -18,7 +18,7 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @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.
|
* API shell to show method signatures of CakePHP core classes.
|
||||||
|
@ -41,13 +41,13 @@ class ApiShell extends Shell {
|
||||||
*/
|
*/
|
||||||
public function initialize() {
|
public function initialize() {
|
||||||
$this->paths = array_merge($this->paths, array(
|
$this->paths = array_merge($this->paths, array(
|
||||||
'behavior' => LIBS . 'model' . DS . 'behaviors' . DS,
|
'behavior' => LIBS . 'Model' . DS . 'Behavior' . DS,
|
||||||
'cache' => LIBS . 'cache' . DS,
|
'cache' => LIBS . 'Cache' . DS,
|
||||||
'controller' => LIBS . 'controller' . DS,
|
'controller' => LIBS . 'Controller' . DS,
|
||||||
'component' => LIBS . 'controller' . DS . 'components' . DS,
|
'component' => LIBS . 'Controller' . DS . 'Component' . DS,
|
||||||
'helper' => LIBS . 'view' . DS . 'helpers' . DS,
|
'helper' => LIBS . 'View' . DS . 'Helper' . DS,
|
||||||
'model' => LIBS . 'model' . DS,
|
'model' => LIBS . 'Model' . DS,
|
||||||
'view' => LIBS . 'view' . DS,
|
'view' => LIBS . 'View' . DS,
|
||||||
'core' => LIBS
|
'core' => LIBS
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class ApiShell extends Shell {
|
||||||
$class = Inflector::camelize($type);
|
$class = Inflector::camelize($type);
|
||||||
} elseif (count($this->args) > 1) {
|
} elseif (count($this->args) > 1) {
|
||||||
$file = Inflector::underscore($this->args[1]);
|
$file = Inflector::underscore($this->args[1]);
|
||||||
$class = Inflector::camelize($file);
|
$class = Inflector::camelize($this->args[1]);
|
||||||
}
|
}
|
||||||
$objects = App::objects('class', $path);
|
$objects = App::objects('class', $path);
|
||||||
if (in_array($class, $objects)) {
|
if (in_array($class, $objects)) {
|
||||||
|
@ -88,7 +88,7 @@ class ApiShell extends Shell {
|
||||||
$this->error(__('%s not found', $class));
|
$this->error(__('%s not found', $class));
|
||||||
}
|
}
|
||||||
|
|
||||||
$parsed = $this->__parseClass($path . $file .'.php', $class);
|
$parsed = $this->__parseClass($path . $class .'.php', $class);
|
||||||
|
|
||||||
if (!empty($parsed)) {
|
if (!empty($parsed)) {
|
||||||
if (isset($this->params['method'])) {
|
if (isset($this->params['method'])) {
|
||||||
|
@ -197,9 +197,12 @@ class ApiShell extends Shell {
|
||||||
function __parseClass($path, $class) {
|
function __parseClass($path, $class) {
|
||||||
$parsed = array();
|
$parsed = array();
|
||||||
|
|
||||||
|
if (!class_exists($class)) {
|
||||||
if (!include_once($path)) {
|
if (!include_once($path)) {
|
||||||
$this->err(__('%s could not be found', $path));
|
$this->err(__('%s could not be found', $path));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$reflection = new ReflectionClass($class);
|
$reflection = new ReflectionClass($class);
|
||||||
|
|
||||||
foreach ($reflection->getMethods() as $method) {
|
foreach ($reflection->getMethods() as $method) {
|
|
@ -21,6 +21,8 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @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.
|
* Bake is a command-line code generation utility for automating programmer chores.
|
||||||
*
|
*
|
||||||
|
@ -149,11 +151,11 @@ class BakeShell extends Shell {
|
||||||
|
|
||||||
$modelExists = false;
|
$modelExists = false;
|
||||||
$model = $this->_modelName($name);
|
$model = $this->_modelName($name);
|
||||||
if (App::import('Model', $model)) {
|
App::uses($model, 'Model');
|
||||||
|
if (class_exists($model)) {
|
||||||
$object = new $model();
|
$object = new $model();
|
||||||
$modelExists = true;
|
$modelExists = true;
|
||||||
} else {
|
} else {
|
||||||
App::import('Model', 'Model', false);
|
|
||||||
$object = new Model(array('name' => $name, 'ds' => $this->connection));
|
$object = new Model(array('name' => $name, 'ds' => $this->connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +176,8 @@ class BakeShell extends Shell {
|
||||||
$this->Controller->bakeTest($controller);
|
$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->args = array($controller);
|
||||||
$this->View->execute();
|
$this->View->execute();
|
||||||
}
|
}
|
|
@ -16,6 +16,8 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
App::uses('Inflector', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a list of commands available from the console.
|
* Shows a list of commands available from the console.
|
||||||
*
|
*
|
||||||
|
@ -79,17 +81,18 @@ class CommandListShell extends Shell {
|
||||||
protected function _getShellList() {
|
protected function _getShellList() {
|
||||||
$shellList = array();
|
$shellList = array();
|
||||||
|
|
||||||
$corePaths = App::core('shells');
|
$shells = App::objects('file', App::core('Console/Command'));
|
||||||
$shellList = $this->_appendShells('CORE', $corePaths, $shellList);
|
$shellList = $this->_appendShells('CORE', $shells, $shellList);
|
||||||
|
|
||||||
$appPaths = array_diff(App::path('shells'), $corePaths);
|
$appShells = App::objects('Console/Command', null, false);
|
||||||
$shellList = $this->_appendShells('app', $appPaths, $shellList);
|
$shellList = $this->_appendShells('app', $appShells, $shellList);
|
||||||
|
|
||||||
$plugins = App::objects('plugin');
|
$plugins = App::objects('plugin');
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
$pluginPath = App::pluginPath($plugin) . 'console' . DS . 'shells' . DS;
|
$pluginShells = App::objects($plugin . '.Console/Command');
|
||||||
$shellList = $this->_appendShells($plugin, array($pluginPath), $shellList);
|
$shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $shellList;
|
return $shellList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,23 +101,11 @@ class CommandListShell extends Shell {
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function _appendShells($type, $paths, $shellList) {
|
protected function _appendShells($type, $shells, $shellList) {
|
||||||
foreach ($paths as $path) {
|
|
||||||
if (!is_dir($path)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$shells = App::objects('file', $path);
|
|
||||||
|
|
||||||
if (empty($shells)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
foreach ($shells as $shell) {
|
foreach ($shells as $shell) {
|
||||||
if ($shell !== 'shell.php' && $shell !== 'app_shell.php') {
|
$shell = Inflector::underscore(str_replace('Shell', '', $shell));
|
||||||
$shell = str_replace('.php', '', $shell);
|
|
||||||
$shellList[$shell][$type] = $type;
|
$shellList[$shell][$type] = $type;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return $shellList;
|
return $shellList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,14 @@ class ConsoleShell extends Shell {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function initialize() {
|
public function initialize() {
|
||||||
require_once CAKE . 'dispatcher.php';
|
App::uses('Dispatcher', 'Routing');
|
||||||
$this->Dispatcher = new Dispatcher();
|
$this->Dispatcher = new Dispatcher();
|
||||||
$this->models = App::objects('model');
|
$this->models = App::objects('model');
|
||||||
App::import('Model', $this->models);
|
|
||||||
|
|
||||||
foreach ($this->models as $model) {
|
foreach ($this->models as $model) {
|
||||||
$class = Inflector::camelize(str_replace('.php', '', $model));
|
$class = Inflector::camelize(str_replace('.php', '', $model));
|
||||||
$this->models[$model] = $class;
|
$this->models[$model] = $class;
|
||||||
|
App::uses($class, 'Model');
|
||||||
$this->{$class} = new $class();
|
$this->{$class} = new $class();
|
||||||
}
|
}
|
||||||
$this->out('Model classes:');
|
$this->out('Model classes:');
|
||||||
|
@ -333,21 +333,20 @@ class ConsoleShell extends Shell {
|
||||||
* @return boolean True if config reload was a success, otherwise false
|
* @return boolean True if config reload was a success, otherwise false
|
||||||
*/
|
*/
|
||||||
protected function _loadRoutes() {
|
protected function _loadRoutes() {
|
||||||
$router = Router::getInstance();
|
Router::reload();
|
||||||
|
extract(Router::getNamedExpressions());
|
||||||
$router->reload();
|
|
||||||
extract($router->getNamedExpressions());
|
|
||||||
|
|
||||||
if (!@include(CONFIGS . 'routes.php')) {
|
if (!@include(CONFIGS . 'routes.php')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$router->parse('/');
|
Router::parse('/');
|
||||||
|
|
||||||
foreach (array_keys($router->getNamedExpressions()) as $var) {
|
foreach (array_keys(Router::getNamedExpressions()) as $var) {
|
||||||
unset(${$var});
|
unset(${$var});
|
||||||
}
|
}
|
||||||
for ($i = 0, $len = count($router->routes); $i < $len; $i++) {
|
|
||||||
$router->routes[$i]->compile();
|
foreach (Router::$routes as $route) {
|
||||||
|
$route->compile();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
|
@ -19,8 +19,8 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5550
|
* @since CakePHP(tm) v 1.2.0.5550
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'File', false);
|
App::uses('File', 'Utility');
|
||||||
App::import('Model', 'CakeSchema', false);
|
App::uses('CakeSchema', 'Model');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schema is a command-line database management utility for automating programmer chores.
|
* Schema is a command-line database management utility for automating programmer chores.
|
|
@ -17,7 +17,7 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
App::uses('BakeTask', 'Console/Command/Task');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task class for creating and updating controller files.
|
* Task class for creating and updating controller files.
|
||||||
|
@ -106,7 +106,8 @@ class ControllerTask extends BakeTask {
|
||||||
foreach ($this->__tables as $table) {
|
foreach ($this->__tables as $table) {
|
||||||
$model = $this->_modelName($table);
|
$model = $this->_modelName($table);
|
||||||
$controller = $this->_controllerName($model);
|
$controller = $this->_controllerName($model);
|
||||||
if (App::import('Model', $model)) {
|
App::uses($model, 'Model');
|
||||||
|
if (class_exists($model)) {
|
||||||
$actions = $this->bakeActions($controller);
|
$actions = $this->bakeActions($controller);
|
||||||
if ($this->bake($controller, $actions) && $unitTestExists) {
|
if ($this->bake($controller, $actions) && $unitTestExists) {
|
||||||
$this->bakeTest($controller);
|
$this->bakeTest($controller);
|
||||||
|
@ -142,10 +143,9 @@ class ControllerTask extends BakeTask {
|
||||||
$useDynamicScaffold = 'n';
|
$useDynamicScaffold = 'n';
|
||||||
$wannaBakeCrud = 'y';
|
$wannaBakeCrud = 'y';
|
||||||
|
|
||||||
$controllerFile = strtolower(Inflector::underscore($controllerName));
|
|
||||||
|
|
||||||
$question[] = __("Would you like to build your controller interactively?");
|
$question[] = __("Would you like to build your controller interactively?");
|
||||||
if (file_exists($this->path . $controllerFile .'_controller.php')) {
|
if (file_exists($this->path . $controllerName .'Controller.php')) {
|
||||||
$question[] = __("Warning: Choosing no will overwrite the %sController.", $controllerName);
|
$question[] = __("Warning: Choosing no will overwrite the %sController.", $controllerName);
|
||||||
}
|
}
|
||||||
$doItInteractive = $this->in(implode("\n", $question), array('y','n'), 'y');
|
$doItInteractive = $this->in(implode("\n", $question), array('y','n'), 'y');
|
||||||
|
@ -269,9 +269,10 @@ class ControllerTask extends BakeTask {
|
||||||
$currentModelName = $modelImport = $this->_modelName($controllerName);
|
$currentModelName = $modelImport = $this->_modelName($controllerName);
|
||||||
$plugin = $this->plugin;
|
$plugin = $this->plugin;
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
$modelImport = $plugin . '.' . $modelImport;
|
$plugin .= '.';
|
||||||
}
|
}
|
||||||
if (!App::import('Model', $modelImport)) {
|
App::uses($modelImport, $plugin . 'Model');
|
||||||
|
if (!class_exists($modelImport)) {
|
||||||
$this->err(__('You must have a model for this class to build basic methods. Please try again.'));
|
$this->err(__('You must have a model for this class to build basic methods. Please try again.'));
|
||||||
$this->_stop();
|
$this->_stop();
|
||||||
}
|
}
|
||||||
|
@ -313,7 +314,7 @@ class ControllerTask extends BakeTask {
|
||||||
$contents = $this->Template->generate('classes', 'controller');
|
$contents = $this->Template->generate('classes', 'controller');
|
||||||
|
|
||||||
$path = $this->getPath();
|
$path = $this->getPath();
|
||||||
$filename = $path . $this->_controllerPath($controllerName) . '_controller.php';
|
$filename = $path . $this->_controllerNames($controllerName) . 'Controller.php';
|
||||||
if ($this->createFile($filename, $contents)) {
|
if ($this->createFile($filename, $contents)) {
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
|
@ -351,7 +351,7 @@ class DbConfigTask extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getConfig() {
|
public function getConfig() {
|
||||||
App::import('Model', 'ConnectionManager', false);
|
App::uses('ConnectionManager', 'Model');
|
||||||
|
|
||||||
$useDbConfig = 'default';
|
$useDbConfig = 'default';
|
||||||
$configs = get_class_vars($this->databaseClassName);
|
$configs = get_class_vars($this->databaseClassName);
|
|
@ -16,7 +16,7 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'File');
|
App::uses('File', 'Utility');
|
||||||
/**
|
/**
|
||||||
* Language string extractor
|
* Language string extractor
|
||||||
*
|
*
|
||||||
|
@ -112,7 +112,7 @@ class ExtractTask extends Shell {
|
||||||
$this->__paths = explode(',', $this->params['paths']);
|
$this->__paths = explode(',', $this->params['paths']);
|
||||||
} else {
|
} else {
|
||||||
$defaultPath = APP_PATH;
|
$defaultPath = APP_PATH;
|
||||||
$message = __("What is the full path you would like to extract?\nExample: %s\n[Q]uit [D]one", $this->Dispatch->params['root'] . DS . 'myapp');
|
$message = __("What is the full path you would like to extract?\nExample: %s\n[Q]uit [D]one", $defaultPath);
|
||||||
while (true) {
|
while (true) {
|
||||||
$response = $this->in($message, null, $defaultPath);
|
$response = $this->in($message, null, $defaultPath);
|
||||||
if (strtoupper($response) === 'Q') {
|
if (strtoupper($response) === 'Q') {
|
|
@ -16,7 +16,10 @@
|
||||||
* @since CakePHP(tm) v 1.3
|
* @since CakePHP(tm) v 1.3
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
|
||||||
|
App::uses('BakeTask', 'Console/Command/Task');
|
||||||
|
App::uses('Model', 'Model');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task class for creating and updating fixtures files.
|
* Task class for creating and updating fixtures files.
|
||||||
*
|
*
|
||||||
|
@ -182,9 +185,7 @@ class FixtureTask extends BakeTask {
|
||||||
* @return string Baked fixture content
|
* @return string Baked fixture content
|
||||||
*/
|
*/
|
||||||
public function bake($model, $useTable = false, $importOptions = array()) {
|
public function bake($model, $useTable = false, $importOptions = array()) {
|
||||||
if (!class_exists('CakeSchema')) {
|
App::uses('CakeSchema', 'Model');
|
||||||
App::import('Model', 'CakeSchema', false);
|
|
||||||
}
|
|
||||||
$table = $schema = $records = $import = $modelImport = null;
|
$table = $schema = $records = $import = $modelImport = null;
|
||||||
$importBits = array();
|
$importBits = array();
|
||||||
|
|
||||||
|
@ -393,7 +394,6 @@ class FixtureTask extends BakeTask {
|
||||||
} else {
|
} else {
|
||||||
$condition = 'WHERE 1=1 LIMIT ' . (isset($this->params['count']) ? $this->params['count'] : 10);
|
$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));
|
$modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
|
||||||
$records = $modelObject->find('all', array(
|
$records = $modelObject->find('all', array(
|
||||||
'conditions' => $condition,
|
'conditions' => $condition,
|
|
@ -17,7 +17,10 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
App::uses('BakeTask', 'Console/Command/Task');
|
||||||
|
App::uses('ConnectionManager', 'Model');
|
||||||
|
App::uses('Model', 'Model');
|
||||||
|
App::uses('Validation', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task class for creating and updating model files.
|
* Task class for creating and updating model files.
|
||||||
|
@ -71,7 +74,6 @@ class ModelTask extends BakeTask {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function execute() {
|
public function execute() {
|
||||||
App::import('Model', 'Model', false);
|
|
||||||
parent::execute();
|
parent::execute();
|
||||||
|
|
||||||
if (empty($this->args)) {
|
if (empty($this->args)) {
|
||||||
|
@ -739,7 +741,7 @@ class ModelTask extends BakeTask {
|
||||||
$out = $this->Template->generate('classes', 'model');
|
$out = $this->Template->generate('classes', 'model');
|
||||||
|
|
||||||
$path = $this->getPath();
|
$path = $this->getPath();
|
||||||
$filename = $path . Inflector::underscore($name) . '.php';
|
$filename = $path . $name . '.php';
|
||||||
$this->out("\nBaking model class for $name...", 1, Shell::QUIET);
|
$this->out("\nBaking model class for $name...", 1, Shell::QUIET);
|
||||||
$this->createFile($filename, $out);
|
$this->createFile($filename, $out);
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
|
@ -789,7 +791,6 @@ class ModelTask extends BakeTask {
|
||||||
if (!isset($useDbConfig)) {
|
if (!isset($useDbConfig)) {
|
||||||
$useDbConfig = $this->connection;
|
$useDbConfig = $this->connection;
|
||||||
}
|
}
|
||||||
App::import('Model', 'ConnectionManager', false);
|
|
||||||
|
|
||||||
$db = ConnectionManager::getDataSource($useDbConfig);
|
$db = ConnectionManager::getDataSource($useDbConfig);
|
||||||
$useTable = Inflector::tableize($modelName);
|
$useTable = Inflector::tableize($modelName);
|
||||||
|
@ -818,7 +819,6 @@ class ModelTask extends BakeTask {
|
||||||
if (!isset($useDbConfig)) {
|
if (!isset($useDbConfig)) {
|
||||||
$useDbConfig = $this->connection;
|
$useDbConfig = $this->connection;
|
||||||
}
|
}
|
||||||
App::import('Model', 'ConnectionManager', false);
|
|
||||||
|
|
||||||
$tables = array();
|
$tables = array();
|
||||||
$db = ConnectionManager::getDataSource($useDbConfig);
|
$db = ConnectionManager::getDataSource($useDbConfig);
|
|
@ -16,7 +16,9 @@
|
||||||
* @since CakePHP(tm) v 1.2
|
* @since CakePHP(tm) v 1.2
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'File');
|
|
||||||
|
App::uses('File', 'Utility');
|
||||||
|
App::uses('Folder', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task class for creating a plugin
|
* Task class for creating a plugin
|
|
@ -17,7 +17,10 @@
|
||||||
* @since CakePHP(tm) v 1.2
|
* @since CakePHP(tm) v 1.2
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'File');
|
|
||||||
|
App::uses('File', 'Utility');
|
||||||
|
App::uses('String', 'Utility');
|
||||||
|
App::uses('Security', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task class for creating new project apps and plugins
|
* Task class for creating new project apps and plugins
|
||||||
|
@ -49,14 +52,6 @@ class ProjectTask extends Shell {
|
||||||
$project = $_SERVER['PWD'] . DS . $project;
|
$project = $_SERVER['PWD'] . DS . $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($this->params['skel'])) {
|
|
||||||
$core = App::core('shells');
|
|
||||||
$skelPath = dirname($core[0]) . DS . 'templates' . DS . 'skel';
|
|
||||||
if (is_dir($skelPath) === true) {
|
|
||||||
$this->params['skel'] = $skelPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!$project) {
|
while (!$project) {
|
||||||
$prompt = __("What is the full path for this app including the app directory name?\n Example:");
|
$prompt = __("What is the full path for this app including the app directory name?\n Example:");
|
||||||
$default = APP_PATH . 'myapp';
|
$default = APP_PATH . 'myapp';
|
||||||
|
@ -236,9 +231,6 @@ 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('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
if (preg_match('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
||||||
if (!class_exists('Security')) {
|
|
||||||
require LIBS . 'security.php';
|
|
||||||
}
|
|
||||||
$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)) {
|
||||||
|
@ -387,6 +379,7 @@ class ProjectTask extends Shell {
|
||||||
))->addOption('empty', array(
|
))->addOption('empty', array(
|
||||||
'help' => __('Create empty files in each of the directories. Good if you are using git')
|
'help' => __('Create empty files in each of the directories. Good if you are using git')
|
||||||
))->addOption('skel', array(
|
))->addOption('skel', array(
|
||||||
|
'default' => current(App::core('Console')) . DS . 'templates' . DS . 'skel',
|
||||||
'help' => __('The directory layout to use for the new application skeleton. Defaults to cake/console/templates/skel of CakePHP used to create the project.')
|
'help' => __('The directory layout to use for the new application skeleton. Defaults to cake/console/templates/skel of CakePHP used to create the project.')
|
||||||
));
|
));
|
||||||
}
|
}
|
|
@ -16,7 +16,8 @@
|
||||||
* @since CakePHP(tm) v 1.3
|
* @since CakePHP(tm) v 1.3
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'Folder');
|
|
||||||
|
App::uses('Folder', 'Utility');
|
||||||
|
|
||||||
class TemplateTask extends Shell {
|
class TemplateTask extends Shell {
|
||||||
|
|
||||||
|
@ -53,8 +54,8 @@ class TemplateTask extends Shell {
|
||||||
* @return array Array of bake themes that are installed.
|
* @return array Array of bake themes that are installed.
|
||||||
*/
|
*/
|
||||||
protected function _findThemes() {
|
protected function _findThemes() {
|
||||||
$paths = App::path('shells');
|
$paths = App::path('Console');
|
||||||
$core = array_pop($paths);
|
$core = current(App::core('Console'));
|
||||||
$separator = DS === '/' ? '/' : '\\\\';
|
$separator = DS === '/' ? '/' : '\\\\';
|
||||||
$core = preg_replace('#shells' . $separator . '$#', '', $core);
|
$core = preg_replace('#shells' . $separator . '$#', '', $core);
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
App::uses('BakeTask', 'Console/Command/Task');
|
||||||
App::import('Model', 'ClassRegistry');
|
App::uses('ClassRegistry', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task class for creating and updating test files.
|
* Task class for creating and updating test files.
|
|
@ -16,8 +16,9 @@
|
||||||
* @since CakePHP(tm) v 1.2
|
* @since CakePHP(tm) v 1.2
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Controller', 'Controller', false);
|
|
||||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
App::uses('Controller', 'Controller');
|
||||||
|
App::uses('BakeTask', 'Console/Command/Task');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task class for creating and updating view files.
|
* Task class for creating and updating view files.
|
||||||
|
@ -146,7 +147,7 @@ class ViewTask extends BakeTask {
|
||||||
protected function _methodsToBake() {
|
protected function _methodsToBake() {
|
||||||
$methods = array_diff(
|
$methods = array_diff(
|
||||||
array_map('strtolower', get_class_methods($this->controllerName . 'Controller')),
|
array_map('strtolower', get_class_methods($this->controllerName . 'Controller')),
|
||||||
array_map('strtolower', get_class_methods('appcontroller'))
|
array_map('strtolower', get_class_methods('AppController'))
|
||||||
);
|
);
|
||||||
$scaffoldActions = false;
|
$scaffoldActions = false;
|
||||||
if (empty($methods)) {
|
if (empty($methods)) {
|
||||||
|
@ -188,7 +189,8 @@ class ViewTask extends BakeTask {
|
||||||
$model = $this->_modelName($table);
|
$model = $this->_modelName($table);
|
||||||
$this->controllerName = $this->_controllerName($model);
|
$this->controllerName = $this->_controllerName($model);
|
||||||
$this->controllerPath = Inflector::underscore($this->controllerName);
|
$this->controllerPath = Inflector::underscore($this->controllerName);
|
||||||
if (App::import('Model', $model)) {
|
App::uses($model, 'Model');
|
||||||
|
if (class_exists($model)) {
|
||||||
$vars = $this->__loadController();
|
$vars = $this->__loadController();
|
||||||
if (!$actions) {
|
if (!$actions) {
|
||||||
$actions = $this->_methodsToBake();
|
$actions = $this->_methodsToBake();
|
||||||
|
@ -269,17 +271,18 @@ class ViewTask extends BakeTask {
|
||||||
$this->err(__('Controller not found'));
|
$this->err(__('Controller not found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$import = $this->controllerName;
|
$plugin = null;
|
||||||
if ($this->plugin) {
|
if ($this->plugin) {
|
||||||
$import = $this->plugin . '.' . $this->controllerName;
|
$plugin = $this->plugin . '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!App::import('Controller', $import)) {
|
$controllerClassName = $this->controllerName . 'Controller';
|
||||||
$file = $this->controllerPath . '_controller.php';
|
App::uses($controllerClassName, $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->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();
|
$this->_stop();
|
||||||
}
|
}
|
||||||
$controllerClassName = $this->controllerName . 'Controller';
|
|
||||||
$controllerObj = new $controllerClassName();
|
$controllerObj = new $controllerClassName();
|
||||||
$controllerObj->plugin = $this->plugin;
|
$controllerObj->plugin = $this->plugin;
|
||||||
$controllerObj->constructClasses();
|
$controllerObj->constructClasses();
|
|
@ -18,7 +18,13 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.4433
|
* @since CakePHP(tm) v 1.2.0.4433
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
class TestSuiteShell extends Shell {
|
|
||||||
|
App::uses('Shell', 'Console');
|
||||||
|
App::uses('CakeTestSuiteDispatcher', 'TestSuite');
|
||||||
|
App::uses('CakeTestSuiteCommand', 'TestSuite');
|
||||||
|
App::uses('CakeTestLoader', 'TestSuite');
|
||||||
|
|
||||||
|
class TestsuiteShell extends Shell {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatcher object for the run.
|
* Dispatcher object for the run.
|
||||||
|
@ -131,7 +137,7 @@ class TestSuiteShell extends Shell {
|
||||||
))->addOption('bootstrap', array(
|
))->addOption('bootstrap', array(
|
||||||
'help' => __('<file> A "bootstrap" PHP file that is run before the tests.'),
|
'help' => __('<file> A "bootstrap" PHP file that is run before the tests.'),
|
||||||
'default' => false
|
'default' => false
|
||||||
))->addOption('configuraion', array(
|
))->addOption('configuration', array(
|
||||||
'help' => __('<file> Read configuration from XML file.'),
|
'help' => __('<file> Read configuration from XML file.'),
|
||||||
'default' => false
|
'default' => false
|
||||||
))->addOption('no-configuration', array(
|
))->addOption('no-configuration', array(
|
||||||
|
@ -156,18 +162,8 @@ class TestSuiteShell extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function initialize() {
|
public function initialize() {
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_dispatcher.php';
|
|
||||||
|
|
||||||
$corePath = App::core('cake');
|
|
||||||
if (isset($corePath[0])) {
|
|
||||||
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
|
|
||||||
} else {
|
|
||||||
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
||||||
$this->_dispatcher->loadTestFramework();
|
$this->_dispatcher->loadTestFramework();
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_command.php';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -256,7 +252,6 @@ class TestSuiteShell extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function run($runnerArgs, $options = array()) {
|
protected function run($runnerArgs, $options = array()) {
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
|
@ -16,8 +16,9 @@
|
||||||
* @since CakePHP(tm) v 2.0
|
* @since CakePHP(tm) v 2.0
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'ErrorHandler');
|
App::uses('ErrorHandler', 'Error');
|
||||||
require_once 'console_output.php';
|
App::uses('ConsoleOutput', 'Console');
|
||||||
|
App::uses('CakeLog', 'Log');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error Handler for Cake console. Does simple printing of the
|
* Error Handler for Cake console. Does simple printing of the
|
||||||
|
@ -83,7 +84,6 @@ class ConsoleErrorHandler extends ErrorHandler {
|
||||||
$stderr->write(__("<error>%s Error:</error> %s\n", $name, $message));
|
$stderr->write(__("<error>%s Error:</error> %s\n", $name, $message));
|
||||||
|
|
||||||
if (Configure::read('debug') == 0) {
|
if (Configure::read('debug') == 0) {
|
||||||
App::import('Core', 'CakeLog');
|
|
||||||
CakeLog::write($log, $message);
|
CakeLog::write($log, $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,10 +16,15 @@
|
||||||
* @since CakePHP(tm) v 2.0
|
* @since CakePHP(tm) v 2.0
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
require_once CONSOLE_LIBS . 'console_input_option.php';
|
|
||||||
require_once CONSOLE_LIBS . 'console_input_argument.php';
|
App::uses('TaskCollection', 'Console');
|
||||||
require_once CONSOLE_LIBS . 'console_input_subcommand.php';
|
App::uses('ConsoleOutput', 'Console');
|
||||||
require_once CONSOLE_LIBS . 'help_formatter.php';
|
App::uses('ConsoleInput', 'Console');
|
||||||
|
App::uses('ConsoleInputSubcommand', 'Console');
|
||||||
|
App::uses('ConsoleInputOption', 'Console');
|
||||||
|
App::uses('ConsoleInputArgument', 'Console');
|
||||||
|
App::uses('ConsoleOptionParser', 'Console');
|
||||||
|
App::uses('HelpFormatter', 'Console');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles parsing the ARGV in the command line and provides support
|
* Handles parsing the ARGV in the command line and provides support
|
|
@ -14,7 +14,7 @@
|
||||||
* @link http://cakephp.org CakePHP(tm) Project
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'String', false);
|
App::uses('String', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HelpFormatter formats help for console shells. Can format to either
|
* HelpFormatter formats help for console shells. Can format to either
|
|
@ -16,10 +16,13 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
require_once CONSOLE_LIBS . 'task_collection.php';
|
|
||||||
require_once CONSOLE_LIBS . 'console_output.php';
|
App::uses('TaskCollection', 'Console');
|
||||||
require_once CONSOLE_LIBS . 'console_input.php';
|
App::uses('ConsoleOutput', 'Console');
|
||||||
require_once CONSOLE_LIBS . 'console_option_parser.php';
|
App::uses('ConsoleInput', 'Console');
|
||||||
|
App::uses('ConsoleInputSubcommand', 'Console');
|
||||||
|
App::uses('ConsoleOptionParser', 'Console');
|
||||||
|
App::uses('File', 'Utility');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for command-line utilities for automating programmer chores.
|
* Base class for command-line utilities for automating programmer chores.
|
||||||
|
@ -607,10 +610,6 @@ class Shell extends Object {
|
||||||
$this->out(__('Creating file %s', $path));
|
$this->out(__('Creating file %s', $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists('File')) {
|
|
||||||
require LIBS . 'file.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($File = new File($path, true)) {
|
if ($File = new File($path, true)) {
|
||||||
$data = $File->prepare($contents);
|
$data = $File->prepare($contents);
|
||||||
$File->write($data);
|
$File->write($data);
|
||||||
|
@ -664,7 +663,7 @@ class Shell extends Object {
|
||||||
* @return string Path to controller
|
* @return string Path to controller
|
||||||
*/
|
*/
|
||||||
protected function _controllerPath($name) {
|
protected function _controllerPath($name) {
|
||||||
return strtolower(Inflector::underscore($name));
|
return Inflector::underscore($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -127,17 +127,17 @@ class ShellDispatcher {
|
||||||
define('APP_PATH', $this->params['working'] . DS);
|
define('APP_PATH', $this->params['working'] . DS);
|
||||||
define('WWW_ROOT', APP_PATH . $this->params['webroot'] . DS);
|
define('WWW_ROOT', APP_PATH . $this->params['webroot'] . DS);
|
||||||
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
|
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
|
||||||
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'tmp' . DS);
|
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'templates' . DS . 'skel' . DS . 'tmp' . DS);
|
||||||
}
|
}
|
||||||
|
|
||||||
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'config' . DS . 'bootstrap.php');
|
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'config' . DS . 'bootstrap.php');
|
||||||
require CORE_PATH . 'cake' . DS . 'bootstrap.php';
|
require CORE_PATH . 'Cake' . DS . 'bootstrap.php';
|
||||||
|
|
||||||
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
|
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
|
||||||
include_once CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
|
include_once CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
|
||||||
App::build();
|
App::build();
|
||||||
}
|
}
|
||||||
require_once CONSOLE_LIBS . 'console_error_handler.php';
|
require_once CONSOLE_LIBS . 'ConsoleErrorHandler.php';
|
||||||
set_exception_handler(array('ConsoleErrorHandler', 'handleException'));
|
set_exception_handler(array('ConsoleErrorHandler', 'handleException'));
|
||||||
set_error_handler(array('ConsoleErrorHandler', 'handleError'), Configure::read('Error.level'));
|
set_error_handler(array('ConsoleErrorHandler', 'handleError'), Configure::read('Error.level'));
|
||||||
|
|
||||||
|
@ -207,14 +207,14 @@ class ShellDispatcher {
|
||||||
protected function _getShell($shell) {
|
protected function _getShell($shell) {
|
||||||
list($plugin, $shell) = pluginSplit($shell, true);
|
list($plugin, $shell) = pluginSplit($shell, true);
|
||||||
|
|
||||||
$loaded = App::import('Shell', $plugin . $shell);
|
|
||||||
$class = Inflector::camelize($shell) . 'Shell';
|
$class = Inflector::camelize($shell) . 'Shell';
|
||||||
|
|
||||||
if (!$loaded) {
|
App::uses('Shell', 'Console');
|
||||||
throw new MissingShellFileException(array('shell' => $shell));
|
App::uses($class, $plugin . 'Console/Command');
|
||||||
}
|
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
throw new MissingShellClassException(array('shell' => $class));
|
throw new MissingShellFileException(array('shell' => $shell));
|
||||||
}
|
}
|
||||||
$Shell = new $class();
|
$Shell = new $class();
|
||||||
return $Shell;
|
return $Shell;
|
|
@ -15,6 +15,9 @@
|
||||||
* @since CakePHP(tm) v 2.0
|
* @since CakePHP(tm) v 2.0
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
App::uses('ObjectCollection', 'Utility');
|
||||||
|
|
||||||
class TaskCollection extends ObjectCollection {
|
class TaskCollection extends ObjectCollection {
|
||||||
/**
|
/**
|
||||||
* Shell to use to set params to tasks.
|
* Shell to use to set params to tasks.
|
||||||
|
@ -57,10 +60,8 @@ class TaskCollection extends ObjectCollection {
|
||||||
}
|
}
|
||||||
$taskFile = Inflector::underscore($name);
|
$taskFile = Inflector::underscore($name);
|
||||||
$taskClass = $name . 'Task';
|
$taskClass = $name . 'Task';
|
||||||
|
App::uses($taskClass, $plugin . 'Console/Command/Task');
|
||||||
if (!class_exists($taskClass)) {
|
if (!class_exists($taskClass)) {
|
||||||
if (!App::import('Shell', $plugin . $this->taskPathPrefix . $name)) {
|
|
||||||
throw new MissingTaskFileException($taskFile . '.php');
|
|
||||||
}
|
|
||||||
if (!class_exists($taskClass)) {
|
if (!class_exists($taskClass)) {
|
||||||
throw new MissingTaskClassException($taskClass);
|
throw new MissingTaskClassException($taskClass);
|
||||||
}
|
}
|
|
@ -19,6 +19,6 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR. 'shell_dispatcher.php');
|
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR. 'ShellDispatcher.php');
|
||||||
|
|
||||||
return ShellDispatcher::run($argv);
|
return ShellDispatcher::run($argv);
|
|
@ -20,7 +20,7 @@
|
||||||
echo "<?php\n";
|
echo "<?php\n";
|
||||||
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n";
|
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n";
|
||||||
?>
|
?>
|
||||||
App::import('<?php echo $type; ?>', '<?php echo $plugin . $className;?>');
|
App::uses('<?php echo $fullClassName; ?>', '<?php echo $plugin . $type;?>');
|
||||||
|
|
||||||
<?php if ($mock and strtolower($type) == 'controller'): ?>
|
<?php if ($mock and strtolower($type) == 'controller'): ?>
|
||||||
/**
|
/**
|
|
@ -2,7 +2,7 @@
|
||||||
$output = "<h2>Sweet, \"" . Inflector::humanize($app) . "\" got Baked by CakePHP!</h2>\n";
|
$output = "<h2>Sweet, \"" . Inflector::humanize($app) . "\" got Baked by CakePHP!</h2>\n";
|
||||||
$output .="
|
$output .="
|
||||||
<?php
|
<?php
|
||||||
App::import('Core', 'Debugger');
|
App::uses('Debugger', 'Utility');
|
||||||
if (Configure::read() > 0):
|
if (Configure::read() > 0):
|
||||||
Debugger::checkSecurityKeys();
|
Debugger::checkSecurityKeys();
|
||||||
endif;
|
endif;
|
||||||
|
@ -52,16 +52,17 @@ endif;
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
if (!empty(\$filePresent)):
|
if (isset(\$filePresent)):
|
||||||
if (!class_exists('ConnectionManager')) {
|
App::uses('ConnectionManager', 'Model');
|
||||||
require LIBS . 'model' . DS . 'connection_manager.php';
|
try {
|
||||||
|
\$connected = ConnectionManager::getDataSource('default');
|
||||||
|
} catch (Exception \$e) {
|
||||||
|
\$connected = false;
|
||||||
}
|
}
|
||||||
\$db = ConnectionManager::getInstance();
|
|
||||||
\$connected = \$db->getDataSource('default');
|
|
||||||
?>
|
?>
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
if (\$connected->isConnected()):
|
if (\$connected && \$connected->isConnected()):
|
||||||
echo '<span class=\"notice success\">';
|
echo '<span class=\"notice success\">';
|
||||||
echo __('Cake is able to connect to the database.');
|
echo __('Cake is able to connect to the database.');
|
||||||
echo '</span>';
|
echo '</span>';
|
||||||
|
@ -71,8 +72,18 @@ if (!empty(\$filePresent)):
|
||||||
echo '</span>';
|
echo '</span>';
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
</p>\n";
|
</p>
|
||||||
$output .= "<?php endif;?>\n";
|
<?php endif;?>
|
||||||
|
<?php
|
||||||
|
App::uses('Validation', 'Utility');
|
||||||
|
if (!Validation::alphaNumeric('cakephp')) {
|
||||||
|
echo '<p><span class=\"notice\">';
|
||||||
|
__('PCRE has not been compiled with Unicode support.');
|
||||||
|
echo '<br/>';
|
||||||
|
__('Recompile PCRE with Unicode support by adding <code>--enable-unicode-properties</code> when configuring');
|
||||||
|
echo '</span></p>';
|
||||||
|
}
|
||||||
|
?>\n";
|
||||||
$output .= "<h3><?php echo __('Editing this Page') ?></h3>\n";
|
$output .= "<h3><?php echo __('Editing this Page') ?></h3>\n";
|
||||||
$output .= "<p>\n";
|
$output .= "<p>\n";
|
||||||
$output .= "<?php\n";
|
$output .= "<?php\n";
|
|
@ -28,15 +28,15 @@
|
||||||
* You can specify multiple configurations for production, development and testing.
|
* You can specify multiple configurations for production, development and testing.
|
||||||
*
|
*
|
||||||
* driver => The name of a supported driver; valid options are as follows:
|
* driver => The name of a supported driver; valid options are as follows:
|
||||||
* mysql - MySQL 4 & 5,
|
* Datasabe/Mysql - MySQL 4 & 5,
|
||||||
* sqlite - SQLite (PHP5 only),
|
* Datasabe/Sqlite - SQLite (PHP5 only),
|
||||||
* postgres - PostgreSQL 7 and higher,
|
* Datasabe/Postgres - PostgreSQL 7 and higher,
|
||||||
* mssql - Microsoft SQL Server 2000 and higher,
|
* Datasabe/Mssql - Microsoft SQL Server 2000 and higher,
|
||||||
* oracle - Oracle 8 and higher
|
* Datasabe/Oracle - Oracle 8 and higher
|
||||||
*
|
*
|
||||||
* You can add custom database drivers (or override existing drivers) by adding the
|
* You can add custom database drivers (or override existing drivers) by adding the
|
||||||
* appropriate file to app/models/datasources/dbo. Drivers should be named 'dbo_x.php',
|
* appropriate file to app/models/datasources/database. Drivers should be named 'MyDriver.php',
|
||||||
* where 'x' is the name of the database.
|
*
|
||||||
*
|
*
|
||||||
* persistent => true / false
|
* persistent => true / false
|
||||||
* Determines whether or not the database should use a persistent connection
|
* Determines whether or not the database should use a persistent connection
|
||||||
|
@ -49,18 +49,17 @@
|
||||||
* on a per-table basis with the Model::$tablePrefix property.
|
* on a per-table basis with the Model::$tablePrefix property.
|
||||||
*
|
*
|
||||||
* schema =>
|
* schema =>
|
||||||
* For Postgresspecifies which schema you would like to use the tables in. Postgres defaults to
|
* For Postgres specifies which schema you would like to use the tables in. Postgres defaults to 'public'.
|
||||||
* 'public', DB2 defaults to empty.
|
|
||||||
*
|
*
|
||||||
* encoding =>
|
* encoding =>
|
||||||
* For MySQL, Postgres and Sqlite, specifies the character encoding to use when connecting to the
|
* For MySQL, Postgres specifies the character encoding to use when connecting to the
|
||||||
* database. Uses database default.
|
* database. Uses database default not specified.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DATABASE_CONFIG {
|
class DATABASE_CONFIG {
|
||||||
|
|
||||||
public $default = array(
|
public $default = array(
|
||||||
'driver' => 'mysql',
|
'datasource' => 'Database/Mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
||||||
|
@ -70,7 +69,7 @@ class DATABASE_CONFIG {
|
||||||
);
|
);
|
||||||
|
|
||||||
public $test = array(
|
public $test = array(
|
||||||
'driver' => 'mysql',
|
'datasource' => 'Database/Mysql',
|
||||||
'persistent' => false,
|
'persistent' => false,
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'login' => 'user',
|
'login' => 'user',
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue