mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge remote-tracking branch 'origin/2.0' into 2.0-upgrade
This commit is contained in:
commit
215445c32d
868 changed files with 14527 additions and 11987 deletions
|
@ -25,7 +25,7 @@
|
|||
SET app=%0
|
||||
SET lib=%~dp0
|
||||
|
||||
php -q "%lib%cake.php" -working "%CD%" %*
|
||||
php -q "%lib%cake.php" -working "%CD% " %*
|
||||
|
||||
echo.
|
||||
|
2
app/console/cake.php → app/Console/cake.php
Executable file → Normal file
2
app/console/cake.php → app/Console/cake.php
Executable file → Normal file
|
@ -19,6 +19,6 @@
|
|||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @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);
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php
|
||||
* This file is loaded automatically by the app/webroot/index.php file after core.php
|
||||
*
|
||||
* This is an application wide file to load any function that is not used within a class
|
||||
* define. You can also use this to include or require any files in your application.
|
||||
* This file should load/create any application wide configuration settings, such as
|
||||
* Caching, Logging, loading additional configuration files.
|
||||
*
|
||||
* You should also use this file to include any files that provide global functions/constants
|
||||
* that your application uses.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
|
@ -20,9 +23,11 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
// Setup a 'default' cache configuration for use in the application.
|
||||
Cache::config('default', array('engine' => 'File'));
|
||||
|
||||
/**
|
||||
* The settings below can be used to set additional paths to models, views and controllers.
|
||||
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
||||
*
|
||||
* App::build(array(
|
||||
* 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
|
||||
|
|
|
@ -283,4 +283,40 @@
|
|||
* ));
|
||||
*
|
||||
*/
|
||||
Cache::config('default', array('engine' => 'File'));
|
||||
|
||||
// Pick the caching engine to use. If APC is enabled use it.
|
||||
$engine = 'File';
|
||||
if (extension_loaded('apc')) {
|
||||
$engine = 'Apc';
|
||||
}
|
||||
|
||||
// In development mode, caches should expire quickly.
|
||||
$duration = '+999 days';
|
||||
if (Configure::read('debug') >= 1) {
|
||||
$duration = '+10 seconds';
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the cache used for general framework caching. Path information,
|
||||
* object listings, and translation cache files are stored with this configuration.
|
||||
*/
|
||||
Cache::config('_cake_core_', array(
|
||||
'engine' => $engine,
|
||||
'prefix' => 'cake_core_',
|
||||
'path' => CACHE . 'persistent' . DS,
|
||||
'serialize' => ($engine === 'File'),
|
||||
'duration' => $duration
|
||||
));
|
||||
|
||||
/**
|
||||
* Configure the cache for model, and datasource caches. This cache configuration
|
||||
* is used to store schema descriptions, and table listings in connections.
|
||||
*/
|
||||
Cache::config('_cake_model_', array(
|
||||
'engine' => $engine,
|
||||
'prefix' => 'cake_model_',
|
||||
'path' => CACHE . 'models' . DS,
|
||||
'serialize' => ($engine === 'File'),
|
||||
'duration' => $duration
|
||||
));
|
||||
|
||||
|
|
|
@ -28,40 +28,38 @@
|
|||
* You can specify multiple configurations for production, development and testing.
|
||||
*
|
||||
* driver => The name of a supported driver; valid options are as follows:
|
||||
* mysql - MySQL 4 & 5,
|
||||
* mysqli - MySQL 4 & 5 Improved Interface (PHP5 only),
|
||||
* sqlite - SQLite (PHP5 only),
|
||||
* postgres - PostgreSQL 7 and higher,
|
||||
* mssql - Microsoft SQL Server 2000 and higher,
|
||||
* oracle - Oracle 8 and higher
|
||||
* Datasabe/Mysql - MySQL 4 & 5,
|
||||
* Datasabe/Sqlite - SQLite (PHP5 only),
|
||||
* Datasabe/Postgres - PostgreSQL 7 and higher,
|
||||
* Datasabe/Mssql - Microsoft SQL Server 2000 and higher,
|
||||
* Datasabe/Oracle - Oracle 8 and higher
|
||||
*
|
||||
* 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',
|
||||
* where 'x' is the name of the database.
|
||||
* appropriate file to app/models/datasources/database. Drivers should be named 'MyDriver.php',
|
||||
*
|
||||
*
|
||||
* persistent => true / false
|
||||
* Determines whether or not the database should use a persistent connection
|
||||
*
|
||||
* host =>
|
||||
* the host you connect to the database. To add a socket or port number, use 'port' => #
|
||||
* the host you connect to the database. To add a socket or port number, use 'port' => #
|
||||
*
|
||||
* prefix =>
|
||||
* Uses the given prefix for all the tables in this database. This setting can be overridden
|
||||
* on a per-table basis with the Model::$tablePrefix property.
|
||||
*
|
||||
* schema =>
|
||||
* For Postgresspecifies which schema you would like to use the tables in. Postgres defaults to
|
||||
* 'public', DB2 defaults to empty.
|
||||
* For Postgres specifies which schema you would like to use the tables in. Postgres defaults to 'public'.
|
||||
*
|
||||
* encoding =>
|
||||
* For MySQL, MySQLi, Postgres specifies the character encoding to use when connecting to the
|
||||
* database. Uses database default.
|
||||
* For MySQL, Postgres specifies the character encoding to use when connecting to the
|
||||
* database. Uses database default not specified.
|
||||
*
|
||||
*/
|
||||
class DATABASE_CONFIG {
|
||||
|
||||
public $default = array(
|
||||
'driver' => 'mysql',
|
||||
'datasource' => 'Database/Mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
|
@ -71,7 +69,7 @@ class DATABASE_CONFIG {
|
|||
);
|
||||
|
||||
public $test = array(
|
||||
'driver' => 'mysql',
|
||||
'datasource' => 'Database/Mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
|
|
|
@ -27,15 +27,6 @@
|
|||
*/
|
||||
class DbAclSchema extends CakeSchema {
|
||||
|
||||
public $name = 'DbAcl';
|
||||
|
||||
function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function after($event = array()) {
|
||||
}
|
||||
|
||||
public $acos = array(
|
||||
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
|
||||
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
|
||||
|
|
|
@ -27,15 +27,6 @@
|
|||
*/
|
||||
class i18nSchema extends CakeSchema {
|
||||
|
||||
public $name = 'i18n';
|
||||
|
||||
function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function after($event = array()) {
|
||||
}
|
||||
|
||||
public $i18n = array(
|
||||
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
|
||||
'locale' => array('type'=>'string', 'null' => false, 'length' => 6, 'key' => 'index'),
|
||||
|
|
|
@ -27,15 +27,6 @@
|
|||
*/
|
||||
class SessionsSchema extends CakeSchema {
|
||||
|
||||
public $name = 'Sessions';
|
||||
|
||||
function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function after($event = array()) {
|
||||
}
|
||||
|
||||
public $cake_sessions = array(
|
||||
'id' => array('type'=>'string', 'null' => false, 'key' => 'primary'),
|
||||
'data' => array('type'=>'text', 'null' => true, 'default' => NULL),
|
||||
|
|
0
app/tmp/cache/models/empty
vendored
Executable file → Normal file
0
app/tmp/cache/models/empty
vendored
Executable file → Normal file
0
app/tmp/cache/views/empty
vendored
Executable file → Normal file
0
app/tmp/cache/views/empty
vendored
Executable file → Normal file
0
app/tmp/logs/empty
Executable file → Normal file
0
app/tmp/logs/empty
Executable file → Normal file
0
app/tmp/sessions/empty
Executable file → Normal file
0
app/tmp/sessions/empty
Executable file → Normal file
0
app/tmp/tests/empty
Executable file → Normal file
0
app/tmp/tests/empty
Executable file → Normal file
|
@ -2,5 +2,5 @@
|
|||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
|
||||
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
|
||||
</IfModule>
|
|
@ -49,7 +49,7 @@
|
|||
*
|
||||
*/
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||
define('CAKE_CORE_INCLUDE_PATH', ROOT);
|
||||
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,13 +67,14 @@
|
|||
define('APP_PATH', ROOT . DS . APP_DIR . 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);
|
||||
}
|
||||
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
|
||||
|
||||
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') {
|
||||
return;
|
||||
} else {
|
||||
require LIBS . 'dispatcher.php';
|
||||
$Dispatcher = new Dispatcher();
|
||||
$Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null));
|
||||
}
|
||||
|
||||
App::uses('Dispatcher', 'Routing');
|
||||
$Dispatcher = new Dispatcher();
|
||||
$Dispatcher->dispatch(new CakeRequest());
|
||||
|
|
|
@ -45,11 +45,11 @@ ini_set('display_errors', 1);
|
|||
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')) {
|
||||
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('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);
|
||||
}
|
||||
|
||||
$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) {
|
||||
die(__('Debug setting does not allow access to this url.', true));
|
||||
die(__d('cake', '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();
|
||||
|
|
|
@ -1,38 +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 . '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,887 +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
|
||||
)));
|
||||
self::${$type} = array_values($path);
|
||||
} 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');`
|
||||
*
|
||||
* @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;
|
||||
$name = $type;
|
||||
|
||||
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;
|
||||
}
|
||||
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)) {
|
||||
$this->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,946 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Authentication component
|
||||
*
|
||||
* Manages user logins and permissions.
|
||||
*
|
||||
* 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.controller.components
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::import('Core', 'Router', false);
|
||||
App::import('Core', 'Security', false);
|
||||
|
||||
/**
|
||||
* Authentication control component class
|
||||
*
|
||||
* Binds access control with user authentication and session management.
|
||||
*
|
||||
* @package cake.libs.controller.components
|
||||
* @link http://book.cakephp.org/view/1250/Authentication
|
||||
*/
|
||||
class AuthComponent extends Component {
|
||||
|
||||
/**
|
||||
* Maintains current user login state.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_loggedIn = false;
|
||||
|
||||
/**
|
||||
* Other components utilized by AuthComponent
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('Session', 'RequestHandler');
|
||||
|
||||
/**
|
||||
* A reference to the object used for authentication
|
||||
*
|
||||
* @var object
|
||||
* @link http://book.cakephp.org/view/1278/authenticate
|
||||
*/
|
||||
public $authenticate = null;
|
||||
|
||||
/**
|
||||
* The name of the component to use for Authorization or set this to
|
||||
* 'controller' will validate against Controller::isAuthorized()
|
||||
* 'actions' will validate Controller::action against an AclComponent::check()
|
||||
* 'crud' will validate mapActions against an AclComponent::check()
|
||||
* array('model'=> 'name'); will validate mapActions against model $name::isAuthorized(user, controller, mapAction)
|
||||
* 'object' will validate Controller::action against object::isAuthorized(user, controller, action)
|
||||
*
|
||||
* @var mixed
|
||||
* @link http://book.cakephp.org/view/1275/authorize
|
||||
*/
|
||||
public $authorize = false;
|
||||
|
||||
/**
|
||||
* The name of an optional view element to render when an Ajax request is made
|
||||
* with an invalid or expired session
|
||||
*
|
||||
* @var string
|
||||
* @link http://book.cakephp.org/view/1277/ajaxLogin
|
||||
*/
|
||||
public $ajaxLogin = null;
|
||||
|
||||
/**
|
||||
* The name of the element used for SessionComponent::setFlash
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $flashElement = 'default';
|
||||
|
||||
/**
|
||||
* The name of the model that represents users which will be authenticated. Defaults to 'User'.
|
||||
*
|
||||
* @var string
|
||||
* @link http://book.cakephp.org/view/1266/userModel
|
||||
*/
|
||||
public $userModel = 'User';
|
||||
|
||||
/**
|
||||
* Additional query conditions to use when looking up and authenticating users,
|
||||
* i.e. array('User.is_active' => 1).
|
||||
*
|
||||
* @var array
|
||||
* @link http://book.cakephp.org/view/1268/userScope
|
||||
*/
|
||||
public $userScope = array();
|
||||
|
||||
/**
|
||||
* Allows you to specify non-default login name and password fields used in
|
||||
* $userModel, i.e. array('username' => 'login_name', 'password' => 'passwd').
|
||||
*
|
||||
* @var array
|
||||
* @link http://book.cakephp.org/view/1267/fields
|
||||
*/
|
||||
public $fields = array('username' => 'username', 'password' => 'password');
|
||||
|
||||
/**
|
||||
* The session key name where the record of the current user is stored. If
|
||||
* unspecified, it will be "Auth.{$userModel name}".
|
||||
*
|
||||
* @var string
|
||||
* @link http://book.cakephp.org/view/1276/sessionKey
|
||||
*/
|
||||
public $sessionKey = null;
|
||||
|
||||
/**
|
||||
* If using action-based access control, this defines how the paths to action
|
||||
* ACO nodes is computed. If, for example, all controller nodes are nested
|
||||
* under an ACO node named 'Controllers', $actionPath should be set to
|
||||
* "Controllers/".
|
||||
*
|
||||
* @var string
|
||||
* @link http://book.cakephp.org/view/1279/actionPath
|
||||
*/
|
||||
public $actionPath = null;
|
||||
|
||||
/**
|
||||
* A URL (defined as a string or array) to the controller action that handles
|
||||
* logins.
|
||||
*
|
||||
* @var mixed
|
||||
* @link http://book.cakephp.org/view/1269/loginAction
|
||||
*/
|
||||
public $loginAction = null;
|
||||
|
||||
/**
|
||||
* Normally, if a user is redirected to the $loginAction page, the location they
|
||||
* were redirected from will be stored in the session so that they can be
|
||||
* redirected back after a successful login. If this session value is not
|
||||
* set, the user will be redirected to the page specified in $loginRedirect.
|
||||
*
|
||||
* @var mixed
|
||||
* @link http://book.cakephp.org/view/1270/loginRedirect
|
||||
*/
|
||||
public $loginRedirect = null;
|
||||
|
||||
/**
|
||||
* The default action to redirect to after the user is logged out. While AuthComponent does
|
||||
* not handle post-logout redirection, a redirect URL will be returned from AuthComponent::logout().
|
||||
* Defaults to AuthComponent::$loginAction.
|
||||
*
|
||||
* @var mixed
|
||||
* @see AuthComponent::$loginAction
|
||||
* @see AuthComponent::logout()
|
||||
* @link http://book.cakephp.org/view/1271/logoutRedirect
|
||||
*/
|
||||
public $logoutRedirect = null;
|
||||
|
||||
/**
|
||||
* The name of model or model object, or any other object has an isAuthorized method.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $object = null;
|
||||
|
||||
/**
|
||||
* Error to display when user login fails. For security purposes, only one error is used for all
|
||||
* login failures, so as not to expose information on why the login failed.
|
||||
*
|
||||
* @var string
|
||||
* @link http://book.cakephp.org/view/1272/loginError
|
||||
*/
|
||||
public $loginError = null;
|
||||
|
||||
/**
|
||||
* Error to display when user attempts to access an object or action to which they do not have
|
||||
* acccess.
|
||||
*
|
||||
* @var string
|
||||
* @link http://book.cakephp.org/view/1273/authError
|
||||
*/
|
||||
public $authError = null;
|
||||
|
||||
/**
|
||||
* Determines whether AuthComponent will automatically redirect and exit if login is successful.
|
||||
*
|
||||
* @var boolean
|
||||
* @link http://book.cakephp.org/view/1274/autoRedirect
|
||||
*/
|
||||
public $autoRedirect = true;
|
||||
|
||||
/**
|
||||
* Controller actions for which user validation is not required.
|
||||
*
|
||||
* @var array
|
||||
* @see AuthComponent::allow()
|
||||
* @link http://book.cakephp.org/view/1251/Setting-Auth-Component-Variables
|
||||
*/
|
||||
public $allowedActions = array();
|
||||
|
||||
/**
|
||||
* Maps actions to CRUD operations. Used for controller-based validation ($validate = 'controller').
|
||||
*
|
||||
* @var array
|
||||
* @see AuthComponent::mapActions()
|
||||
*/
|
||||
public $actionMap = array(
|
||||
'index' => 'read',
|
||||
'add' => 'create',
|
||||
'edit' => 'update',
|
||||
'view' => 'read',
|
||||
'remove' => 'delete'
|
||||
);
|
||||
|
||||
/**
|
||||
* Request object
|
||||
*
|
||||
* @var CakeRequest
|
||||
*/
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* Form data from Controller::$data
|
||||
*
|
||||
* @deprecated Use $this->request->data instead
|
||||
* @var array
|
||||
*/
|
||||
public $data = array();
|
||||
|
||||
/**
|
||||
* Parameter data from Controller::$params
|
||||
*
|
||||
* @deprecated Use $this->request instead
|
||||
* @var array
|
||||
*/
|
||||
public $params = array();
|
||||
|
||||
/**
|
||||
* AclComponent instance if using Acl + Auth
|
||||
*
|
||||
* @var AclComponent
|
||||
*/
|
||||
public $Acl;
|
||||
|
||||
/**
|
||||
* Method list for bound controller
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_methods = array();
|
||||
|
||||
/**
|
||||
* Initializes AuthComponent for use in the controller
|
||||
*
|
||||
* @param object $controller A reference to the instantiating controller object
|
||||
* @return void
|
||||
*/
|
||||
public function initialize($controller) {
|
||||
$this->request = $controller->request;
|
||||
$this->params = $this->request;
|
||||
|
||||
$crud = array('create', 'read', 'update', 'delete');
|
||||
$this->actionMap = array_merge($this->actionMap, array_combine($crud, $crud));
|
||||
$this->_methods = $controller->methods;
|
||||
|
||||
$prefixes = Router::prefixes();
|
||||
if (!empty($prefixes)) {
|
||||
foreach ($prefixes as $prefix) {
|
||||
$this->actionMap = array_merge($this->actionMap, array(
|
||||
$prefix . '_index' => 'read',
|
||||
$prefix . '_add' => 'create',
|
||||
$prefix . '_edit' => 'update',
|
||||
$prefix . '_view' => 'read',
|
||||
$prefix . '_remove' => 'delete',
|
||||
$prefix . '_create' => 'create',
|
||||
$prefix . '_read' => 'read',
|
||||
$prefix . '_update' => 'update',
|
||||
$prefix . '_delete' => 'delete'
|
||||
));
|
||||
}
|
||||
}
|
||||
if (Configure::read('debug') > 0) {
|
||||
App::import('Debugger');
|
||||
Debugger::checkSecurityKeys();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main execution method. Handles redirecting of invalid users, and processing
|
||||
* of login form data.
|
||||
*
|
||||
* @param object $controller A reference to the instantiating controller object
|
||||
* @return boolean
|
||||
*/
|
||||
public function startup($controller) {
|
||||
$isErrorOrTests = (
|
||||
strtolower($controller->name) == 'cakeerror' ||
|
||||
(strtolower($controller->name) == 'tests' && Configure::read('debug') > 0)
|
||||
);
|
||||
if ($isErrorOrTests) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$methods = array_flip($controller->methods);
|
||||
$action = $controller->request->params['action'];
|
||||
|
||||
$isMissingAction = (
|
||||
$controller->scaffold === false &&
|
||||
!isset($methods[$action])
|
||||
);
|
||||
|
||||
if ($isMissingAction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$this->__setDefaults()) {
|
||||
return false;
|
||||
}
|
||||
$request = $controller->request;
|
||||
|
||||
$this->request->data = $controller->request->data = $this->hashPasswords($request->data);
|
||||
$url = '';
|
||||
|
||||
if (isset($request->query['url'])) {
|
||||
$url = $request->query['url'];
|
||||
}
|
||||
$url = Router::normalize($url);
|
||||
$loginAction = Router::normalize($this->loginAction);
|
||||
|
||||
$allowedActions = $this->allowedActions;
|
||||
$isAllowed = (
|
||||
$this->allowedActions == array('*') ||
|
||||
in_array($action, $allowedActions)
|
||||
);
|
||||
|
||||
if ($loginAction != $url && $isAllowed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($loginAction == $url) {
|
||||
$model = $this->getModel();
|
||||
if (empty($request->data) || !isset($request->data[$model->alias])) {
|
||||
if (!$this->Session->check('Auth.redirect') && !$this->loginRedirect && env('HTTP_REFERER')) {
|
||||
$this->Session->write('Auth.redirect', $controller->referer(null, true));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$isValid = !empty($request->data[$model->alias][$this->fields['username']]) &&
|
||||
!empty($request->data[$model->alias][$this->fields['password']]);
|
||||
|
||||
if ($isValid) {
|
||||
$username = $request->data[$model->alias][$this->fields['username']];
|
||||
$password = $request->data[$model->alias][$this->fields['password']];
|
||||
|
||||
$data = array(
|
||||
$model->alias . '.' . $this->fields['username'] => $username,
|
||||
$model->alias . '.' . $this->fields['password'] => $password
|
||||
);
|
||||
|
||||
if ($this->login($data)) {
|
||||
if ($this->autoRedirect) {
|
||||
$controller->redirect($this->redirect(), null, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->Session->setFlash($this->loginError, $this->flashElement, array(), 'auth');
|
||||
$request->data[$model->alias][$this->fields['password']] = null;
|
||||
return false;
|
||||
} else {
|
||||
if (!$this->user()) {
|
||||
if (!$request->is('ajax')) {
|
||||
$this->Session->setFlash($this->authError, $this->flashElement, array(), 'auth');
|
||||
if (!empty($request->query) && count($request->query) >= 2) {
|
||||
$query = $request->query;
|
||||
unset($query['url'], $query['ext']);
|
||||
$url .= Router::queryString($query, array());
|
||||
}
|
||||
$this->Session->write('Auth.redirect', $url);
|
||||
$controller->redirect($loginAction);
|
||||
return false;
|
||||
} elseif (!empty($this->ajaxLogin)) {
|
||||
$controller->viewPath = 'elements';
|
||||
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
|
||||
$this->_stop();
|
||||
return false;
|
||||
} else {
|
||||
$controller->redirect(null, 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->authorize) {
|
||||
return true;
|
||||
}
|
||||
|
||||
extract($this->__authType());
|
||||
switch ($type) {
|
||||
case 'controller':
|
||||
$this->object = $controller;
|
||||
break;
|
||||
case 'crud':
|
||||
case 'actions':
|
||||
if (isset($controller->Acl)) {
|
||||
$this->Acl = $controller->Acl;
|
||||
} else {
|
||||
trigger_error(__('Could not find AclComponent. Please include Acl in Controller::$components.'), E_USER_WARNING);
|
||||
}
|
||||
break;
|
||||
case 'model':
|
||||
if (!isset($object)) {
|
||||
$hasModel = (
|
||||
isset($controller->{$controller->modelClass}) &&
|
||||
is_object($controller->{$controller->modelClass})
|
||||
);
|
||||
$isUses = (
|
||||
!empty($controller->uses) && isset($controller->{$controller->uses[0]}) &&
|
||||
is_object($controller->{$controller->uses[0]})
|
||||
);
|
||||
|
||||
if ($hasModel) {
|
||||
$object = $controller->modelClass;
|
||||
} elseif ($isUses) {
|
||||
$object = $controller->uses[0];
|
||||
}
|
||||
}
|
||||
$type = array('model' => $object);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->isAuthorized($type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->Session->setFlash($this->authError, $this->flashElement, array(), 'auth');
|
||||
$controller->redirect($controller->referer(), null, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to introspect the correct values for object properties including
|
||||
* $userModel and $sessionKey.
|
||||
*
|
||||
* @param object $controller A reference to the instantiating controller object
|
||||
* @return boolean
|
||||
* @access private
|
||||
*/
|
||||
function __setDefaults() {
|
||||
if (empty($this->userModel)) {
|
||||
trigger_error(__("Could not find \$userModel. Please set AuthComponent::\$userModel in beforeFilter()."), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
list($plugin, $model) = pluginSplit($this->userModel);
|
||||
$defaults = array(
|
||||
'loginAction' => array(
|
||||
'controller' => Inflector::underscore(Inflector::pluralize($model)),
|
||||
'action' => 'login',
|
||||
'plugin' => Inflector::underscore($plugin),
|
||||
),
|
||||
'sessionKey' => 'Auth.' . $model,
|
||||
'logoutRedirect' => $this->loginAction,
|
||||
'loginError' => __('Login failed. Invalid username or password.'),
|
||||
'authError' => __('You are not authorized to access that location.')
|
||||
);
|
||||
foreach ($defaults as $key => $value) {
|
||||
if (empty($this->{$key})) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given user is authorized to perform an action. The type of
|
||||
* authorization used is based on the value of AuthComponent::$authorize or the
|
||||
* passed $type param.
|
||||
*
|
||||
* Types:
|
||||
* 'controller' will validate against Controller::isAuthorized() if controller instance is
|
||||
* passed in $object
|
||||
* 'actions' will validate Controller::action against an AclComponent::check()
|
||||
* 'crud' will validate mapActions against an AclComponent::check()
|
||||
* array('model'=> 'name'); will validate mapActions against model
|
||||
* $name::isAuthorized(user, controller, mapAction)
|
||||
* 'object' will validate Controller::action against
|
||||
* object::isAuthorized(user, controller, action)
|
||||
*
|
||||
* @param string $type Type of authorization
|
||||
* @param mixed $object object, model object, or model name
|
||||
* @param mixed $user The user to check the authorization of
|
||||
* @return boolean True if $user is authorized, otherwise false
|
||||
*/
|
||||
public function isAuthorized($type = null, $object = null, $user = null) {
|
||||
if (empty($user) && !$this->user()) {
|
||||
return false;
|
||||
} elseif (empty($user)) {
|
||||
$user = $this->user();
|
||||
}
|
||||
|
||||
extract($this->__authType($type));
|
||||
|
||||
if (!$object) {
|
||||
$object = $this->object;
|
||||
}
|
||||
|
||||
$valid = false;
|
||||
switch ($type) {
|
||||
case 'controller':
|
||||
$valid = $object->isAuthorized();
|
||||
break;
|
||||
case 'actions':
|
||||
$valid = $this->Acl->check($user, $this->action());
|
||||
break;
|
||||
case 'crud':
|
||||
if (!isset($this->actionMap[$this->request['action']])) {
|
||||
trigger_error(
|
||||
__('Auth::startup() - Attempted access of un-mapped action "%1$s" in controller "%2$s"', $this->request['action'], $this->request['controller']),
|
||||
E_USER_WARNING
|
||||
);
|
||||
} else {
|
||||
$valid = $this->Acl->check(
|
||||
$user,
|
||||
$this->action(':controller'),
|
||||
$this->actionMap[$this->request['action']]
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'model':
|
||||
$action = $this->request['action'];
|
||||
if (isset($this->actionMap[$action])) {
|
||||
$action = $this->actionMap[$action];
|
||||
}
|
||||
if (is_string($object)) {
|
||||
$object = $this->getModel($object);
|
||||
}
|
||||
case 'object':
|
||||
if (!isset($action)) {
|
||||
$action = $this->action(':action');
|
||||
}
|
||||
if (empty($object)) {
|
||||
trigger_error(__('Could not find %s. Set AuthComponent::$object in beforeFilter() or pass a valid object', get_class($object)), E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
if (method_exists($object, 'isAuthorized')) {
|
||||
$valid = $object->isAuthorized($user, $this->action(':controller'), $action);
|
||||
} elseif ($object) {
|
||||
trigger_error(__('%s::isAuthorized() is not defined.', get_class($object)), E_USER_WARNING);
|
||||
}
|
||||
break;
|
||||
case null:
|
||||
case false:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
trigger_error(__('Auth::isAuthorized() - $authorize is set to an incorrect value. Allowed settings are: "actions", "crud", "model" or null.'), E_USER_WARNING);
|
||||
break;
|
||||
}
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get authorization type
|
||||
*
|
||||
* @param string $auth Type of authorization
|
||||
* @return array Associative array with: type, object
|
||||
* @access private
|
||||
*/
|
||||
function __authType($auth = null) {
|
||||
if ($auth == null) {
|
||||
$auth = $this->authorize;
|
||||
}
|
||||
$object = null;
|
||||
if (is_array($auth)) {
|
||||
$type = key($auth);
|
||||
$object = $auth[$type];
|
||||
} else {
|
||||
$type = $auth;
|
||||
return compact('type');
|
||||
}
|
||||
return compact('type', 'object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a list of actions in the current controller for which authentication is not required, or
|
||||
* no parameters to allow all actions.
|
||||
*
|
||||
* @param mixed $action Controller action name or array of actions
|
||||
* @param string $action Controller action name
|
||||
* @param string ... etc.
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/view/1257/allow
|
||||
*/
|
||||
public function allow() {
|
||||
$args = func_get_args();
|
||||
if (empty($args) || $args == array('*')) {
|
||||
$this->allowedActions = $this->_methods;
|
||||
} else {
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
$this->allowedActions = array_merge($this->allowedActions, $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes items from the list of allowed actions.
|
||||
*
|
||||
* @param mixed $action Controller action name or array of actions
|
||||
* @param string $action Controller action name
|
||||
* @param string ... etc.
|
||||
* @return void
|
||||
* @see AuthComponent::allow()
|
||||
* @link http://book.cakephp.org/view/1258/deny
|
||||
*/
|
||||
public function deny() {
|
||||
$args = func_get_args();
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
foreach ($args as $arg) {
|
||||
$i = array_search($arg, $this->allowedActions);
|
||||
if (is_int($i)) {
|
||||
unset($this->allowedActions[$i]);
|
||||
}
|
||||
}
|
||||
$this->allowedActions = array_values($this->allowedActions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps action names to CRUD operations. Used for controller-based authentication.
|
||||
*
|
||||
* @param array $map Actions to map
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/view/1260/mapActions
|
||||
*/
|
||||
public function mapActions($map = array()) {
|
||||
$crud = array('create', 'read', 'update', 'delete');
|
||||
foreach ($map as $action => $type) {
|
||||
if (in_array($action, $crud) && is_array($type)) {
|
||||
foreach ($type as $typedAction) {
|
||||
$this->actionMap[$typedAction] = $action;
|
||||
}
|
||||
} else {
|
||||
$this->actionMap[$action] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually log-in a user with the given parameter data. The $data provided can be any data
|
||||
* structure used to identify a user in AuthComponent::identify(). If $data is empty or not
|
||||
* specified, POST data from Controller::$data will be used automatically.
|
||||
*
|
||||
* After (if) login is successful, the user record is written to the session key specified in
|
||||
* AuthComponent::$sessionKey.
|
||||
*
|
||||
* @param mixed $data User object
|
||||
* @return boolean True on login success, false on failure
|
||||
* @link http://book.cakephp.org/view/1261/login
|
||||
*/
|
||||
public function login($data = null) {
|
||||
$this->__setDefaults();
|
||||
$this->_loggedIn = false;
|
||||
|
||||
if (empty($data)) {
|
||||
$data = $this->data;
|
||||
}
|
||||
|
||||
if ($user = $this->identify($data)) {
|
||||
$this->Session->write($this->sessionKey, $user);
|
||||
$this->_loggedIn = true;
|
||||
}
|
||||
return $this->_loggedIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a user out, and returns the login action to redirect to.
|
||||
*
|
||||
* @param mixed $url Optional URL to redirect the user to after logout
|
||||
* @return string AuthComponent::$loginAction
|
||||
* @see AuthComponent::$loginAction
|
||||
* @link http://book.cakephp.org/view/1262/logout
|
||||
*/
|
||||
public function logout() {
|
||||
$this->__setDefaults();
|
||||
$this->Session->delete($this->sessionKey);
|
||||
$this->Session->delete('Auth.redirect');
|
||||
$this->_loggedIn = false;
|
||||
return Router::normalize($this->logoutRedirect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current user from the session.
|
||||
*
|
||||
* @param string $key field to retrive. Leave null to get entire User record
|
||||
* @return mixed User record. or null if no user is logged in.
|
||||
* @link http://book.cakephp.org/view/1264/user
|
||||
*/
|
||||
public function user($key = null) {
|
||||
$this->__setDefaults();
|
||||
if (!$this->Session->check($this->sessionKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($key == null) {
|
||||
$model = $this->getModel();
|
||||
return array($model->alias => $this->Session->read($this->sessionKey));
|
||||
} else {
|
||||
$user = $this->Session->read($this->sessionKey);
|
||||
if (isset($user[$key])) {
|
||||
return $user[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If no parameter is passed, gets the authentication redirect URL.
|
||||
*
|
||||
* @param mixed $url Optional URL to write as the login redirect URL.
|
||||
* @return string Redirect URL
|
||||
*/
|
||||
public function redirect($url = null) {
|
||||
if (!is_null($url)) {
|
||||
$redir = $url;
|
||||
$this->Session->write('Auth.redirect', $redir);
|
||||
} elseif ($this->Session->check('Auth.redirect')) {
|
||||
$redir = $this->Session->read('Auth.redirect');
|
||||
$this->Session->delete('Auth.redirect');
|
||||
|
||||
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
|
||||
$redir = $this->loginRedirect;
|
||||
}
|
||||
} else {
|
||||
$redir = $this->loginRedirect;
|
||||
}
|
||||
return Router::normalize($redir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a user against an abstract object.
|
||||
*
|
||||
* @param mixed $object The object to validate the user against.
|
||||
* @param mixed $user Optional. The identity of the user to be validated.
|
||||
* Uses the current user session if none specified. For
|
||||
* valid forms of identifying users, see
|
||||
* AuthComponent::identify().
|
||||
* @param string $action Optional. The action to validate against.
|
||||
* @see AuthComponent::identify()
|
||||
* @return boolean True if the user validates, false otherwise.
|
||||
*/
|
||||
public function validate($object, $user = null, $action = null) {
|
||||
if (empty($user)) {
|
||||
$user = $this->user();
|
||||
}
|
||||
if (empty($user)) {
|
||||
return false;
|
||||
}
|
||||
return $this->Acl->check($user, $object, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the ACO node bound to a controller/action.
|
||||
*
|
||||
* @param string $action Optional. The controller/action path to validate the
|
||||
* user against. The current request action is used if
|
||||
* none is specified.
|
||||
* @return boolean ACO node path
|
||||
* @link http://book.cakephp.org/view/1256/action
|
||||
*/
|
||||
public function action($action = ':plugin/:controller/:action') {
|
||||
$plugin = empty($this->request['plugin']) ? null : Inflector::camelize($this->request['plugin']) . '/';
|
||||
return str_replace(
|
||||
array(':controller', ':action', ':plugin/'),
|
||||
array(Inflector::camelize($this->request['controller']), $this->request['action'], $plugin),
|
||||
$this->actionPath . $action
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the model object specified, and attempts
|
||||
* to load it if it is not found.
|
||||
*
|
||||
* @param string $name Model name (defaults to AuthComponent::$userModel)
|
||||
* @return object A reference to a model object
|
||||
*/
|
||||
public function &getModel($name = null) {
|
||||
$model = null;
|
||||
if (!$name) {
|
||||
$name = $this->userModel;
|
||||
}
|
||||
|
||||
$model = ClassRegistry::init($name);
|
||||
|
||||
if (empty($model)) {
|
||||
trigger_error(__('Auth::getModel() - Model is not set or could not be found'), E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies a user based on specific criteria.
|
||||
*
|
||||
* @param mixed $user Optional. The identity of the user to be validated.
|
||||
* Uses the current user session if none specified.
|
||||
* @param array $conditions Optional. Additional conditions to a find.
|
||||
* @return array User record data, or null, if the user could not be identified.
|
||||
*/
|
||||
public function identify($user = null, $conditions = null) {
|
||||
if ($conditions === false) {
|
||||
$conditions = null;
|
||||
} elseif (is_array($conditions)) {
|
||||
$conditions = array_merge((array)$this->userScope, $conditions);
|
||||
} else {
|
||||
$conditions = $this->userScope;
|
||||
}
|
||||
$model = $this->getModel();
|
||||
if (empty($user)) {
|
||||
$user = $this->user();
|
||||
if (empty($user)) {
|
||||
return null;
|
||||
}
|
||||
} elseif (is_object($user) && is_a($user, 'Model')) {
|
||||
if (!$user->exists()) {
|
||||
return null;
|
||||
}
|
||||
$user = $user->read();
|
||||
$user = $user[$model->alias];
|
||||
} elseif (is_array($user) && isset($user[$model->alias])) {
|
||||
$user = $user[$model->alias];
|
||||
}
|
||||
|
||||
if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$model->alias . '.' . $this->fields['username']]))) {
|
||||
if (isset($user[$this->fields['username']]) && !empty($user[$this->fields['username']]) && !empty($user[$this->fields['password']])) {
|
||||
if (trim($user[$this->fields['username']]) == '=' || trim($user[$this->fields['password']]) == '=') {
|
||||
return false;
|
||||
}
|
||||
$find = array(
|
||||
$model->alias.'.'.$this->fields['username'] => $user[$this->fields['username']],
|
||||
$model->alias.'.'.$this->fields['password'] => $user[$this->fields['password']]
|
||||
);
|
||||
} elseif (isset($user[$model->alias . '.' . $this->fields['username']]) && !empty($user[$model->alias . '.' . $this->fields['username']])) {
|
||||
if (trim($user[$model->alias . '.' . $this->fields['username']]) == '=' || trim($user[$model->alias . '.' . $this->fields['password']]) == '=') {
|
||||
return false;
|
||||
}
|
||||
$find = array(
|
||||
$model->alias.'.'.$this->fields['username'] => $user[$model->alias . '.' . $this->fields['username']],
|
||||
$model->alias.'.'.$this->fields['password'] => $user[$model->alias . '.' . $this->fields['password']]
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
$data = $model->find('first', array(
|
||||
'conditions' => array_merge($find, $conditions),
|
||||
'recursive' => 0
|
||||
));
|
||||
if (empty($data) || empty($data[$model->alias])) {
|
||||
return null;
|
||||
}
|
||||
} elseif (!empty($user) && is_string($user)) {
|
||||
$data = $model->find('first', array(
|
||||
'conditions' => array_merge(array($model->escapeField() => $user), $conditions),
|
||||
));
|
||||
if (empty($data) || empty($data[$model->alias])) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
if (!empty($data[$model->alias][$this->fields['password']])) {
|
||||
unset($data[$model->alias][$this->fields['password']]);
|
||||
}
|
||||
return $data[$model->alias];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash any passwords found in $data using $userModel and $fields['password']
|
||||
*
|
||||
* @param array $data Set of data to look for passwords
|
||||
* @return array Data with passwords hashed
|
||||
* @link http://book.cakephp.org/view/1259/hashPasswords
|
||||
*/
|
||||
public function hashPasswords($data) {
|
||||
if (is_object($this->authenticate) && method_exists($this->authenticate, 'hashPasswords')) {
|
||||
return $this->authenticate->hashPasswords($data);
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$model = $this->getModel();
|
||||
|
||||
if(isset($data[$model->alias])) {
|
||||
if (isset($data[$model->alias][$this->fields['username']]) && isset($data[$model->alias][$this->fields['password']])) {
|
||||
$data[$model->alias][$this->fields['password']] = $this->password($data[$model->alias][$this->fields['password']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash a password with the application's salt value (as defined with Configure::write('Security.salt');
|
||||
*
|
||||
* @param string $password Password to hash
|
||||
* @return string Hashed password
|
||||
* @link http://book.cakephp.org/view/1263/password
|
||||
*/
|
||||
public function password($password) {
|
||||
return Security::hash($password, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component shutdown. If user is logged in, wipe out redirect.
|
||||
*
|
||||
* @param object $controller Instantiating controller
|
||||
*/
|
||||
public function shutdown($controller) {
|
||||
if ($this->_loggedIn) {
|
||||
$this->Session->delete('Auth.redirect');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or gets whether the user is logged in
|
||||
*
|
||||
* @param boolean $logged sets the status of the user, true to logged in, false to logged out
|
||||
* @return boolean true if the user is logged in, false otherwise
|
||||
* @access public
|
||||
*/
|
||||
public function loggedIn($logged = null) {
|
||||
if (!is_null($logged)) {
|
||||
$this->_loggedIn = $logged;
|
||||
}
|
||||
return $this->_loggedIn;
|
||||
}
|
||||
}
|
|
@ -1,291 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MagicDb parser and file analyzer
|
||||
*
|
||||
* 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
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (!class_exists('Object')) {
|
||||
require LIBS . 'object.php';
|
||||
}
|
||||
if (!class_exists('File')) {
|
||||
require LIBS . 'file.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to parse and use the MagicDb for file type analysis
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class MagicDb extends Object {
|
||||
|
||||
/**
|
||||
* Holds the parsed MagicDb for this class instance
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $db = array();
|
||||
|
||||
/**
|
||||
* Reads a MagicDb from various formats
|
||||
*
|
||||
* @public $magicDb mixed Can be an array containing the db, a magic db as a string, or a filename pointing to a magic db in .db or magic.db.php format
|
||||
* @return boolean Returns false if reading / validation failed or true on success.
|
||||
* @author Felix
|
||||
*/
|
||||
function read($magicDb = null) {
|
||||
if (!is_string($magicDb) && !is_array($magicDb)) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($magicDb) || strpos($magicDb, '# FILE_ID DB') === 0) {
|
||||
$data = $magicDb;
|
||||
} else {
|
||||
$File = new File($magicDb);
|
||||
if (!$File->exists()) {
|
||||
return false;
|
||||
}
|
||||
if ($File->ext() == 'php') {
|
||||
include($File->pwd());
|
||||
$data = $magicDb;
|
||||
} else {
|
||||
// @TODO: Needs test coverage
|
||||
$data = $File->read();
|
||||
}
|
||||
}
|
||||
|
||||
$magicDb = $this->toArray($data);
|
||||
if (!$this->validates($magicDb)) {
|
||||
return false;
|
||||
}
|
||||
return !!($this->db = $magicDb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a MagicDb $data string into an array or returns the current MagicDb instance as an array
|
||||
*
|
||||
* @param string $data A MagicDb string to turn into an array
|
||||
* @return array A parsed MagicDb array or an empty array if the $data param was invalid. Returns the db property if $data is not set.
|
||||
*/
|
||||
public function toArray($data = null) {
|
||||
if (is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
if ($data === null) {
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
if (strpos($data, '# FILE_ID DB') !== 0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$lines = explode("\r\n", $data);
|
||||
$db = array();
|
||||
|
||||
$validHeader = count($lines) > 3
|
||||
&& preg_match('/^# Date:([0-9]{4}-[0-9]{2}-[0-9]{2})$/', $lines[1], $date)
|
||||
&& preg_match('/^# Source:(.+)$/', $lines[2], $source)
|
||||
&& strlen($lines[3]) == 0;
|
||||
if (!$validHeader) {
|
||||
return $db;
|
||||
}
|
||||
|
||||
$db = array('header' => array('Date' => $date[1], 'Source' => $source[1]), 'database' => array());
|
||||
$lines = array_splice($lines, 3);
|
||||
|
||||
$format = array();
|
||||
while (!empty($lines)) {
|
||||
$line = array_shift($lines);
|
||||
if (isset($line[0]) && $line[0] == '#' || empty($line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns = explode("\t", $line);
|
||||
if (in_array($columns[0]{0}, array('>', '&'))) {
|
||||
$format[] = $columns;
|
||||
} elseif (!empty($format)) {
|
||||
$db['database'][] = $format;
|
||||
$format = array($columns);
|
||||
} else {
|
||||
$format = array($columns);
|
||||
}
|
||||
}
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the MagicDb instance or the passed $magicDb is valid
|
||||
*
|
||||
* @param mixed $magicDb A $magicDb string / array to validate (optional)
|
||||
* @return boolean True if the $magicDb / instance db validates, false if not
|
||||
*/
|
||||
public function validates($magicDb = null) {
|
||||
if (is_null($magicDb)) {
|
||||
$magicDb = $this->db;
|
||||
} elseif (!is_array($magicDb)) {
|
||||
$magicDb = $this->toArray($magicDb);
|
||||
}
|
||||
|
||||
return isset($magicDb['header'], $magicDb['database']) && is_array($magicDb['header']) && is_array($magicDb['database']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyzes a given $file using the currently loaded MagicDb information based on the desired $options
|
||||
*
|
||||
* @param string $file Absolute path to the file to analyze
|
||||
* @param array $options TBT
|
||||
* @return mixed
|
||||
*/
|
||||
public function analyze($file, $options = array()) {
|
||||
if (!is_string($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
$MagicFileResource = new MagicFileResource($file);
|
||||
foreach ($this->db['database'] as $format) {
|
||||
$magic = $format[0];
|
||||
$match = $MagicFileResource->test($magic);
|
||||
if ($match === false) {
|
||||
continue;
|
||||
}
|
||||
$matches[] = $magic;
|
||||
}
|
||||
|
||||
return $matches;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented class
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class MagicFileResource extends Object{
|
||||
|
||||
/**
|
||||
* undocumented variable
|
||||
*
|
||||
* @var unknown
|
||||
* @access public
|
||||
*/
|
||||
public $resource = null;
|
||||
|
||||
/**
|
||||
* undocumented variable
|
||||
*
|
||||
* @var unknown
|
||||
* @access public
|
||||
*/
|
||||
public $offset = 0;
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @param unknown $file
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($file) {
|
||||
if (file_exists($file)) {
|
||||
$this->resource = new File($file);
|
||||
} else {
|
||||
$this->resource = $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @param unknown $magic
|
||||
* @return void
|
||||
*/
|
||||
public function test($magic) {
|
||||
$offset = null;
|
||||
$type = null;
|
||||
$expected = null;
|
||||
$comment = null;
|
||||
if (isset($magic[0])) {
|
||||
$offset = $magic[0];
|
||||
}
|
||||
if (isset($magic[1])) {
|
||||
$type = $magic[1];
|
||||
}
|
||||
if (isset($magic[2])) {
|
||||
$expected = $magic[2];
|
||||
}
|
||||
if (isset($magic[3])) {
|
||||
$comment = $magic[3];
|
||||
}
|
||||
$val = $this->extract($offset, $type, $expected);
|
||||
return $val == $expected;
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @param unknown $type
|
||||
* @param unknown $length
|
||||
* @return void
|
||||
*/
|
||||
public function read($length = null) {
|
||||
if (!is_object($this->resource)) {
|
||||
return substr($this->resource, $this->offset, $length);
|
||||
}
|
||||
return $this->resource->read($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @param unknown $type
|
||||
* @param unknown $expected
|
||||
* @return void
|
||||
*/
|
||||
public function extract($offset, $type, $expected) {
|
||||
switch ($type) {
|
||||
case 'string':
|
||||
$this->offset($offset);
|
||||
$val = $this->read(strlen($expected));
|
||||
if ($val === $expected) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @param unknown $offset
|
||||
* @param unknown $whence
|
||||
* @return void
|
||||
*/
|
||||
public function offset($offset = null) {
|
||||
if (is_null($offset)) {
|
||||
if (!is_object($this->resource)) {
|
||||
return $this->offset;
|
||||
}
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
if (!ctype_digit($offset)) {
|
||||
return false;
|
||||
}
|
||||
if (is_object($this->resource)) {
|
||||
$this->resource->offset($offset);
|
||||
} else {
|
||||
$this->offset = $offset;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,274 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Datasource connection manager
|
||||
*
|
||||
* Provides an interface for loading and enumerating connections defined in app/config/database.php
|
||||
*
|
||||
* 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.model
|
||||
* @since CakePHP(tm) v 0.10.x.1402
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
require LIBS . 'model' . DS . 'datasources' . DS . 'datasource.php';
|
||||
config('database');
|
||||
|
||||
/**
|
||||
* Manages loaded instances of DataSource objects
|
||||
*
|
||||
* @package cake.libs.model
|
||||
*/
|
||||
class ConnectionManager {
|
||||
|
||||
/**
|
||||
* Holds a loaded instance of the Connections object
|
||||
*
|
||||
* @var DATABASE_CONFIG
|
||||
* @access public
|
||||
*/
|
||||
public $config = null;
|
||||
|
||||
/**
|
||||
* Holds instances DataSource objects
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $_dataSources = array();
|
||||
|
||||
/**
|
||||
* Contains a list of all file and class names used in Connection settings
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $_connectionsEnum = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
function __construct() {
|
||||
if (class_exists('DATABASE_CONFIG')) {
|
||||
$this->config = new DATABASE_CONFIG();
|
||||
$this->_getConnectionObjects();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a reference to the ConnectionManger object instance
|
||||
*
|
||||
* @return object Instance
|
||||
*/
|
||||
public static function &getInstance() {
|
||||
static $instance = array();
|
||||
|
||||
if (!$instance) {
|
||||
$instance[0] = new ConnectionManager();
|
||||
}
|
||||
|
||||
return $instance[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a reference to a DataSource object
|
||||
*
|
||||
* @param string $name The name of the DataSource, as defined in app/config/database.php
|
||||
* @return object Instance
|
||||
*/
|
||||
public static function &getDataSource($name) {
|
||||
$_this = ConnectionManager::getInstance();
|
||||
|
||||
if (!empty($_this->_dataSources[$name])) {
|
||||
$return = $_this->_dataSources[$name];
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (empty($_this->_connectionsEnum[$name])) {
|
||||
trigger_error(__("ConnectionManager::getDataSource - Non-existent data source %s", $name), E_USER_ERROR);
|
||||
$null = null;
|
||||
return $null;
|
||||
}
|
||||
$conn = $_this->_connectionsEnum[$name];
|
||||
$class = $conn['classname'];
|
||||
|
||||
if ($_this->loadDataSource($name) === null) {
|
||||
trigger_error(__("ConnectionManager::getDataSource - Could not load class %s", $class), E_USER_ERROR);
|
||||
$null = null;
|
||||
return $null;
|
||||
}
|
||||
$_this->_dataSources[$name] = new $class($_this->config->{$name});
|
||||
$_this->_dataSources[$name]->configKeyName = $name;
|
||||
|
||||
$return = $_this->_dataSources[$name];
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of available DataSource connections
|
||||
*
|
||||
* @return array List of available connections
|
||||
*/
|
||||
public static function sourceList() {
|
||||
$_this = ConnectionManager::getInstance();
|
||||
return array_keys($_this->_dataSources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a DataSource name from an object reference.
|
||||
*
|
||||
* **Warning** this method may cause fatal errors in PHP4.
|
||||
*
|
||||
* @param object $source DataSource object
|
||||
* @return string Datasource name, or null if source is not present
|
||||
* in the ConnectionManager.
|
||||
*/
|
||||
public static function getSourceName(&$source) {
|
||||
$_this = ConnectionManager::getInstance();
|
||||
foreach ($_this->_dataSources as $name => $ds) {
|
||||
if ($ds == $source) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the DataSource class for the given connection name
|
||||
*
|
||||
* @param mixed $connName A string name of the connection, as defined in app/config/database.php,
|
||||
* or an array containing the filename (without extension) and class name of the object,
|
||||
* to be found in app/models/datasources/ or cake/libs/model/datasources/.
|
||||
* @return boolean True on success, null on failure or false if the class is already loaded
|
||||
*/
|
||||
public static function loadDataSource($connName) {
|
||||
$_this = ConnectionManager::getInstance();
|
||||
|
||||
if (is_array($connName)) {
|
||||
$conn = $connName;
|
||||
} else {
|
||||
$conn = $_this->_connectionsEnum[$connName];
|
||||
}
|
||||
|
||||
if (class_exists($conn['classname'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($conn['parent'])) {
|
||||
$_this->loadDataSource($conn['parent']);
|
||||
}
|
||||
|
||||
$conn = array_merge(array('plugin' => null, 'classname' => null, 'parent' => null), $conn);
|
||||
$class = "{$conn['plugin']}.{$conn['classname']}";
|
||||
|
||||
if (!App::import('Datasource', $class, !is_null($conn['plugin']))) {
|
||||
trigger_error(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s', $class), E_USER_ERROR);
|
||||
return null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of connections
|
||||
*
|
||||
* @return array An associative array of elements where the key is the connection name
|
||||
* (as defined in Connections), and the value is an array with keys 'filename' and 'classname'.
|
||||
*/
|
||||
public static function enumConnectionObjects() {
|
||||
$_this = ConnectionManager::getInstance();
|
||||
return $_this->_connectionsEnum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically creates a DataSource object at runtime, with the given name and settings
|
||||
*
|
||||
* @param string $name The DataSource name
|
||||
* @param array $config The DataSource configuration settings
|
||||
* @return object A reference to the DataSource object, or null if creation failed
|
||||
*/
|
||||
public static function &create($name = '', $config = array()) {
|
||||
$_this = ConnectionManager::getInstance();
|
||||
|
||||
if (empty($name) || empty($config) || array_key_exists($name, $_this->_connectionsEnum)) {
|
||||
$null = null;
|
||||
return $null;
|
||||
}
|
||||
$_this->config->{$name} = $config;
|
||||
$_this->_connectionsEnum[$name] = $_this->__connectionData($config);
|
||||
$return = $_this->getDataSource($name);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of class and file names associated with the user-defined DataSource connections
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _getConnectionObjects() {
|
||||
$connections = get_object_vars($this->config);
|
||||
|
||||
if ($connections != null) {
|
||||
foreach ($connections as $name => $config) {
|
||||
$this->_connectionsEnum[$name] = $this->__connectionData($config);
|
||||
}
|
||||
} else {
|
||||
throw new MissingConnectionException(array('class' => 'ConnectionManager'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file, class name, and parent for the given driver.
|
||||
*
|
||||
* @return array An indexed array with: filename, classname, plugin and parent
|
||||
*/
|
||||
private function __connectionData($config) {
|
||||
if (!isset($config['datasource'])) {
|
||||
$config['datasource'] = 'dbo';
|
||||
}
|
||||
$filename = $classname = $parent = $plugin = null;
|
||||
|
||||
if (!empty($config['driver'])) {
|
||||
$parent = $this->__connectionData(array('datasource' => $config['datasource']));
|
||||
$parentSource = preg_replace('/_source$/', '', $parent['filename']);
|
||||
|
||||
list($plugin, $classname) = pluginSplit($config['driver']);
|
||||
if ($plugin) {
|
||||
$source = Inflector::underscore($classname);
|
||||
} else {
|
||||
$source = $parentSource . '_' . $config['driver'];
|
||||
$classname = Inflector::camelize(strtolower($source));
|
||||
}
|
||||
$filename = $parentSource . DS . $source;
|
||||
} else {
|
||||
list($plugin, $classname) = pluginSplit($config['datasource']);
|
||||
if ($plugin) {
|
||||
$filename = Inflector::underscore($classname);
|
||||
} else {
|
||||
$filename = Inflector::underscore($config['datasource']);
|
||||
}
|
||||
if (substr($filename, -7) != '_source') {
|
||||
$filename .= '_source';
|
||||
}
|
||||
$classname = Inflector::camelize(strtolower($filename));
|
||||
}
|
||||
return compact('filename', 'classname', 'parent', 'plugin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
*/
|
||||
function __destruct() {
|
||||
if (Configure::read('Session.defaults') == 'database' && function_exists('session_write_close')) {
|
||||
session_write_close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* 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.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __('Missing Method in %s', $controller); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __('Error'); ?>: </strong>
|
||||
<?php echo __('The action %1$s is not defined in controller %2$s', '<em>' . $action . '</em>', '<em>' . $controller . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __('Error'); ?>: </strong>
|
||||
<?php echo __('Create %1$s%2$s in file: %3$s.', '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $controller;?> extends AppController {
|
||||
|
||||
<strong>
|
||||
function <?php echo $action;?> {
|
||||
|
||||
}
|
||||
</strong>
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php echo __('Notice'); ?>: </strong>
|
||||
<?php echo __('If you want to customize this error message, create %s', APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_action.ctp'); ?>
|
||||
</p>
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* 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.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __('Missing View'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __('Error'); ?>: </strong>
|
||||
<?php echo __('The view for %1$s%2$s was not found.', '<em>' . Inflector::camelize($this->request->controller) . 'Controller::</em>', '<em>' . $this->request->action . '()</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __('Error'); ?>: </strong>
|
||||
<?php echo __('Confirm you have created the file: %s', $file); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php echo __('Notice'); ?>: </strong>
|
||||
<?php echo __('If you want to customize this error message, create %s', APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_view.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
|
@ -1,170 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* 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.view.templates.pages
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (Configure::read() == 0):
|
||||
throw new NotFoundException();
|
||||
endif;
|
||||
App::import('Core', 'Debugger');
|
||||
?>
|
||||
<h2><?php echo __('Release Notes for CakePHP %s.', Configure::version()); ?></h2>
|
||||
<a href="http://cakephp.org/changelogs/1.3.6"><?php __('Read the changelog'); ?> </a>
|
||||
<?php
|
||||
if (Configure::read() > 0):
|
||||
Debugger::checkSecurityKeys();
|
||||
endif;
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
if (is_writable(TMP)):
|
||||
echo '<span class="notice success">';
|
||||
echo __('Your tmp directory is writable.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Your tmp directory is NOT writable.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
$settings = Cache::settings();
|
||||
if (!empty($settings)):
|
||||
echo '<span class="notice success">';
|
||||
echo __('The %s is being used for caching. To change the config edit APP/config/core.php ', '<em>'. $settings['engine'] . 'Engine</em>');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Your cache is NOT working. Please check the settings in APP/config/core.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
$filePresent = null;
|
||||
if (file_exists(CONFIGS.'database.php')):
|
||||
echo '<span class="notice success">';
|
||||
echo __('Your database configuration file is present.');
|
||||
$filePresent = true;
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Your database configuration file is NOT present.');
|
||||
echo '<br/>';
|
||||
echo __('Rename config/database.php.default to config/database.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
App::import('Core', 'Validation');
|
||||
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>';
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if (isset($filePresent)):
|
||||
if (!class_exists('ConnectionManager')) {
|
||||
require LIBS . 'model' . DS . 'connection_manager.php';
|
||||
}
|
||||
$db = ConnectionManager::getInstance();
|
||||
@$connected = $db->getDataSource('default');
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
if ($connected->isConnected()):
|
||||
echo '<span class="notice success">';
|
||||
echo __('Cake is able to connect to the database.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Cake is NOT able to connect to the database.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php endif;?>
|
||||
<h3><?php echo __('Editing this Page'); ?></h3>
|
||||
<p>
|
||||
<?php
|
||||
echo __('To change the content of this page, create: APP/views/pages/home.ctp.<br />
|
||||
To change its layout, create: APP/views/layouts/default.ctp.<br />
|
||||
You can also add some CSS styles for your pages at: APP/webroot/css.');
|
||||
?>
|
||||
</p>
|
||||
|
||||
<h3><?php echo __('Getting Started'); ?></h3>
|
||||
<p>
|
||||
<?php
|
||||
echo $this->Html->link(
|
||||
sprintf('<strong>%s</strong> %s', __('New', true), __('CakePHP 1.3 Docs', true)),
|
||||
'http://book.cakephp.org/view/875/x1-3-Collection',
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
echo $this->Html->link(
|
||||
__('The 15 min Blog Tutorial', true),
|
||||
'http://book.cakephp.org/view/1528/Blog',
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
<h3><?php echo __('More about Cake'); ?></h3>
|
||||
<p>
|
||||
<?php echo __('CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Active Record, Association Data Mapping, Front Controller and MVC.'); ?>
|
||||
</p>
|
||||
<p>
|
||||
<?php echo __('Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.'); ?>
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="http://cakefoundation.org/"><?php echo __('Cake Software Foundation'); ?> </a>
|
||||
<ul><li><?php echo __('Promoting development related to CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://www.cakephp.org"><?php echo __('CakePHP'); ?> </a>
|
||||
<ul><li><?php echo __('The Rapid Development Framework'); ?></li></ul></li>
|
||||
<li><a href="http://book.cakephp.org"><?php echo __('CakePHP Documentation'); ?> </a>
|
||||
<ul><li><?php echo __('Your Rapid Development Cookbook'); ?></li></ul></li>
|
||||
<li><a href="http://api.cakephp.org"><?php echo __('CakePHP API'); ?> </a>
|
||||
<ul><li><?php echo __('Quick Reference'); ?></li></ul></li>
|
||||
<li><a href="http://bakery.cakephp.org"><?php echo __('The Bakery'); ?> </a>
|
||||
<ul><li><?php echo __('Everything CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://live.cakephp.org"><?php echo __('The Show'); ?> </a>
|
||||
<ul><li><?php echo __('The Show is a live and archived internet radio broadcast CakePHP-related topics and answer questions live via IRC, Skype, and telephone.'); ?></li></ul></li>
|
||||
<li><a href="http://groups.google.com/group/cake-php"><?php echo __('CakePHP Google Group'); ?> </a>
|
||||
<ul><li><?php echo __('Community mailing list'); ?></li></ul></li>
|
||||
<li><a href="irc://irc.freenode.net/cakephp">irc.freenode.net #cakephp</a>
|
||||
<ul><li><?php echo __('Live chat about CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://github.com/cakephp/"><?php echo __('CakePHP Code'); ?> </a>
|
||||
<ul><li><?php echo __('For the Development of CakePHP Git repository, Downloads'); ?></li></ul></li>
|
||||
<li><a href="http://cakephp.lighthouseapp.com/"><?php echo __('CakePHP Lighthouse'); ?> </a>
|
||||
<ul><li><?php echo __('CakePHP Tickets, Wiki pages, Roadmap'); ?></li></ul></li>
|
||||
<li><a href="http://www.cakeforge.org"><?php echo __('CakeForge'); ?> </a>
|
||||
<ul><li><?php echo __('Open Development for CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://astore.amazon.com/cakesoftwaref-20/"><?php echo __('Book Store'); ?> </a>
|
||||
<ul><li><?php echo __('Recommended Software Books'); ?></li></ul></li>
|
||||
<li><a href="http://www.cafepress.com/cakefoundation"><?php echo __('CakePHP gear'); ?> </a>
|
||||
<ul><li><?php echo __('Get your own CakePHP gear - Doughnate to Cake'); ?></li></ul></li>
|
||||
</ul>
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* AllLibsTest file
|
||||
*
|
||||
* 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.tests.cases
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* AllLibsTest class
|
||||
*
|
||||
* This test group will run all non mvc related lib class tests
|
||||
*
|
||||
* @package cake.tests.cases
|
||||
*/
|
||||
class AllLibsTest extends PHPUnit_Framework_TestSuite {
|
||||
|
||||
/**
|
||||
* suite method, defines tests for this suite.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function suite() {
|
||||
$suite = new PHPUnit_Framework_TestSuite('All non-MVC lib class tests');
|
||||
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'basics.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_session.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'debugger.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'file.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'folder.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'inflector.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'log' . DS . 'file_log.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_log.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'sanitize.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'set.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'string.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'validation.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'object_collection.test.php');
|
||||
return $suite;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* AllTestSuiteTest file
|
||||
*
|
||||
* 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.tests.cases
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* AllTestSuiteTest class
|
||||
*
|
||||
* This test group will run socket class tests
|
||||
*
|
||||
* @package cake.tests.groups
|
||||
*/
|
||||
class AllTestSuiteTest extends PHPUnit_Framework_TestSuite {
|
||||
|
||||
/**
|
||||
* suite method, defines tests for this suite.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function suite() {
|
||||
$suite = new PHPUnit_Framework_TestSuite('All Test Suite classes tests');
|
||||
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'test_manager.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_case.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_fixture.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'html_coverage_report.test.php');
|
||||
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller_test_case.test.php');
|
||||
return $suite;
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* AllTests file
|
||||
*
|
||||
* 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.tests.cases
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
/**
|
||||
* AllTests class
|
||||
*
|
||||
* This test group will run all test in the cases/libs/models/behaviors directory
|
||||
*
|
||||
* @package cake.tests.groups
|
||||
*/
|
||||
class AllTests extends PHPUnit_Framework_TestSuite {
|
||||
|
||||
/**
|
||||
* Suite define the tests for this suite
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function suite() {
|
||||
$suite = new PHPUnit_Framework_TestSuite('All Tests');
|
||||
|
||||
$path = CORE_TEST_CASES . DS . 'libs' . DS;
|
||||
$console = CORE_TEST_CASES . DS . 'console' . DS;
|
||||
|
||||
$suite->addTestFile($console . 'all_console_libs.test.php');
|
||||
$suite->addTestFile($console . 'all_shells.test.php');
|
||||
$suite->addTestFile($console . 'all_tasks.test.php');
|
||||
|
||||
$suite->addTestFile($path . 'all_behaviors.test.php');
|
||||
$suite->addTestFile($path . 'all_cache_engines.test.php');
|
||||
$suite->addTestFile($path . 'all_components.test.php');
|
||||
$suite->addTestFile($path . 'all_configure.test.php');
|
||||
$suite->addTestFile($path . 'all_controllers.test.php');
|
||||
$suite->addTestFile($path . 'all_database.test.php');
|
||||
$suite->addTestFile($path . 'all_error.test.php');
|
||||
$suite->addTestFile($path . 'all_helpers.test.php');
|
||||
$suite->addTestFile($path . 'all_libs.test.php');
|
||||
$suite->addTestFile($path . 'all_localization.test.php');
|
||||
$suite->addTestFile($path . 'all_model.test.php');
|
||||
$suite->addTestFile($path . 'all_routing.test.php');
|
||||
$suite->addTestFile($path . 'all_socket.test.php');
|
||||
$suite->addTestFile($path . 'all_test_suite.test.php');;
|
||||
$suite->addTestFile($path . 'all_views.test.php');
|
||||
$suite->addTestFile($path . 'all_xml.test.php');
|
||||
return $suite;
|
||||
}
|
||||
}
|
|
@ -1,532 +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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TestManagerTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake.tests.cases.libs
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
class TestTestManager extends TestManager {
|
||||
|
||||
public function setTestSuite($testSuite) {
|
||||
$this->_testSuite = $testSuite;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TestManagerTest class
|
||||
*
|
||||
* @package cake.tests.cases.libs
|
||||
*/
|
||||
class TestManagerTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* Number of times the funcion PHPUnit_Framework_TestSuite::addTestFile() has been called
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_countFiles = 0;
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->_countFiles = 0;
|
||||
$this->TestManager = new TestTestManager();
|
||||
$this->testSuiteStub = $this->getMock('CakeTestSuite');
|
||||
|
||||
$this->testSuiteStub
|
||||
->expects($this->any())
|
||||
->method('addTestFile')
|
||||
->will($this->returnCallback(array(&$this, '_countIncludedTestFiles')));
|
||||
|
||||
$this->testSuiteStub
|
||||
->expects($this->any())
|
||||
->method('addTestSuite')
|
||||
->will($this->returnCallback(array(&$this, '_countIncludedTestFiles')));
|
||||
|
||||
$this->TestManager->setTestSuite($this->testSuiteStub);
|
||||
$this->Reporter = $this->getMock('CakeHtmlReporter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to count the number of times the
|
||||
* function PHPUnit_Framework_TestSuite::addTestFile() has been called
|
||||
* @return void
|
||||
*/
|
||||
public function _countIncludedTestFiles() {
|
||||
$this->_countFiles++;
|
||||
}
|
||||
|
||||
protected function _getAllTestFiles($directory = CORE_TEST_CASES, $type = 'test') {
|
||||
$folder = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
|
||||
$extension = str_replace('.', '\.', $this->TestManager->getExtension($type));
|
||||
$out = new RegexIterator($folder, '#^.+'.$extension.'$#i', RecursiveRegexIterator::GET_MATCH);
|
||||
|
||||
$files = array();
|
||||
foreach ($out as $testFile) {
|
||||
$files[] = $testFile[0];
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that trying to run an unexistent file throws an exception
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testRunUnexistentCase() {
|
||||
$file = md5(time());
|
||||
$result = $this->TestManager->runTestCase($file, $this->Reporter);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRunTestCase method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRunTestCase() {
|
||||
$file = 'libs/test_manager.test.php';
|
||||
$result = $this->TestManager->runTestCase($file, $this->Reporter, true);
|
||||
$this->assertEquals(1, $this->_countFiles);
|
||||
$this->assertInstanceOf('PHPUnit_Framework_TestResult', $result);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,299 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TestManager for CakePHP Test suite.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package cake.tests.lib
|
||||
* @since CakePHP(tm) v 1.2.0.4433
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
define('CORE_TEST_CASES', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'cases');
|
||||
define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups');
|
||||
define('APP_TEST_CASES', TESTS . 'cases');
|
||||
define('APP_TEST_GROUPS', TESTS . 'groups');
|
||||
|
||||
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
|
||||
require_once CAKE_TESTS_LIB . 'cake_test_suite.php';
|
||||
|
||||
/**
|
||||
* TestManager is the base class that handles loading and initiating the running
|
||||
* of TestCase and TestSuite classes that the user has selected.
|
||||
*
|
||||
* @package cake.tests.lib
|
||||
*/
|
||||
class TestManager {
|
||||
/**
|
||||
* Extension suffix for test case files.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $_testExtension = '.test.php';
|
||||
|
||||
/**
|
||||
* Is this test an AppTest?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $appTest = false;
|
||||
|
||||
/**
|
||||
* Is this test a plugin test?
|
||||
*
|
||||
* @var mixed boolean false or string name of the plugin being used.
|
||||
*/
|
||||
public $pluginTest = false;
|
||||
|
||||
/**
|
||||
* String to filter test case method names by.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $filter = false;
|
||||
|
||||
/**
|
||||
* TestSuite container for single or grouped test files
|
||||
*
|
||||
* @var PHPUnit_Framework_TestSuite
|
||||
*/
|
||||
protected $_testSuite = null;
|
||||
|
||||
/**
|
||||
* Object instance responsible for managing the test fixtures
|
||||
*
|
||||
* @var CakeFixtureManager
|
||||
*/
|
||||
protected $_fixtureManager = null;
|
||||
|
||||
/**
|
||||
* Params to configure test runner
|
||||
*
|
||||
* @var CakeFixtureManager
|
||||
*/
|
||||
public $params = array();
|
||||
|
||||
/**
|
||||
* Constructor for the TestManager class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params = array()) {
|
||||
require_once(CAKE_TESTS_LIB . 'cake_test_case.php');
|
||||
require_once(CAKE_TESTS_LIB . 'controller_test_case.php');
|
||||
|
||||
$this->params = $params;
|
||||
if (isset($params['app'])) {
|
||||
$this->appTest = true;
|
||||
}
|
||||
if (isset($params['plugin'])) {
|
||||
$this->pluginTest = htmlentities($params['plugin']);
|
||||
}
|
||||
if (
|
||||
isset($params['filter']) &&
|
||||
$params['filter'] !== false &&
|
||||
preg_match('/^[a-zA-Z0-9_]/', $params['filter'])
|
||||
) {
|
||||
$this->filter = '/' . $params['filter'] . '/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a specific test case file
|
||||
*
|
||||
* @param string $testCaseFile Filename of the test to be run.
|
||||
* @param PHPUnit_Framework_TestListener $reporter Reporter instance to attach to the test case.
|
||||
* @throws InvalidArgumentException if the supplied $testCaseFile does not exists
|
||||
* @return mixed Result of test case being run.
|
||||
*/
|
||||
public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $reporter, $codeCoverage = false) {
|
||||
$this->loadCase($testCaseFile);
|
||||
return $this->run($reporter, $codeCoverage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the main testSuite and attaches to it a reporter
|
||||
*
|
||||
* @param PHPUnit_Framework_TestListener $reporter Reporter instance to use with the group test being run.
|
||||
* @return PHPUnit_Framework_TestResult Result object of the test run.
|
||||
*/
|
||||
protected function run($reporter, $codeCoverage = false) {
|
||||
restore_error_handler();
|
||||
restore_error_handler();
|
||||
|
||||
$result = new PHPUnit_Framework_TestResult;
|
||||
$result->collectCodeCoverageInformation($codeCoverage);
|
||||
$result->addListener($reporter);
|
||||
$reporter->paintHeader();
|
||||
$testSuite = $this->getTestSuite();
|
||||
$testSuite->setFixtureManager($this->getFixtureManager());
|
||||
$testSuite->run($result, $this->filter);
|
||||
$reporter->paintResult($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a test case in a test suite, if the test suite is null it will create it
|
||||
*
|
||||
* @param string Test file path
|
||||
* @param PHPUnit_Framework_TestSuite $suite the test suite to load the case in
|
||||
* @throws InvalidArgumentException if test case file is not found
|
||||
* @return PHPUnit_Framework_TestSuite the suite with the test case loaded
|
||||
*/
|
||||
public function loadCase($testCaseFile, PHPUnit_Framework_TestSuite $suite = null) {
|
||||
$testCaseFileWithPath = $this->_getTestsPath($this->params) . DS . $testCaseFile;
|
||||
|
||||
if (!file_exists($testCaseFileWithPath) || strpos($testCaseFileWithPath, '..')) {
|
||||
throw new InvalidArgumentException(__('Unable to load test file %s', htmlentities($testCaseFile)));
|
||||
}
|
||||
if (!$suite) {
|
||||
$suite = $this->getTestSuite(__('Individual test case: %s', $testCaseFile));
|
||||
}
|
||||
$suite->addTestFile($testCaseFileWithPath);
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of test cases found in the current valid test case path
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static function getTestCaseList($params) {
|
||||
$directory = self::_getTestsPath($params);
|
||||
$fileList = self::_getTestFileList($directory);
|
||||
|
||||
$testCases = array();
|
||||
foreach ($fileList as $testCaseFile) {
|
||||
$testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile);
|
||||
}
|
||||
return $testCases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of test files from a given directory
|
||||
*
|
||||
* @param string $directory Directory to get test case files from.
|
||||
* @static
|
||||
*/
|
||||
protected static function &_getTestFileList($directory = '.') {
|
||||
$return = self::_getRecursiveFileList($directory, array('self', '_isTestCaseFile'));
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a recursive list of files from a given directory and matches then against
|
||||
* a given fileTestFunction, like isTestCaseFile()
|
||||
*
|
||||
* @param string $directory The directory to scan for files.
|
||||
* @param mixed $fileTestFunction
|
||||
* @static
|
||||
*/
|
||||
protected static function &_getRecursiveFileList($directory = '.', $fileTestFunction) {
|
||||
$fileList = array();
|
||||
if (!is_dir($directory)) {
|
||||
return $fileList;
|
||||
}
|
||||
|
||||
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isFile()) {
|
||||
continue;
|
||||
}
|
||||
$file = $file->getRealPath();
|
||||
|
||||
if (call_user_func_array($fileTestFunction, array($file))) {
|
||||
$fileList[] = $file;
|
||||
}
|
||||
}
|
||||
return $fileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a file has the correct test case extension
|
||||
*
|
||||
* @param string $file
|
||||
* @return boolean Whether $file is a test case.
|
||||
* @static
|
||||
*/
|
||||
protected static function _isTestCaseFile($file) {
|
||||
return self::_hasExpectedExtension($file, self::$_testExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file has a specific extension
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $extension
|
||||
* @return void
|
||||
* @static
|
||||
*/
|
||||
protected static function _hasExpectedExtension($file, $extension) {
|
||||
return $extension == strtolower(substr($file, (0 - strlen($extension))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given path to the test files depending on a given type of tests (core, app, plugin)
|
||||
*
|
||||
* @param array $params Array of parameters for getting test paths.
|
||||
* Can contain app, type, and plugin params.
|
||||
* @return string The path tests are located on
|
||||
* @static
|
||||
*/
|
||||
protected static function _getTestsPath($params) {
|
||||
$result = null;
|
||||
if (!empty($params['app'])) {
|
||||
$result = APP_TEST_CASES;
|
||||
} else if (!empty($params['plugin'])) {
|
||||
$pluginPath = App::pluginPath($params['plugin']);
|
||||
$result = $pluginPath . 'tests' . DS . 'cases';
|
||||
} else {
|
||||
$result = CORE_TEST_CASES;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extension for either 'group' or 'test' types.
|
||||
*
|
||||
* @param string $type Type of test to get, either 'test' or 'group'
|
||||
* @return string Extension suffix for test.
|
||||
*/
|
||||
public static function getExtension($type = 'test') {
|
||||
return self::$_testExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container testSuite instance for this runner or creates a new one
|
||||
*
|
||||
* @param string $name The name for the container test suite
|
||||
* @return PHPUnit_Framework_TestSuite container test suite
|
||||
*/
|
||||
public function getTestSuite($name = '') {
|
||||
if (!empty($this->_testSuite)) {
|
||||
return $this->_testSuite;
|
||||
}
|
||||
return $this->_testSuite = new CakeTestSuite($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of a Fixture manager to be used by the test cases
|
||||
*
|
||||
* @return CakeFixtureManager fixture manager
|
||||
*/
|
||||
public function getFixtureManager() {
|
||||
if (!empty($this->_fixtureManager)) {
|
||||
return $this->_fixtureManager;
|
||||
}
|
||||
return $this->_fixtureManager = new CakeFixtureManager;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* TestRunner for CakePHP Test suite.
|
||||
*
|
||||
* 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.tests.libs
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
|
||||
require 'PHPUnit/TextUI/Command.php';
|
||||
require_once 'test_manager.php';
|
||||
|
||||
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
|
||||
|
||||
/**
|
||||
* Class to customize loading of test suites from CLI
|
||||
*
|
||||
* @package cake.tests.lib
|
||||
*/
|
||||
class TestRunner extends PHPUnit_TextUI_Command {
|
||||
|
||||
/**
|
||||
* Construct method
|
||||
*
|
||||
* @param array $params list of options to be used for this run
|
||||
*/
|
||||
public function __construct($params = array()) {
|
||||
$this->_params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the proper test suite to use and loads the test file in it.
|
||||
* this method gets called as a callback from the parent class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handleCustomTestSuite() {
|
||||
$manager = new TestManager($this->_params);
|
||||
|
||||
if (!empty($this->_params['case'])) {
|
||||
$this->arguments['test'] = $manager->getTestSuite();
|
||||
$this->arguments['test']->setFixtureManager($manager->getFixtureManager());
|
||||
$manager->loadCase($this->_params['case'] . '.test.php', $this->arguments['test']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
|
||||
class TestLocalDriver extends TestSource {
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
<h2>Sweet, "Test App" got Baked by CakePHP!</h2>
|
||||
<p>
|
||||
<?php
|
||||
if (is_writable(TMP)):
|
||||
echo '<span class="notice success">';
|
||||
echo __('Your tmp directory is writable.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Your tmp directory is NOT writable.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
$settings = array();
|
||||
if (!empty($settings)):
|
||||
echo '<span class="notice success">';
|
||||
echo __('The %s is being used for caching. To change the config edit APP/config/core.php ', '<em>'. $settings['engine'] . 'Engine</em>');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Your cache is NOT working. Please check the settings in APP/config/core.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
$filePresent = null;
|
||||
if (file_exists(CONFIGS . 'database.php')):
|
||||
echo '<span class="notice success">';
|
||||
echo __('Your database configuration file is present.');
|
||||
$filePresent = true;
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Your database configuration file is NOT present.');
|
||||
echo '<br/>';
|
||||
echo __('Rename config/database.php.default to config/database.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty($filePresent)):
|
||||
if (!class_exists('ConnectionManager')) {
|
||||
require LIBS . 'model' . DS . 'connection_manager.php';
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
if (true):
|
||||
echo '<span class="notice success">';
|
||||
echo __('Cake is able to connect to the database.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
echo __('Cake is NOT able to connect to the database.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php endif;?>
|
||||
<h3><?php echo __('Editing this Page') ?></h3>
|
||||
<p>
|
||||
<?php
|
||||
echo __('To change the content of this page, edit: %s
|
||||
To change its layout, edit: %s
|
||||
You can also add some CSS styles for your pages at: %s',
|
||||
APP . 'views' . DS . 'pages' . DS . 'home.ctp.<br />', APP . 'views' . DS . 'layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');
|
||||
?>
|
||||
</p>
|
|
@ -1,143 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* 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.view.templates.pages
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<p>
|
||||
<!--nocache-->
|
||||
<span class="notice">
|
||||
<?php
|
||||
echo __('Your tmp directory is ');
|
||||
if (is_writable(TMP)):
|
||||
echo __('writable.');
|
||||
else:
|
||||
echo __('NOT writable.');
|
||||
endif;
|
||||
?>
|
||||
</span>
|
||||
<!--/nocache-->
|
||||
</p>
|
||||
<p>
|
||||
<span class="notice">
|
||||
<?php
|
||||
echo __('Your cache is ');
|
||||
if (Cache::isInitialized('default')):
|
||||
echo __('set up and initialized properly.');
|
||||
$settings = Cache::settings();
|
||||
echo '<p>' . $settings['engine'];
|
||||
echo __(' is being used to cache, to change this edit config/core.php ');
|
||||
echo '</p>';
|
||||
|
||||
echo 'Settings: <ul>';
|
||||
foreach ($settings as $name => $value):
|
||||
echo '<li>' . $name . ': ' . $value . '</li>';
|
||||
endforeach;
|
||||
echo '</ul>';
|
||||
|
||||
else:
|
||||
echo __('NOT working.');
|
||||
echo '<br />';
|
||||
if (is_writable(TMP)):
|
||||
echo __('Edit: config/core.php to insure you have the newset version of this file and the variable $cakeCache set properly');
|
||||
endif;
|
||||
endif;
|
||||
?>
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
<span class="notice">
|
||||
<?php
|
||||
echo __('Your database configuration file is ');
|
||||
$filePresent = null;
|
||||
if (file_exists(CONFIGS.'database.php')):
|
||||
echo __('present.');
|
||||
$filePresent = true;
|
||||
else:
|
||||
echo __('NOT present.');
|
||||
echo '<br/>';
|
||||
echo __('Rename config/database.php.default to config/database.php');
|
||||
endif;
|
||||
?>
|
||||
</span>
|
||||
</p>
|
||||
<?php
|
||||
if (!empty($filePresent)):
|
||||
if (!class_exists('ConnectionManager')) {
|
||||
require LIBS . 'model' . DS . 'connection_manager.php';
|
||||
}
|
||||
$db = ConnectionManager::getInstance();
|
||||
$connected = $db->getDataSource('default');
|
||||
?>
|
||||
<p>
|
||||
<span class="notice">
|
||||
<?php
|
||||
__('Cake');
|
||||
if ($connected->isConnected()):
|
||||
__(' is able to ');
|
||||
else:
|
||||
__(' is NOT able to ');
|
||||
endif;
|
||||
__('connect to the database.');
|
||||
?>
|
||||
</span>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<h2><?php echo __('Release Notes for CakePHP %s.', Configure::version()); ?></h2>
|
||||
<a href="https://trac.cakephp.org/wiki/notes/1.2.x.x"><?php __('Read the release notes and get the latest version'); ?> </a>
|
||||
<h2><?php __('Editing this Page'); ?></h2>
|
||||
<p>
|
||||
<?php __('To change the content of this page, create: /app/views/pages/home.ctp.'); ?><br />
|
||||
<?php __('To change its layout, create: /app/views/layouts/default.ctp.'); ?><br />
|
||||
<a href="http://manual.cakephp.org/"><?php __('See the views section of the manual for more info.'); ?> </a><br />
|
||||
<?php __('You can also add some CSS styles for your pages at: app/webroot/css/.'); ?>
|
||||
</p>
|
||||
<h2><?php __('Getting Started'); ?></h2>
|
||||
<p>
|
||||
<a href="http://manual.cakephp.org/appendix/blog_tutorial"><?php __('The 15 min Blog Tutorial'); ?></a><br />
|
||||
<a href="http://www-128.ibm.com/developerworks/edu/os-dw-os-php-cake1.html"><?php __('Cook up Web sites fast with CakePHP'); ?></a><br />
|
||||
<a href="http://www-128.ibm.com/developerworks/edu/os-dw-os-php-wiki1.html"><?php __('Create an interactive production wiki using PHP'); ?></a>
|
||||
</p>
|
||||
<h2><?php __('More about Cake'); ?></h2>
|
||||
<p>
|
||||
<?php __('CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Active Record, Association Data Mapping, Front Controller and MVC.'); ?>
|
||||
</p>
|
||||
<p>
|
||||
<?php __('Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.'); ?>
|
||||
</p>
|
||||
<ul>
|
||||
<li><a href="http://cakefoundation.org/"><?php __('Cake Software Foundation'); ?> </a>
|
||||
<ul><li><?php __('Promoting development related to CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://bakery.cakephp.org"><?php __('The Bakery'); ?> </a>
|
||||
<ul><li><?php __('Everything CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://astore.amazon.com/cakesoftwaref-20/"><?php __('Book Store'); ?> </a>
|
||||
<ul><li><?php __('Recommended Software Books'); ?></li></ul></li>
|
||||
<li><a href="http://www.cafepress.com/cakefoundation"><?php __('CakeSchwag'); ?> </a>
|
||||
<ul><li><?php __('Get your own CakePHP gear - Doughnate to Cake'); ?></li></ul></li>
|
||||
<li><a href="http://www.cakephp.org"><?php __('CakePHP'); ?> </a>
|
||||
<ul><li><?php __('The Rapid Development Framework'); ?></li></ul></li>
|
||||
<li><a href="http://manual.cakephp.org"><?php __('CakePHP Manual'); ?> </a>
|
||||
<ul><li><?php __('Your Rapid Development Cookbook'); ?></li></ul></li>
|
||||
<li><a href="http://api.cakephp.org"><?php __('CakePHP API'); ?> </a>
|
||||
<ul><li><?php __('Docblock Your Best Friend'); ?></li></ul></li>
|
||||
<li><a href="http://www.cakeforge.org"><?php __('CakeForge'); ?> </a>
|
||||
<ul><li><?php __('Open Development for CakePHP'); ?></li></ul></li>
|
||||
<li><a href="https://trac.cakephp.org/"><?php __('CakePHP Trac'); ?> </a>
|
||||
<ul><li><?php __('For the Development of CakePHP (Tickets, SVN browser, Roadmap, Changelogs)'); ?></li></ul></li>
|
||||
<li><a href="http://groups-beta.google.com/group/cake-php"><?php __('CakePHP Google Group'); ?> </a>
|
||||
<ul><li><?php __('Community mailing list'); ?></li></ul></li>
|
||||
<li><a href="irc://irc.freenode.net/cakephp">irc.freenode.net #cakephp</a>
|
||||
<ul><li><?php __('Live chat about CakePHP'); ?></li></ul></li>
|
||||
</ul>
|
|
@ -18,6 +18,8 @@
|
|||
* @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
|
||||
* to use several different Cache engines, without coupling your application to a specific
|
||||
|
@ -71,14 +73,39 @@ class Cache {
|
|||
* both create new configurations, return the settings for already configured
|
||||
* configurations.
|
||||
*
|
||||
* To create a new configuration:
|
||||
* To create a new configuration, or to modify an existing configuration permanently:
|
||||
*
|
||||
* `Cache::config('my_config', array('engine' => 'File', 'path' => TMP));`
|
||||
*
|
||||
* To get the settings for a configuration, and set it as the currently selected configuration
|
||||
* If you need to modify a configuration temporarily, use Cache::set().
|
||||
* To get the settings for a configuration:
|
||||
*
|
||||
* `Cache::config('default');`
|
||||
*
|
||||
* There are 4 built-in caching engines:
|
||||
*
|
||||
* - `FileEngine` - Uses simple files to store content. Poor performance, but good for
|
||||
* storing large objects, or things that are not IO sensitive.
|
||||
* - `ApcEngine` - Uses the APC object cache, one of the fastest caching engines.
|
||||
* - `MemcacheEngine` - Uses the PECL::Memcache extension and Memcached for storage.
|
||||
* Fast reads/writes, and benefits from memcache being distributed.
|
||||
* - `XcacheEngine` - Uses the Xcache extension, an alternative to APC.
|
||||
*
|
||||
* The following keys are used in core cache engines:
|
||||
*
|
||||
* - `duration` Specify how long items in this cache configuration last.
|
||||
* - `prefix` Prefix appended to all entries. Good for when you need to share a keyspace
|
||||
* with either another cache config or annother application.
|
||||
* - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable
|
||||
* cache::gc from ever being called automatically.
|
||||
* - `servers' Used by memcache. Give the address of the memcached servers to use.
|
||||
* - `compress` Used by memcache. Enables memcache's compressed format.
|
||||
* - `serialize` Used by FileCache. Should cache objects be serialized first.
|
||||
* - `path` Used by FileCache. Path to where cachefiles should be saved.
|
||||
* - `lock` Used by FileCache. Should files be locked before writing to them?
|
||||
* - `user` Used by Xcache. Username for XCache
|
||||
* - `password` Used by Xcache. Password for XCache
|
||||
*
|
||||
* @see app/config/core.php for configuration settings
|
||||
* @param string $name Name of the configuration
|
||||
* @param array $settings Optional associative array of settings passed to the engine
|
||||
|
@ -123,18 +150,19 @@ class Cache {
|
|||
protected static function _buildEngine($name) {
|
||||
$config = self::$_config[$name];
|
||||
|
||||
list($plugin, $class) = pluginSplit($config['engine']);
|
||||
list($plugin, $class) = pluginSplit($config['engine'], true);
|
||||
$cacheClass = $class . 'Engine';
|
||||
if (!class_exists($cacheClass) && self::_loadEngine($class, $plugin) === false) {
|
||||
App::uses($cacheClass, $plugin . 'Cache/Engine');
|
||||
if (!class_exists($cacheClass)) {
|
||||
return false;
|
||||
}
|
||||
$cacheClass = $class . 'Engine';
|
||||
if (!is_subclass_of($cacheClass, 'CacheEngine')) {
|
||||
throw new CacheException(__('Cache engines must use CacheEngine as a base class.'));
|
||||
throw new CacheException(__d('cake_dev', 'Cache engines must use CacheEngine as a base class.'));
|
||||
}
|
||||
self::$_engines[$name] = new $cacheClass();
|
||||
if (self::$_engines[$name]->init($config)) {
|
||||
if (time() % self::$_engines[$name]->settings['probability'] === 0) {
|
||||
if (self::$_engines[$name]->settings['probability'] && time() % self::$_engines[$name]->settings['probability'] === 0) {
|
||||
self::$_engines[$name]->gc();
|
||||
}
|
||||
return true;
|
||||
|
@ -167,26 +195,6 @@ class Cache {
|
|||
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
|
||||
* operation (write, decrement, increment, clear). Any reads that are done before the write, will
|
||||
|
@ -290,7 +298,7 @@ class Cache {
|
|||
self::set(null, $config);
|
||||
if ($success === false && $value !== '') {
|
||||
trigger_error(
|
||||
__("%s cache was unable to write '%s' to cache", $config, $key),
|
||||
__d('cake_dev', "%s cache was unable to write '%s' to cache", $config, $key),
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* File Storage engine for cache
|
||||
* File Storage engine for cache. Filestorage is the slowest cache storage
|
||||
* to read and write. However, it is good for servers that don't have other storage
|
||||
* engine available, or have content which is not performance sensitive.
|
||||
*
|
||||
* You can configure a FileEngine cache, using Cache::config()
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
|
@ -13,7 +16,6 @@
|
|||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake.libs.cache
|
||||
* @since CakePHP(tm) v 1.2.0.4933
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
@ -21,7 +23,6 @@
|
|||
/**
|
||||
* File Storage engine for cache
|
||||
*
|
||||
* @todo use the File and Folder classes (if it's not a too big performance hit)
|
||||
* @package cake.libs.cache
|
||||
*/
|
||||
class FileEngine extends CacheEngine {
|
||||
|
@ -250,7 +251,7 @@ class FileEngine extends CacheEngine {
|
|||
* @throws CacheException
|
||||
*/
|
||||
public function decrement($key, $offset = 1) {
|
||||
throw new CacheException(__('Files cannot be atomically decremented.'));
|
||||
throw new CacheException(__d('cake_dev', 'Files cannot be atomically decremented.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -260,7 +261,7 @@ class FileEngine extends CacheEngine {
|
|||
* @throws CacheException
|
||||
*/
|
||||
public function increment($key, $offset = 1) {
|
||||
throw new CacheException(__('Files cannot be atomically incremented.'));
|
||||
throw new CacheException(__d('cake_dev', 'Files cannot be atomically incremented.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,7 +297,7 @@ class FileEngine extends CacheEngine {
|
|||
$dir = new SplFileInfo($this->settings['path']);
|
||||
if ($this->_init && !($dir->isDir() && $dir->isWritable())) {
|
||||
$this->_init = false;
|
||||
trigger_error(__('%s is not writable', $this->settings['path']), E_USER_WARNING);
|
||||
trigger_error(__d('cake_dev', '%s is not writable', $this->settings['path']), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
|
@ -33,7 +33,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @var Memcache
|
||||
* @access private
|
||||
*/
|
||||
private $__Memcache = null;
|
||||
protected $_Memcache = null;
|
||||
|
||||
/**
|
||||
* Settings
|
||||
|
@ -74,12 +74,12 @@ class MemcacheEngine extends CacheEngine {
|
|||
if (!is_array($this->settings['servers'])) {
|
||||
$this->settings['servers'] = array($this->settings['servers']);
|
||||
}
|
||||
if (!isset($this->__Memcache)) {
|
||||
if (!isset($this->_Memcache)) {
|
||||
$return = false;
|
||||
$this->__Memcache = new Memcache();
|
||||
$this->_Memcache = new Memcache();
|
||||
foreach ($this->settings['servers'] as $server) {
|
||||
list($host, $port) = $this->_parseServerString($server);
|
||||
if ($this->__Memcache->addServer($host, $port)) {
|
||||
if ($this->_Memcache->addServer($host, $port)) {
|
||||
$return = true;
|
||||
}
|
||||
}
|
||||
|
@ -116,8 +116,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
/**
|
||||
* Write data for key into cache. When using memcache as your cache engine
|
||||
* remember that the Memcache pecl extension does not support cache expiry times greater
|
||||
* than 30 days in the future. If you wish to create cache entries that do not expire, set the duration
|
||||
* to `0` in your cache configuration.
|
||||
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param mixed $value Data to be cached
|
||||
|
@ -126,7 +125,10 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @see http://php.net/manual/en/memcache.set.php
|
||||
*/
|
||||
public function write($key, $value, $duration) {
|
||||
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
|
||||
if ($duration > 30 * DAY) {
|
||||
$duration = 0;
|
||||
}
|
||||
return $this->_Memcache->set($key, $value, $this->settings['compress'], $duration);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,7 +138,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
|
||||
*/
|
||||
public function read($key) {
|
||||
return $this->__Memcache->get($key);
|
||||
return $this->_Memcache->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,10 +153,10 @@ class MemcacheEngine extends CacheEngine {
|
|||
public function increment($key, $offset = 1) {
|
||||
if ($this->settings['compress']) {
|
||||
throw new CacheException(
|
||||
__('Method increment() not implemented for compressed cache in %s', __CLASS__)
|
||||
__d('cake_dev', 'Method increment() not implemented for compressed cache in %s', __CLASS__)
|
||||
);
|
||||
}
|
||||
return $this->__Memcache->increment($key, $offset);
|
||||
return $this->_Memcache->increment($key, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,10 +171,10 @@ class MemcacheEngine extends CacheEngine {
|
|||
public function decrement($key, $offset = 1) {
|
||||
if ($this->settings['compress']) {
|
||||
throw new CacheException(
|
||||
__('Method decrement() not implemented for compressed cache in %s', __CLASS__)
|
||||
__d('cake_dev', 'Method decrement() not implemented for compressed cache in %s', __CLASS__)
|
||||
);
|
||||
}
|
||||
return $this->__Memcache->decrement($key, $offset);
|
||||
return $this->_Memcache->decrement($key, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,7 +184,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
|
||||
*/
|
||||
public function delete($key) {
|
||||
return $this->__Memcache->delete($key);
|
||||
return $this->_Memcache->delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,7 +193,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @return boolean True if the cache was succesfully cleared, false otherwise
|
||||
*/
|
||||
public function clear($check) {
|
||||
return $this->__Memcache->flush();
|
||||
return $this->_Memcache->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,8 +204,8 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @return boolean True if memcache server was connected
|
||||
*/
|
||||
public function connect($host, $port = 11211) {
|
||||
if ($this->__Memcache->getServerStatus($host, $port) === 0) {
|
||||
if ($this->__Memcache->connect($host, $port)) {
|
||||
if ($this->_Memcache->getServerStatus($host, $port) === 0) {
|
||||
if ($this->_Memcache->connect($host, $port)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
|
@ -71,13 +71,24 @@ class IniReader implements ConfigReaderInterface {
|
|||
*/
|
||||
public function read($file) {
|
||||
$filename = $this->_path . $file;
|
||||
if (!file_exists($filename)) {
|
||||
$filename .= '.ini';
|
||||
if (!file_exists($filename)) {
|
||||
throw new ConfigureException(__d('cake_dev', 'Could not load configuration files: %s or %s', substr($filename, 0, -4), $filename));
|
||||
}
|
||||
}
|
||||
$contents = parse_ini_file($filename, true);
|
||||
if (!empty($this->_section) && isset($contents[$this->_section])) {
|
||||
$values = $this->_parseNestedValues($contents[$this->_section]);
|
||||
} else {
|
||||
$values = array();
|
||||
foreach ($contents as $section => $attribs) {
|
||||
$values[$section] = $this->_parseNestedValues($attribs);
|
||||
if (is_array($attribs)) {
|
||||
$values[$section] = $this->_parseNestedValues($attribs);
|
||||
} else {
|
||||
$parse = $this->_parseNestedValues(array($attribs));
|
||||
$values[$section] = array_shift($parse);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
|
@ -55,22 +55,28 @@ class PhpReader implements ConfigReaderInterface {
|
|||
*/
|
||||
public function read($key) {
|
||||
if (strpos($key, '..') !== false) {
|
||||
throw new ConfigureException(__('Cannot load configuration files with ../ in them.'));
|
||||
throw new ConfigureException(__d('cake_dev', 'Cannot load configuration files with ../ in them.'));
|
||||
}
|
||||
if (substr($key, -4) === '.php') {
|
||||
$key = substr($key, 0, -4);
|
||||
}
|
||||
list($plugin, $key) = pluginSplit($key);
|
||||
|
||||
if ($plugin) {
|
||||
$file = App::pluginPath($plugin) . 'config' . DS . $key . '.php';
|
||||
$file = App::pluginPath($plugin) . 'config' . DS . $key;
|
||||
} else {
|
||||
$file = $this->_path . $key . '.php';
|
||||
$file = $this->_path . $key;
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
throw new ConfigureException(__('Could not load configuration file: ') . $file);
|
||||
$file .= '.php';
|
||||
if (!file_exists($file)) {
|
||||
throw new ConfigureException(__d('cake_dev', 'Could not load configuration files: %s or %s', substr($file, 0, -4), $file));
|
||||
}
|
||||
}
|
||||
include $file;
|
||||
if (!isset($config)) {
|
||||
throw new ConfigureException(
|
||||
sprintf(__('No variable $config found in %s.php'), $file)
|
||||
sprintf(__d('cake_dev', 'No variable $config found in %s.php'), $file)
|
||||
);
|
||||
}
|
||||
return $config;
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
/**
|
||||
* 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
|
||||
* will inherit them.
|
|
@ -16,8 +16,8 @@
|
|||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Component', 'Acl');
|
||||
App::import('Model', 'DbAcl');
|
||||
App::uses('AclComponent', 'Controller/Component');
|
||||
App::uses('DbAcl', 'Model');
|
||||
|
||||
/**
|
||||
* Shell for ACL management. This console is known to have issues with zend.ze1_compatibility_mode
|
||||
|
@ -71,12 +71,12 @@ class AclShell extends Shell {
|
|||
|
||||
if (!in_array(Configure::read('Acl.classname'), array('DbAcl', 'DB_ACL'))) {
|
||||
$out = "--------------------------------------------------\n";
|
||||
$out .= __('Error: Your current Cake configuration is set to') . "\n";
|
||||
$out .= __('an ACL implementation other than DB. Please change') . "\n";
|
||||
$out .= __('your core config to reflect your decision to use') . "\n";
|
||||
$out .= __('DbAcl before attempting to use this script') . ".\n";
|
||||
$out .= __d('cake_console', 'Error: Your current Cake configuration is set to') . "\n";
|
||||
$out .= __d('cake_console', 'an ACL implementation other than DB. Please change') . "\n";
|
||||
$out .= __d('cake_console', 'your core config to reflect your decision to use') . "\n";
|
||||
$out .= __d('cake_console', 'DbAcl before attempting to use this script') . ".\n";
|
||||
$out .= "--------------------------------------------------\n";
|
||||
$out .= __('Current ACL Classname: %s', Configure::read('Acl.classname')) . "\n";
|
||||
$out .= __d('cake_console', 'Current ACL Classname: %s', Configure::read('Acl.classname')) . "\n";
|
||||
$out .= "--------------------------------------------------\n";
|
||||
$this->err($out);
|
||||
$this->_stop();
|
||||
|
@ -84,7 +84,7 @@ class AclShell extends Shell {
|
|||
|
||||
if ($this->command) {
|
||||
if (!config('database')) {
|
||||
$this->out(__('Your database configuration was not found. Take a moment to create one.'), true);
|
||||
$this->out(__d('cake_console', 'Your database configuration was not found. Take a moment to create one.'), true);
|
||||
$this->args = null;
|
||||
return $this->DbConfig->execute();
|
||||
}
|
||||
|
@ -127,15 +127,15 @@ class AclShell extends Shell {
|
|||
if (is_string($data) && $data != '/') {
|
||||
$data = array('alias' => $data);
|
||||
} elseif (is_string($data)) {
|
||||
$this->error(__('/ can not be used as an alias!') . __(" / is the root, please supply a sub alias"));
|
||||
$this->error(__d('cake_console', '/ can not be used as an alias!') . __d('cake_console', " / is the root, please supply a sub alias"));
|
||||
}
|
||||
|
||||
$data['parent_id'] = $parent;
|
||||
$this->Acl->{$class}->create();
|
||||
if ($this->Acl->{$class}->save($data)) {
|
||||
$this->out(__("<success>New %s</success> '%s' created.", $class, $this->args[2]), 2);
|
||||
$this->out(__d('cake_console', "<success>New %s</success> '%s' created.", $class, $this->args[2]), 2);
|
||||
} else {
|
||||
$this->err(__("There was a problem creating a new %s '%s'.", $class, $this->args[2]));
|
||||
$this->err(__d('cake_console', "There was a problem creating a new %s '%s'.", $class, $this->args[2]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,9 +150,9 @@ class AclShell extends Shell {
|
|||
$nodeId = $this->_getNodeId($class, $identifier);
|
||||
|
||||
if (!$this->Acl->{$class}->delete($nodeId)) {
|
||||
$this->error(__('Node Not Deleted') . __('There was an error deleting the %s. Check that the node exists', $class) . ".\n");
|
||||
$this->error(__d('cake_console', 'Node Not Deleted') . __d('cake_console', 'There was an error deleting the %s. Check that the node exists', $class) . ".\n");
|
||||
}
|
||||
$this->out(__('<success>%s deleted.</success>', $class), 2);
|
||||
$this->out(__d('cake_console', '<success>%s deleted.</success>', $class), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,9 +172,9 @@ class AclShell extends Shell {
|
|||
);
|
||||
$this->Acl->{$class}->create();
|
||||
if (!$this->Acl->{$class}->save($data)) {
|
||||
$this->out(__('Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.'), true);
|
||||
$this->out(__d('cake_console', 'Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.'), true);
|
||||
} else {
|
||||
$this->out(__('Node parent set to %s', $this->args[2]) . "\n", true);
|
||||
$this->out(__d('cake_console', 'Node parent set to %s', $this->args[2]) . "\n", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,11 +191,11 @@ class AclShell extends Shell {
|
|||
|
||||
if (empty($nodes)) {
|
||||
$this->error(
|
||||
__("Supplied Node '%s' not found", $this->args[1]),
|
||||
__('No tree returned.')
|
||||
__d('cake_console', "Supplied Node '%s' not found", $this->args[1]),
|
||||
__d('cake_console', 'No tree returned.')
|
||||
);
|
||||
}
|
||||
$this->out(__('Path:'));
|
||||
$this->out(__d('cake_console', 'Path:'));
|
||||
$this->hr();
|
||||
for ($i = 0; $i < count($nodes); $i++) {
|
||||
$this->_outputNode($class, $nodes[$i], $i);
|
||||
|
@ -228,9 +228,9 @@ class AclShell extends Shell {
|
|||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->check($aro, $aco, $action)) {
|
||||
$this->out(__('%s is <success>allowed</success>.', $aroName), true);
|
||||
$this->out(__d('cake_console', '%s is <success>allowed</success>.', $aroName), true);
|
||||
} else {
|
||||
$this->out(__('%s is <error>not allowed</error>.', $aroName), true);
|
||||
$this->out(__d('cake_console', '%s is <error>not allowed</error>.', $aroName), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,9 +242,9 @@ class AclShell extends Shell {
|
|||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->allow($aro, $aco, $action)) {
|
||||
$this->out(__('Permission <success>granted</success>.'), true);
|
||||
$this->out(__d('cake_console', 'Permission <success>granted</success>.'), true);
|
||||
} else {
|
||||
$this->out(__('Permission was <error>not granted</error>.'), true);
|
||||
$this->out(__d('cake_console', 'Permission was <error>not granted</error>.'), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,9 +256,9 @@ class AclShell extends Shell {
|
|||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->deny($aro, $aco, $action)) {
|
||||
$this->out(__('Permission denied.'), true);
|
||||
$this->out(__d('cake_console', 'Permission denied.'), true);
|
||||
} else {
|
||||
$this->out(__('Permission was not denied.'), true);
|
||||
$this->out(__d('cake_console', 'Permission was not denied.'), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,9 +270,9 @@ class AclShell extends Shell {
|
|||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->inherit($aro, $aco, $action)) {
|
||||
$this->out(__('Permission inherited.'), true);
|
||||
$this->out(__d('cake_console', 'Permission inherited.'), true);
|
||||
} else {
|
||||
$this->out(__('Permission was not inherited.'), true);
|
||||
$this->out(__d('cake_console', 'Permission was not inherited.'), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,9 +303,9 @@ class AclShell extends Shell {
|
|||
|
||||
if (empty($nodes)) {
|
||||
if (isset($this->args[1])) {
|
||||
$this->error(__('%s not found', $this->args[1]), __('No tree returned.'));
|
||||
$this->error(__d('cake_console', '%s not found', $this->args[1]), __d('cake_console', 'No tree returned.'));
|
||||
} elseif (isset($this->args[0])) {
|
||||
$this->error(__('%s not found', $this->args[0]), __('No tree returned.'));
|
||||
$this->error(__d('cake_console', '%s not found', $this->args[0]), __d('cake_console', 'No tree returned.'));
|
||||
}
|
||||
}
|
||||
$this->out($class . " tree:");
|
||||
|
@ -354,140 +354,140 @@ class AclShell extends Shell {
|
|||
$type = array(
|
||||
'choices' => array('aro', 'aco'),
|
||||
'required' => true,
|
||||
'help' => __('Type of node to create.')
|
||||
'help' => __d('cake_console', 'Type of node to create.')
|
||||
);
|
||||
|
||||
$parser->description('A console tool for managing the DbAcl')
|
||||
->addSubcommand('create', array(
|
||||
'help' => __('Create a new ACL node'),
|
||||
'help' => __d('cake_console', 'Create a new ACL node'),
|
||||
'parser' => array(
|
||||
'description' => __('Creates a new ACL object <node> under the parent'),
|
||||
'description' => __d('cake_console', 'Creates a new ACL object <node> under the parent'),
|
||||
'arguments' => array(
|
||||
'type' => $type,
|
||||
'parent' => array(
|
||||
'help' => __('The node selector for the parent.'),
|
||||
'help' => __d('cake_console', 'The node selector for the parent.'),
|
||||
'required' => true
|
||||
),
|
||||
'alias' => array(
|
||||
'help' => __('The alias to use for the newly created node.'),
|
||||
'help' => __d('cake_console', 'The alias to use for the newly created node.'),
|
||||
'required' => true
|
||||
)
|
||||
)
|
||||
)
|
||||
))->addSubcommand('delete', array(
|
||||
'help' => __('Deletes the ACL object with the given <node> reference'),
|
||||
'help' => __d('cake_console', 'Deletes the ACL object with the given <node> reference'),
|
||||
'parser' => array(
|
||||
'description' => __('Delete an ACL node.'),
|
||||
'description' => __d('cake_console', 'Delete an ACL node.'),
|
||||
'arguments' => array(
|
||||
'type' => $type,
|
||||
'node' => array(
|
||||
'help' => __('The node identifier to delete.'),
|
||||
'help' => __d('cake_console', 'The node identifier to delete.'),
|
||||
'required' => true,
|
||||
)
|
||||
)
|
||||
)
|
||||
))->addSubcommand('setparent', array(
|
||||
'help' => __('Moves the ACL node under a new parent.'),
|
||||
'help' => __d('cake_console', 'Moves the ACL node under a new parent.'),
|
||||
'parser' => array(
|
||||
'description' => __('Moves the ACL object specified by <node> beneath <parent>'),
|
||||
'description' => __d('cake_console', 'Moves the ACL object specified by <node> beneath <parent>'),
|
||||
'arguments' => array(
|
||||
'type' => $type,
|
||||
'node' => array(
|
||||
'help' => __('The node to move'),
|
||||
'help' => __d('cake_console', 'The node to move'),
|
||||
'required' => true,
|
||||
),
|
||||
'parent' => array(
|
||||
'help' => __('The new parent for <node>.'),
|
||||
'help' => __d('cake_console', 'The new parent for <node>.'),
|
||||
'required' => true
|
||||
)
|
||||
)
|
||||
)
|
||||
))->addSubcommand('getpath', array(
|
||||
'help' => __('Print out the path to an ACL node.'),
|
||||
'help' => __d('cake_console', 'Print out the path to an ACL node.'),
|
||||
'parser' => array(
|
||||
'description' => array(
|
||||
__("Returns the path to the ACL object specified by <node>."),
|
||||
__("This command is useful in determining the inhertiance of permissions"),
|
||||
__("for a certain object in the tree.")
|
||||
__d('cake_console', "Returns the path to the ACL object specified by <node>."),
|
||||
__d('cake_console', "This command is useful in determining the inhertiance of permissions"),
|
||||
__d('cake_console', "for a certain object in the tree.")
|
||||
),
|
||||
'arguments' => array(
|
||||
'type' => $type,
|
||||
'node' => array(
|
||||
'help' => __('The node to get the path of'),
|
||||
'help' => __d('cake_console', 'The node to get the path of'),
|
||||
'required' => true,
|
||||
)
|
||||
)
|
||||
)
|
||||
))->addSubcommand('check', array(
|
||||
'help' => __('Check the permissions between an ACO and ARO.'),
|
||||
'help' => __d('cake_console', 'Check the permissions between an ACO and ARO.'),
|
||||
'parser' => array(
|
||||
'description' => array(
|
||||
__("Use this command to grant ACL permissions. Once executed, the ARO "),
|
||||
__("specified (and its children, if any) will have ALLOW access to the"),
|
||||
__("specified ACO action (and the ACO's children, if any).")
|
||||
__d('cake_console', "Use this command to grant ACL permissions. Once executed, the ARO "),
|
||||
__d('cake_console', "specified (and its children, if any) will have ALLOW access to the"),
|
||||
__d('cake_console', "specified ACO action (and the ACO's children, if any).")
|
||||
),
|
||||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to check.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to check.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to check'), 'default' => 'all')
|
||||
'aro' => array('help' => __d('cake_console', 'ARO to check.'), 'required' => true),
|
||||
'aco' => array('help' => __d('cake_console', 'ACO to check.'), 'required' => true),
|
||||
'action' => array('help' => __d('cake_console', 'Action to check'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('grant', array(
|
||||
'help' => __('Grant an ARO permissions to an ACO.'),
|
||||
'help' => __d('cake_console', 'Grant an ARO permissions to an ACO.'),
|
||||
'parser' => array(
|
||||
'description' => array(
|
||||
__("Use this command to grant ACL permissions. Once executed, the ARO"),
|
||||
__("specified (and its children, if any) will have ALLOW access to the"),
|
||||
__("specified ACO action (and the ACO's children, if any).")
|
||||
__d('cake_console', "Use this command to grant ACL permissions. Once executed, the ARO"),
|
||||
__d('cake_console', "specified (and its children, if any) will have ALLOW access to the"),
|
||||
__d('cake_console', "specified ACO action (and the ACO's children, if any).")
|
||||
),
|
||||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to grant permission to.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to grant access to.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to grant'), 'default' => 'all')
|
||||
'aro' => array('help' => __d('cake_console', 'ARO to grant permission to.'), 'required' => true),
|
||||
'aco' => array('help' => __d('cake_console', 'ACO to grant access to.'), 'required' => true),
|
||||
'action' => array('help' => __d('cake_console', 'Action to grant'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('deny', array(
|
||||
'help' => __('Deny an ARO permissions to an ACO.'),
|
||||
'help' => __d('cake_console', 'Deny an ARO permissions to an ACO.'),
|
||||
'parser' => array(
|
||||
'description' => array(
|
||||
__("Use this command to deny ACL permissions. Once executed, the ARO"),
|
||||
__("specified (and its children, if any) will have DENY access to the"),
|
||||
__("specified ACO action (and the ACO's children, if any).")
|
||||
__d('cake_console', "Use this command to deny ACL permissions. Once executed, the ARO"),
|
||||
__d('cake_console', "specified (and its children, if any) will have DENY access to the"),
|
||||
__d('cake_console', "specified ACO action (and the ACO's children, if any).")
|
||||
),
|
||||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to deny.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to deny.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to deny'), 'default' => 'all')
|
||||
'aro' => array('help' => __d('cake_console', 'ARO to deny.'), 'required' => true),
|
||||
'aco' => array('help' => __d('cake_console', 'ACO to deny.'), 'required' => true),
|
||||
'action' => array('help' => __d('cake_console', 'Action to deny'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('inherit', array(
|
||||
'help' => __('Inherit an ARO\'s parent permissions.'),
|
||||
'help' => __d('cake_console', 'Inherit an ARO\'s parent permissions.'),
|
||||
'parser' => array(
|
||||
'description' => array(
|
||||
__("Use this command to force a child ARO object to inherit its"),
|
||||
__("permissions settings from its parent.")
|
||||
__d('cake_console', "Use this command to force a child ARO object to inherit its"),
|
||||
__d('cake_console', "permissions settings from its parent.")
|
||||
),
|
||||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to have permisssions inherit.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to inherit permissions on.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to inherit'), 'default' => 'all')
|
||||
'aro' => array('help' => __d('cake_console', 'ARO to have permisssions inherit.'), 'required' => true),
|
||||
'aco' => array('help' => __d('cake_console', 'ACO to inherit permissions on.'), 'required' => true),
|
||||
'action' => array('help' => __d('cake_console', 'Action to inherit'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('view', array(
|
||||
'help' => __('View a tree or a single node\'s subtree.'),
|
||||
'help' => __d('cake_console', 'View a tree or a single node\'s subtree.'),
|
||||
'parser' => array(
|
||||
'description' => array(
|
||||
__("The view command will return the ARO or ACO tree."),
|
||||
__("The optional node parameter allows you to return"),
|
||||
__("only a portion of the requested tree.")
|
||||
__d('cake_console', "The view command will return the ARO or ACO tree."),
|
||||
__d('cake_console', "The optional node parameter allows you to return"),
|
||||
__d('cake_console', "only a portion of the requested tree.")
|
||||
),
|
||||
'arguments' => array(
|
||||
'type' => $type,
|
||||
'node' => array('help' => __('The optional node to view the subtree of.'))
|
||||
'node' => array('help' => __d('cake_console', 'The optional node to view the subtree of.'))
|
||||
)
|
||||
)
|
||||
))->addSubcommand('initdb', array(
|
||||
'help' => __('Initialize the DbAcl tables. Uses this command : cake schema run create DbAcl')
|
||||
'help' => __d('cake_console', 'Initialize the DbAcl tables. Uses this command : cake schema run create DbAcl')
|
||||
))->epilog(
|
||||
array(
|
||||
'Node and parent arguments can be in one of the following formats:',
|
||||
|
@ -520,7 +520,7 @@ class AclShell extends Shell {
|
|||
$conditions = array($class . '.' . $key => $this->args[1]);
|
||||
$possibility = $this->Acl->{$class}->find('all', compact('conditions'));
|
||||
if (empty($possibility)) {
|
||||
$this->error(__('%s not found', $this->args[1]), __('No tree returned.'));
|
||||
$this->error(__d('cake_console', '%s not found', $this->args[1]), __d('cake_console', 'No tree returned.'));
|
||||
}
|
||||
return $possibility;
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ class AclShell extends Shell {
|
|||
if (is_array($identifier)) {
|
||||
$identifier = var_export($identifier, true);
|
||||
}
|
||||
$this->error(__('Could not find node using reference "%s"', $identifier));
|
||||
$this->error(__d('cake_console', 'Could not find node using reference "%s"', $identifier));
|
||||
}
|
||||
return Set::extract($node, "0.{$class}.id");
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'File');
|
||||
App::uses('File', 'Utility');
|
||||
|
||||
/**
|
||||
* API shell to show method signatures of CakePHP core classes.
|
||||
|
@ -41,13 +41,13 @@ class ApiShell extends Shell {
|
|||
*/
|
||||
public function initialize() {
|
||||
$this->paths = array_merge($this->paths, array(
|
||||
'behavior' => LIBS . 'model' . DS . 'behaviors' . DS,
|
||||
'cache' => LIBS . 'cache' . DS,
|
||||
'controller' => LIBS . 'controller' . DS,
|
||||
'component' => LIBS . 'controller' . DS . 'components' . DS,
|
||||
'helper' => LIBS . 'view' . DS . 'helpers' . DS,
|
||||
'model' => LIBS . 'model' . DS,
|
||||
'view' => LIBS . 'view' . DS,
|
||||
'behavior' => LIBS . 'Model' . DS . 'Behavior' . DS,
|
||||
'cache' => LIBS . 'Cache' . DS,
|
||||
'controller' => LIBS . 'Controller' . DS,
|
||||
'component' => LIBS . 'Controller' . DS . 'Component' . DS,
|
||||
'helper' => LIBS . 'View' . DS . 'Helper' . DS,
|
||||
'model' => LIBS . 'Model' . DS,
|
||||
'view' => LIBS . 'View' . DS,
|
||||
'core' => LIBS
|
||||
));
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class ApiShell extends Shell {
|
|||
$class = Inflector::camelize($type);
|
||||
} elseif (count($this->args) > 1) {
|
||||
$file = Inflector::underscore($this->args[1]);
|
||||
$class = Inflector::camelize($file);
|
||||
$class = Inflector::camelize($this->args[1]);
|
||||
}
|
||||
$objects = App::objects('class', $path);
|
||||
if (in_array($class, $objects)) {
|
||||
|
@ -85,15 +85,15 @@ class ApiShell extends Shell {
|
|||
}
|
||||
|
||||
} else {
|
||||
$this->error(__('%s not found', $class));
|
||||
$this->error(__d('cake_console', '%s not found', $class));
|
||||
}
|
||||
|
||||
$parsed = $this->__parseClass($path . $file .'.php', $class);
|
||||
$parsed = $this->__parseClass($path . $class .'.php', $class);
|
||||
|
||||
if (!empty($parsed)) {
|
||||
if (isset($this->params['method'])) {
|
||||
if (!isset($parsed[$this->params['method']])) {
|
||||
$this->err(__('%s::%s() could not be found', $class, $this->params['method']));
|
||||
$this->err(__d('cake_console', '%s::%s() could not be found', $class, $this->params['method']));
|
||||
$this->_stop();
|
||||
}
|
||||
$method = $parsed[$this->params['method']];
|
||||
|
@ -110,9 +110,9 @@ class ApiShell extends Shell {
|
|||
$this->out($list);
|
||||
|
||||
$methods = array_keys($parsed);
|
||||
while ($number = strtolower($this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.'), null, 'q'))) {
|
||||
while ($number = strtolower($this->in(__d('cake_console', 'Select a number to see the more information about a specific method. q to quit. l to list.'), null, 'q'))) {
|
||||
if ($number === 'q') {
|
||||
$this->out(__('Done'));
|
||||
$this->out(__d('cake_console', 'Done'));
|
||||
return $this->_stop();
|
||||
}
|
||||
|
||||
|
@ -145,8 +145,8 @@ class ApiShell extends Shell {
|
|||
'help' => 'A CakePHP core class name (e.g: Component, HtmlHelper).'
|
||||
))->addOption('method', array(
|
||||
'short' => 'm',
|
||||
'help' => __('The specific method you want help on.')
|
||||
))->description(__('Lookup doc block comments for classes in CakePHP.'));
|
||||
'help' => __d('cake_console', 'The specific method you want help on.')
|
||||
))->description(__d('cake_console', 'Lookup doc block comments for classes in CakePHP.'));
|
||||
return $parser;
|
||||
}
|
||||
/**
|
||||
|
@ -197,9 +197,12 @@ class ApiShell extends Shell {
|
|||
function __parseClass($path, $class) {
|
||||
$parsed = array();
|
||||
|
||||
if (!include_once($path)) {
|
||||
$this->err(__('%s could not be found', $path));
|
||||
if (!class_exists($class)) {
|
||||
if (!include_once($path)) {
|
||||
$this->err(__d('cake_console', '%s could not be found', $path));
|
||||
}
|
||||
}
|
||||
|
||||
$reflection = new ReflectionClass($class);
|
||||
|
||||
foreach ($reflection->getMethods() as $method) {
|
|
@ -21,6 +21,8 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Model', 'Model');
|
||||
|
||||
/**
|
||||
* Bake is a command-line code generation utility for automating programmer chores.
|
||||
*
|
||||
|
@ -73,7 +75,7 @@ class BakeShell extends Shell {
|
|||
}
|
||||
|
||||
if (!config('database')) {
|
||||
$this->out(__('Your database configuration was not found. Take a moment to create one.'));
|
||||
$this->out(__d('cake_console', 'Your database configuration was not found. Take a moment to create one.'));
|
||||
$this->args = null;
|
||||
return $this->DbConfig->execute();
|
||||
}
|
||||
|
@ -88,7 +90,7 @@ class BakeShell extends Shell {
|
|||
$this->out('[T]est case');
|
||||
$this->out('[Q]uit');
|
||||
|
||||
$classToBake = strtoupper($this->in(__('What would you like to Bake?'), array('D', 'M', 'V', 'C', 'P', 'F', 'T', 'Q')));
|
||||
$classToBake = strtoupper($this->in(__d('cake_console', 'What would you like to Bake?'), array('D', 'M', 'V', 'C', 'P', 'F', 'T', 'Q')));
|
||||
switch ($classToBake) {
|
||||
case 'D':
|
||||
$this->DbConfig->execute();
|
||||
|
@ -115,7 +117,7 @@ class BakeShell extends Shell {
|
|||
exit(0);
|
||||
break;
|
||||
default:
|
||||
$this->out(__('You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, F, T, or C.'));
|
||||
$this->out(__d('cake_console', 'You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, F, T, or C.'));
|
||||
}
|
||||
$this->hr();
|
||||
$this->main();
|
||||
|
@ -149,11 +151,13 @@ class BakeShell extends Shell {
|
|||
|
||||
$modelExists = false;
|
||||
$model = $this->_modelName($name);
|
||||
if (App::import('Model', $model)) {
|
||||
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses($model, 'Model');
|
||||
if (class_exists($model)) {
|
||||
$object = new $model();
|
||||
$modelExists = true;
|
||||
} else {
|
||||
App::import('Model', 'Model', false);
|
||||
$object = new Model(array('name' => $name, 'ds' => $this->connection));
|
||||
}
|
||||
|
||||
|
@ -174,15 +178,16 @@ class BakeShell extends Shell {
|
|||
$this->Controller->bakeTest($controller);
|
||||
}
|
||||
}
|
||||
if (App::import('Controller', $controller)) {
|
||||
App::uses($controller . 'Controller', 'Controller');
|
||||
if (class_exists($controller . 'Controller')) {
|
||||
$this->View->args = array($controller);
|
||||
$this->View->execute();
|
||||
}
|
||||
$this->out('', 1, Shell::QUIET);
|
||||
$this->out(__('<success>Bake All complete</success>'), 1, Shell::QUIET);
|
||||
$this->out(__d('cake_console', '<success>Bake All complete</success>'), 1, Shell::QUIET);
|
||||
array_shift($this->args);
|
||||
} else {
|
||||
$this->error(__('Bake All could not continue without a valid model'));
|
||||
$this->error(__d('cake_console', 'Bake All could not continue without a valid model'));
|
||||
}
|
||||
return $this->_stop();
|
||||
}
|
||||
|
@ -200,33 +205,33 @@ class BakeShell extends Shell {
|
|||
'creation process. You can customize the generation process by telling Bake' .
|
||||
'where different parts of your application are using command line arguments.'
|
||||
)->addSubcommand('all', array(
|
||||
'help' => __('Bake a complete MVC. optional <name> of a Model'),
|
||||
'help' => __d('cake_console', 'Bake a complete MVC. optional <name> of a Model'),
|
||||
))->addSubcommand('project', array(
|
||||
'help' => __('Bake a new app folder in the path supplied or in current directory if no path is specified'),
|
||||
'help' => __d('cake_console', 'Bake a new app folder in the path supplied or in current directory if no path is specified'),
|
||||
'parser' => $this->Project->getOptionParser()
|
||||
))->addSubcommand('plugin', array(
|
||||
'help' => __('Bake a new plugin folder in the path supplied or in current directory if no path is specified.'),
|
||||
'help' => __d('cake_console', 'Bake a new plugin folder in the path supplied or in current directory if no path is specified.'),
|
||||
'parser' => $this->Plugin->getOptionParser()
|
||||
))->addSubcommand('db_config', array(
|
||||
'help' => __('Bake a database.php file in config directory.'),
|
||||
'help' => __d('cake_console', 'Bake a database.php file in config directory.'),
|
||||
'parser' => $this->DbConfig->getOptionParser()
|
||||
))->addSubcommand('model', array(
|
||||
'help' => __('Bake a model.'),
|
||||
'help' => __d('cake_console', 'Bake a model.'),
|
||||
'parser' => $this->Model->getOptionParser()
|
||||
))->addSubcommand('view', array(
|
||||
'help' => __('Bake views for controllers.'),
|
||||
'help' => __d('cake_console', 'Bake views for controllers.'),
|
||||
'parser' => $this->View->getOptionParser()
|
||||
))->addSubcommand('controller', array(
|
||||
'help' => __('Bake a controller.'),
|
||||
'help' => __d('cake_console', 'Bake a controller.'),
|
||||
'parser' => $this->Controller->getOptionParser()
|
||||
))->addSubcommand('fixture', array(
|
||||
'help' => __('Bake a fixture.'),
|
||||
'help' => __d('cake_console', 'Bake a fixture.'),
|
||||
'parser' => $this->Fixture->getOptionParser()
|
||||
))->addSubcommand('test', array(
|
||||
'help' => __('Bake a unit test.'),
|
||||
'help' => __d('cake_console', 'Bake a unit test.'),
|
||||
'parser' => $this->Test->getOptionParser()
|
||||
))->addOption('connection', array(
|
||||
'help' => __('Database connection to use in conjunction with `bake all`.'),
|
||||
'help' => __d('cake_console', 'Database connection to use in conjunction with `bake all`.'),
|
||||
'short' => 'c',
|
||||
'default' => 'default'
|
||||
));
|
|
@ -16,6 +16,8 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Inflector', 'Utility');
|
||||
|
||||
/**
|
||||
* Shows a list of commands available from the console.
|
||||
*
|
||||
|
@ -79,17 +81,18 @@ class CommandListShell extends Shell {
|
|||
protected function _getShellList() {
|
||||
$shellList = array();
|
||||
|
||||
$corePaths = App::core('shells');
|
||||
$shellList = $this->_appendShells('CORE', $corePaths, $shellList);
|
||||
$shells = App::objects('file', App::core('Console/Command'));
|
||||
$shellList = $this->_appendShells('CORE', $shells, $shellList);
|
||||
|
||||
$appPaths = array_diff(App::path('shells'), $corePaths);
|
||||
$shellList = $this->_appendShells('app', $appPaths, $shellList);
|
||||
$appShells = App::objects('Console/Command', null, false);
|
||||
$shellList = $this->_appendShells('app', $appShells, $shellList);
|
||||
|
||||
$plugins = App::objects('plugin');
|
||||
foreach ($plugins as $plugin) {
|
||||
$pluginPath = App::pluginPath($plugin) . 'console' . DS . 'shells' . DS;
|
||||
$shellList = $this->_appendShells($plugin, array($pluginPath), $shellList);
|
||||
$pluginShells = App::objects($plugin . '.Console/Command');
|
||||
$shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
|
||||
}
|
||||
|
||||
return $shellList;
|
||||
}
|
||||
|
||||
|
@ -98,22 +101,10 @@ class CommandListShell extends Shell {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _appendShells($type, $paths, $shellList) {
|
||||
foreach ($paths as $path) {
|
||||
if (!is_dir($path)) {
|
||||
continue;
|
||||
}
|
||||
$shells = App::objects('file', $path);
|
||||
|
||||
if (empty($shells)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($shells as $shell) {
|
||||
if ($shell !== 'shell.php' && $shell !== 'app_shell.php') {
|
||||
$shell = str_replace('.php', '', $shell);
|
||||
$shellList[$shell][$type] = $type;
|
||||
}
|
||||
}
|
||||
protected function _appendShells($type, $shells, $shellList) {
|
||||
foreach ($shells as $shell) {
|
||||
$shell = Inflector::underscore(str_replace('Shell', '', $shell));
|
||||
$shellList[$shell][$type] = $type;
|
||||
}
|
||||
return $shellList;
|
||||
}
|
||||
|
@ -223,10 +214,10 @@ class CommandListShell extends Shell {
|
|||
$parser = parent::getOptionParser();
|
||||
return $parser->description('Get the list of available shells for this CakePHP application.')
|
||||
->addOption('xml', array(
|
||||
'help' => __('Get the listing as XML.'),
|
||||
'help' => __d('cake_console', 'Get the listing as XML.'),
|
||||
'boolean' => true
|
||||
))->addOption('sort', array(
|
||||
'help' => __('Sorts the commands by where they are located.'),
|
||||
'help' => __d('cake_console', 'Sorts the commands by where they are located.'),
|
||||
'boolean' => true
|
||||
));
|
||||
}
|
|
@ -51,14 +51,14 @@ class ConsoleShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function initialize() {
|
||||
require_once CAKE . 'dispatcher.php';
|
||||
App::uses('Dispatcher', 'Routing');
|
||||
$this->Dispatcher = new Dispatcher();
|
||||
$this->models = App::objects('model');
|
||||
App::import('Model', $this->models);
|
||||
|
||||
foreach ($this->models as $model) {
|
||||
$class = Inflector::camelize(str_replace('.php', '', $model));
|
||||
$this->models[$model] = $class;
|
||||
App::uses($class, 'Model');
|
||||
$this->{$class} = new $class();
|
||||
}
|
||||
$this->out('Model classes:');
|
||||
|
@ -333,21 +333,20 @@ class ConsoleShell extends Shell {
|
|||
* @return boolean True if config reload was a success, otherwise false
|
||||
*/
|
||||
protected function _loadRoutes() {
|
||||
$router = Router::getInstance();
|
||||
|
||||
$router->reload();
|
||||
extract($router->getNamedExpressions());
|
||||
Router::reload();
|
||||
extract(Router::getNamedExpressions());
|
||||
|
||||
if (!@include(CONFIGS . 'routes.php')) {
|
||||
return false;
|
||||
}
|
||||
$router->parse('/');
|
||||
Router::parse('/');
|
||||
|
||||
foreach (array_keys($router->getNamedExpressions()) as $var) {
|
||||
foreach (array_keys(Router::getNamedExpressions()) as $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;
|
||||
}
|
|
@ -52,7 +52,7 @@ class I18nShell extends Shell {
|
|||
|
||||
if ($this->command && !in_array($this->command, array('help'))) {
|
||||
if (!config('database')) {
|
||||
$this->out(__('Your database configuration was not found. Take a moment to create one.'), true);
|
||||
$this->out(__d('cake_console', 'Your database configuration was not found. Take a moment to create one.'), true);
|
||||
return $this->DbConfig->execute();
|
||||
}
|
||||
}
|
||||
|
@ -63,14 +63,14 @@ class I18nShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function main() {
|
||||
$this->out(__('<info>I18n Shell</info>'));
|
||||
$this->out(__d('cake_console', '<info>I18n Shell</info>'));
|
||||
$this->hr();
|
||||
$this->out(__('[E]xtract POT file from sources'));
|
||||
$this->out(__('[I]nitialize i18n database table'));
|
||||
$this->out(__('[H]elp'));
|
||||
$this->out(__('[Q]uit'));
|
||||
$this->out(__d('cake_console', '[E]xtract POT file from sources'));
|
||||
$this->out(__d('cake_console', '[I]nitialize i18n database table'));
|
||||
$this->out(__d('cake_console', '[H]elp'));
|
||||
$this->out(__d('cake_console', '[Q]uit'));
|
||||
|
||||
$choice = strtolower($this->in(__('What would you like to do?'), array('E', 'I', 'H', 'Q')));
|
||||
$choice = strtolower($this->in(__d('cake_console', 'What would you like to do?'), array('E', 'I', 'H', 'Q')));
|
||||
switch ($choice) {
|
||||
case 'e':
|
||||
$this->Extract->execute();
|
||||
|
@ -85,7 +85,7 @@ class I18nShell extends Shell {
|
|||
exit(0);
|
||||
break;
|
||||
default:
|
||||
$this->out(__('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.'));
|
||||
$this->out(__d('cake_console', 'You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.'));
|
||||
}
|
||||
$this->hr();
|
||||
$this->main();
|
||||
|
@ -107,11 +107,11 @@ class I18nShell extends Shell {
|
|||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(
|
||||
__('I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.')
|
||||
__d('cake_console', 'I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.')
|
||||
)->addSubcommand('initdb', array(
|
||||
'help' => __('Initialize the i18n table.')
|
||||
'help' => __d('cake_console', 'Initialize the i18n table.')
|
||||
))->addSubcommand('extract', array(
|
||||
'help' => __('Extract the po translations from your application'),
|
||||
'help' => __d('cake_console', 'Extract the po translations from your application'),
|
||||
'parser' => $this->Extract->getOptionParser()
|
||||
));
|
||||
}
|
|
@ -19,8 +19,8 @@
|
|||
* @since CakePHP(tm) v 1.2.0.5550
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'File', false);
|
||||
App::import('Model', 'CakeSchema', false);
|
||||
App::uses('File', 'Utility');
|
||||
App::uses('CakeSchema', 'Model');
|
||||
|
||||
/**
|
||||
* Schema is a command-line database management utility for automating programmer chores.
|
||||
|
@ -112,7 +112,7 @@ class SchemaShell extends Shell {
|
|||
$this->_stop();
|
||||
} else {
|
||||
$file = $this->Schema->path . DS . $this->params['file'];
|
||||
$this->err(__('Schema file (%s) could not be found.', $file));
|
||||
$this->err(__d('cake_console', 'Schema file (%s) could not be found.', $file));
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ class SchemaShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function generate() {
|
||||
$this->out(__('Generating Schema...'));
|
||||
$this->out(__d('cake_console', 'Generating Schema...'));
|
||||
$options = array();
|
||||
if (isset($this->params['force'])) {
|
||||
$options = array('models' => false);
|
||||
|
@ -145,9 +145,14 @@ class SchemaShell extends Shell {
|
|||
}
|
||||
}
|
||||
|
||||
$cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', true);
|
||||
|
||||
$content = $this->Schema->read($options);
|
||||
$content['file'] = $this->params['file'];
|
||||
|
||||
Configure::write('Cache.disable', $cacheDisable);
|
||||
|
||||
if ($snapshot === true) {
|
||||
$Folder = new Folder($this->Schema->path);
|
||||
$result = $Folder->read();
|
||||
|
@ -177,10 +182,10 @@ class SchemaShell extends Shell {
|
|||
}
|
||||
|
||||
if ($this->Schema->write($content)) {
|
||||
$this->out(__('Schema file: %s generated', $content['file']));
|
||||
$this->out(__d('cake_console', 'Schema file: %s generated', $content['file']));
|
||||
$this->_stop();
|
||||
} else {
|
||||
$this->err(__('Schema file: %s generated'));
|
||||
$this->err(__d('cake_console', 'Schema file: %s generated'));
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +202,7 @@ class SchemaShell extends Shell {
|
|||
$write = false;
|
||||
$Schema = $this->Schema->load();
|
||||
if (!$Schema) {
|
||||
$this->err(__('Schema could not be loaded'));
|
||||
$this->err(__d('cake_console', 'Schema could not be loaded'));
|
||||
$this->_stop();
|
||||
}
|
||||
if (!empty($this->params['write'])) {
|
||||
|
@ -222,10 +227,10 @@ class SchemaShell extends Shell {
|
|||
}
|
||||
|
||||
if ($File->write($contents)) {
|
||||
$this->out(__('SQL dump file created in %s', $File->pwd()));
|
||||
$this->out(__d('cake_console', 'SQL dump file created in %s', $File->pwd()));
|
||||
$this->_stop();
|
||||
} else {
|
||||
$this->err(__('SQL dump could not be created'));
|
||||
$this->err(__d('cake_console', 'SQL dump could not be created'));
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +274,7 @@ class SchemaShell extends Shell {
|
|||
|
||||
if (!empty($this->params['dry'])) {
|
||||
$this->__dry = true;
|
||||
$this->out(__('Performing a dry run.'));
|
||||
$this->out(__d('cake_console', 'Performing a dry run.'));
|
||||
}
|
||||
|
||||
$options = array('name' => $name, 'plugin' => $plugin);
|
||||
|
@ -281,7 +286,7 @@ class SchemaShell extends Shell {
|
|||
$Schema = $this->Schema->load($options);
|
||||
|
||||
if (!$Schema) {
|
||||
$this->err(__('%s could not be loaded', $this->Schema->path . DS . $this->Schema->file));
|
||||
$this->err(__d('cake_console', '%s could not be loaded', $this->Schema->path . DS . $this->Schema->file));
|
||||
$this->_stop();
|
||||
}
|
||||
$table = null;
|
||||
|
@ -312,26 +317,26 @@ class SchemaShell extends Shell {
|
|||
$create[$table] = $db->createSchema($Schema, $table);
|
||||
}
|
||||
if (empty($drop) || empty($create)) {
|
||||
$this->out(__('Schema is up to date.'));
|
||||
$this->out(__d('cake_console', 'Schema is up to date.'));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$this->out("\n" . __('The following table(s) will be dropped.'));
|
||||
$this->out("\n" . __d('cake_console', 'The following table(s) will be dropped.'));
|
||||
$this->out(array_keys($drop));
|
||||
|
||||
if ('y' == $this->in(__('Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n')) {
|
||||
$this->out(__('Dropping table(s).'));
|
||||
if ('y' == $this->in(__d('cake_console', 'Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n')) {
|
||||
$this->out(__d('cake_console', 'Dropping table(s).'));
|
||||
$this->__run($drop, 'drop', $Schema);
|
||||
}
|
||||
|
||||
$this->out("\n" . __('The following table(s) will be created.'));
|
||||
$this->out("\n" . __d('cake_console', 'The following table(s) will be created.'));
|
||||
$this->out(array_keys($create));
|
||||
|
||||
if ('y' == $this->in(__('Are you sure you want to create the table(s)?'), array('y', 'n'), 'y')) {
|
||||
$this->out(__('Creating table(s).'));
|
||||
if ('y' == $this->in(__d('cake_console', 'Are you sure you want to create the table(s)?'), array('y', 'n'), 'y')) {
|
||||
$this->out(__d('cake_console', 'Creating table(s).'));
|
||||
$this->__run($create, 'create', $Schema);
|
||||
}
|
||||
$this->out(__('End create.'));
|
||||
$this->out(__d('cake_console', 'End create.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -343,7 +348,7 @@ class SchemaShell extends Shell {
|
|||
function __update(&$Schema, $table = null) {
|
||||
$db = ConnectionManager::getDataSource($this->Schema->connection);
|
||||
|
||||
$this->out(__('Comparing Database to Schema...'));
|
||||
$this->out(__d('cake_console', 'Comparing Database to Schema...'));
|
||||
$options = array();
|
||||
if (isset($this->params['force'])) {
|
||||
$options['models'] = false;
|
||||
|
@ -362,19 +367,19 @@ class SchemaShell extends Shell {
|
|||
}
|
||||
|
||||
if (empty($contents)) {
|
||||
$this->out(__('Schema is up to date.'));
|
||||
$this->out(__d('cake_console', 'Schema is up to date.'));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$this->out("\n" . __('The following statements will run.'));
|
||||
$this->out("\n" . __d('cake_console', 'The following statements will run.'));
|
||||
$this->out(array_map('trim', $contents));
|
||||
if ('y' == $this->in(__('Are you sure you want to alter the tables?'), array('y', 'n'), 'n')) {
|
||||
if ('y' == $this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n')) {
|
||||
$this->out();
|
||||
$this->out(__('Updating Database...'));
|
||||
$this->out(__d('cake_console', 'Updating Database...'));
|
||||
$this->__run($contents, 'update', $Schema);
|
||||
}
|
||||
|
||||
$this->out(__('End update.'));
|
||||
$this->out(__d('cake_console', 'End update.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -384,7 +389,7 @@ class SchemaShell extends Shell {
|
|||
*/
|
||||
function __run($contents, $event, &$Schema) {
|
||||
if (empty($contents)) {
|
||||
$this->err(__('Sql could not be run'));
|
||||
$this->err(__d('cake_console', 'Sql could not be run'));
|
||||
return;
|
||||
}
|
||||
Configure::write('debug', 2);
|
||||
|
@ -392,10 +397,10 @@ class SchemaShell extends Shell {
|
|||
|
||||
foreach ($contents as $table => $sql) {
|
||||
if (empty($sql)) {
|
||||
$this->out(__('%s is up to date.', $table));
|
||||
$this->out(__d('cake_console', '%s is up to date.', $table));
|
||||
} else {
|
||||
if ($this->__dry === true) {
|
||||
$this->out(__('Dry run for %s :', $table));
|
||||
$this->out(__d('cake_console', 'Dry run for %s :', $table));
|
||||
$this->out($sql);
|
||||
} else {
|
||||
if (!$Schema->before(array($event => $table))) {
|
||||
|
@ -411,7 +416,7 @@ class SchemaShell extends Shell {
|
|||
if (!empty($error)) {
|
||||
$this->out($error);
|
||||
} else {
|
||||
$this->out(__('%s updated.', $table));
|
||||
$this->out(__d('cake_console', '%s updated.', $table));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -425,26 +430,26 @@ class SchemaShell extends Shell {
|
|||
*/
|
||||
public function getOptionParser() {
|
||||
$plugin = array(
|
||||
'help' => __('The plugin to use.'),
|
||||
'help' => __d('cake_console', 'The plugin to use.'),
|
||||
);
|
||||
$connection = array(
|
||||
'help' => __('Set the db config to use.'),
|
||||
'help' => __d('cake_console', 'Set the db config to use.'),
|
||||
'default' => 'default'
|
||||
);
|
||||
$path = array(
|
||||
'help' => __('Path to read and write schema.php'),
|
||||
'help' => __d('cake_console', 'Path to read and write schema.php'),
|
||||
'default' => CONFIGS . 'schema'
|
||||
);
|
||||
$file = array(
|
||||
'help' => __('File name to read and write.'),
|
||||
'help' => __d('cake_console', 'File name to read and write.'),
|
||||
'default' => 'schema.php'
|
||||
);
|
||||
$name = array(
|
||||
'help' => __('Classname to use. If its Plugin.class, both name and plugin options will be set.')
|
||||
'help' => __d('cake_console', 'Classname to use. If its Plugin.class, both name and plugin options will be set.')
|
||||
);
|
||||
$snapshot = array(
|
||||
'short' => 's',
|
||||
'help' => __('Snapshot number to use/make.')
|
||||
'help' => __d('cake_console', 'Snapshot number to use/make.')
|
||||
);
|
||||
$dry = array(
|
||||
'help' => 'Perform a dry run on create and update commands. Queries will be output instead of run.',
|
||||
|
@ -452,11 +457,11 @@ class SchemaShell extends Shell {
|
|||
);
|
||||
$force = array(
|
||||
'short' => 'f',
|
||||
'help' => __('Force "generate" to create a new schema'),
|
||||
'help' => __d('cake_console', 'Force "generate" to create a new schema'),
|
||||
'boolean' => true
|
||||
);
|
||||
$write = array(
|
||||
'help' => __('Write the dumped SQL to a file.')
|
||||
'help' => __d('cake_console', 'Write the dumped SQL to a file.')
|
||||
);
|
||||
|
||||
$parser = parent::getOptionParser();
|
||||
|
@ -470,42 +475,42 @@ class SchemaShell extends Shell {
|
|||
'arguments' => compact('name')
|
||||
)
|
||||
))->addSubcommand('generate', array(
|
||||
'help' => __('Reads from --connection and writes to --path. Generate snapshots with -s'),
|
||||
'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'),
|
||||
'parser' => array(
|
||||
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force'),
|
||||
'arguments' => array(
|
||||
'snapshot' => array('help' => __('Generate a snapshot.'))
|
||||
'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.'))
|
||||
)
|
||||
)
|
||||
))->addSubcommand('dump', array(
|
||||
'help' => __('Dump database SQL based on a schema file to stdout.'),
|
||||
'help' => __d('cake_console', 'Dump database SQL based on a schema file to stdout.'),
|
||||
'parser' => array(
|
||||
'options' => compact('plugin', 'path', 'file', 'name', 'connection'),
|
||||
'arguments' => compact('name')
|
||||
)
|
||||
))->addSubcommand('create', array(
|
||||
'help' => __('Drop and create tables based on the schema file.'),
|
||||
'help' => __d('cake_console', 'Drop and create tables based on the schema file.'),
|
||||
'parser' => array(
|
||||
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'dry', 'snapshot'),
|
||||
'args' => array(
|
||||
'name' => array(
|
||||
'help' => __('Name of schema to use.')
|
||||
'help' => __d('cake_console', 'Name of schema to use.')
|
||||
),
|
||||
'table' => array(
|
||||
'help' => __('Only create the specified table.')
|
||||
'help' => __d('cake_console', 'Only create the specified table.')
|
||||
)
|
||||
)
|
||||
)
|
||||
))->addSubcommand('update', array(
|
||||
'help' => __('Alter the tables based on the schema file.'),
|
||||
'help' => __d('cake_console', 'Alter the tables based on the schema file.'),
|
||||
'parser' => array(
|
||||
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'dry', 'snapshot'),
|
||||
'args' => array(
|
||||
'name' => array(
|
||||
'help' => __('Name of schema to use.')
|
||||
'help' => __d('cake_console', 'Name of schema to use.')
|
||||
),
|
||||
'table' => array(
|
||||
'help' => __('Only create the specified table.')
|
||||
'help' => __d('cake_console', 'Only create the specified table.')
|
||||
)
|
||||
)
|
||||
)
|
|
@ -50,7 +50,7 @@ class BakeTask extends Shell {
|
|||
public function getPath() {
|
||||
$path = $this->path;
|
||||
if (isset($this->plugin)) {
|
||||
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($this->name)) . DS;
|
||||
$path = $this->_pluginPath($this->plugin) . $this->name . DS;
|
||||
}
|
||||
return $path;
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* @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.
|
||||
|
@ -71,13 +71,13 @@ class ControllerTask extends BakeTask {
|
|||
$actions = '';
|
||||
|
||||
if (!empty($this->params['public'])) {
|
||||
$this->out(__('Baking basic crud methods for ') . $controller);
|
||||
$this->out(__d('cake_console', 'Baking basic crud methods for ') . $controller);
|
||||
$actions .= $this->bakeActions($controller);
|
||||
}
|
||||
if (!empty($this->params['admin'])) {
|
||||
$admin = $this->Project->getPrefix();
|
||||
if ($admin) {
|
||||
$this->out(__('Adding %s methods', $admin));
|
||||
$this->out(__d('cake_console', 'Adding %s methods', $admin));
|
||||
$actions .= "\n" . $this->bakeActions($controller, $admin);
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,8 @@ class ControllerTask extends BakeTask {
|
|||
foreach ($this->__tables as $table) {
|
||||
$model = $this->_modelName($table);
|
||||
$controller = $this->_controllerName($model);
|
||||
if (App::import('Model', $model)) {
|
||||
App::uses($model, 'Model');
|
||||
if (class_exists($model)) {
|
||||
$actions = $this->bakeActions($controller);
|
||||
if ($this->bake($controller, $actions) && $unitTestExists) {
|
||||
$this->bakeTest($controller);
|
||||
|
@ -123,7 +124,7 @@ class ControllerTask extends BakeTask {
|
|||
protected function _interactive() {
|
||||
$this->interactive = true;
|
||||
$this->hr();
|
||||
$this->out(__("Bake Controller\nPath: %s", $this->path));
|
||||
$this->out(__d('cake_console', "Bake Controller\nPath: %s", $this->path));
|
||||
$this->hr();
|
||||
|
||||
if (empty($this->connection)) {
|
||||
|
@ -132,7 +133,7 @@ class ControllerTask extends BakeTask {
|
|||
|
||||
$controllerName = $this->getName();
|
||||
$this->hr();
|
||||
$this->out(__('Baking %sController', $controllerName));
|
||||
$this->out(__d('cake_console', 'Baking %sController', $controllerName));
|
||||
$this->hr();
|
||||
|
||||
$helpers = $components = array();
|
||||
|
@ -142,18 +143,17 @@ class ControllerTask extends BakeTask {
|
|||
$useDynamicScaffold = 'n';
|
||||
$wannaBakeCrud = 'y';
|
||||
|
||||
$controllerFile = strtolower(Inflector::underscore($controllerName));
|
||||
|
||||
$question[] = __("Would you like to build your controller interactively?");
|
||||
if (file_exists($this->path . $controllerFile .'_controller.php')) {
|
||||
$question[] = __("Warning: Choosing no will overwrite the %sController.", $controllerName);
|
||||
$question[] = __d('cake_console', "Would you like to build your controller interactively?");
|
||||
if (file_exists($this->path . $controllerName .'Controller.php')) {
|
||||
$question[] = __d('cake_console', "Warning: Choosing no will overwrite the %sController.", $controllerName);
|
||||
}
|
||||
$doItInteractive = $this->in(implode("\n", $question), array('y','n'), 'y');
|
||||
|
||||
if (strtolower($doItInteractive) == 'y') {
|
||||
$this->interactive = true;
|
||||
$useDynamicScaffold = $this->in(
|
||||
__("Would you like to use dynamic scaffolding?"), array('y','n'), 'n'
|
||||
__d('cake_console', "Would you like to use dynamic scaffolding?"), array('y','n'), 'n'
|
||||
);
|
||||
|
||||
if (strtolower($useDynamicScaffold) == 'y') {
|
||||
|
@ -166,7 +166,7 @@ class ControllerTask extends BakeTask {
|
|||
$components = $this->doComponents();
|
||||
|
||||
$wannaUseSession = $this->in(
|
||||
__("Would you like to use Session flash messages?"), array('y','n'), 'y'
|
||||
__d('cake_console', "Would you like to use Session flash messages?"), array('y','n'), 'y'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -184,7 +184,7 @@ class ControllerTask extends BakeTask {
|
|||
$baked = false;
|
||||
if ($this->interactive === true) {
|
||||
$this->confirmController($controllerName, $useDynamicScaffold, $helpers, $components);
|
||||
$looksGood = $this->in(__('Look okay?'), array('y','n'), 'y');
|
||||
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y','n'), 'y');
|
||||
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
$baked = $this->bake($controllerName, $actions, $helpers, $components);
|
||||
|
@ -209,17 +209,17 @@ class ControllerTask extends BakeTask {
|
|||
public function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
|
||||
$this->out();
|
||||
$this->hr();
|
||||
$this->out(__('The following controller will be created:'));
|
||||
$this->out(__d('cake_console', 'The following controller will be created:'));
|
||||
$this->hr();
|
||||
$this->out(__("Controller Name:\n\t%s", $controllerName));
|
||||
$this->out(__d('cake_console', "Controller Name:\n\t%s", $controllerName));
|
||||
|
||||
if (strtolower($useDynamicScaffold) == 'y') {
|
||||
$this->out("var \$scaffold;");
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'helpers' => __('Helpers:'),
|
||||
'components' => __('Components:'),
|
||||
'helpers' => __d('cake_console', 'Helpers:'),
|
||||
'components' => __d('cake_console', 'Components:'),
|
||||
);
|
||||
|
||||
foreach ($properties as $var => $title) {
|
||||
|
@ -246,11 +246,11 @@ class ControllerTask extends BakeTask {
|
|||
*/
|
||||
protected function _askAboutMethods() {
|
||||
$wannaBakeCrud = $this->in(
|
||||
__("Would you like to create some basic class methods \n(index(), add(), view(), edit())?"),
|
||||
__d('cake_console', "Would you like to create some basic class methods \n(index(), add(), view(), edit())?"),
|
||||
array('y','n'), 'n'
|
||||
);
|
||||
$wannaBakeAdminCrud = $this->in(
|
||||
__("Would you like to create the basic class methods for admin routing?"),
|
||||
__d('cake_console', "Would you like to create the basic class methods for admin routing?"),
|
||||
array('y','n'), 'n'
|
||||
);
|
||||
return array($wannaBakeCrud, $wannaBakeAdminCrud);
|
||||
|
@ -269,10 +269,11 @@ class ControllerTask extends BakeTask {
|
|||
$currentModelName = $modelImport = $this->_modelName($controllerName);
|
||||
$plugin = $this->plugin;
|
||||
if ($plugin) {
|
||||
$modelImport = $plugin . '.' . $modelImport;
|
||||
$plugin .= '.';
|
||||
}
|
||||
if (!App::import('Model', $modelImport)) {
|
||||
$this->err(__('You must have a model for this class to build basic methods. Please try again.'));
|
||||
App::uses($modelImport, $plugin . 'Model');
|
||||
if (!class_exists($modelImport)) {
|
||||
$this->err(__d('cake_console', 'You must have a model for this class to build basic methods. Please try again.'));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
|
@ -282,9 +283,13 @@ class ControllerTask extends BakeTask {
|
|||
$singularName = Inflector::variable($currentModelName);
|
||||
$singularHumanName = $this->_singularHumanName($controllerName);
|
||||
$pluralHumanName = $this->_pluralName($controllerName);
|
||||
$displayField = $modelObj->displayField;
|
||||
$primaryKey = $modelObj->primaryKey;
|
||||
|
||||
$this->Template->set(compact('plugin', 'admin', 'controllerPath', 'pluralName', 'singularName', 'singularHumanName',
|
||||
'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName'));
|
||||
$this->Template->set(compact('plugin', 'admin', 'controllerPath', 'pluralName', 'singularName',
|
||||
'singularHumanName', 'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName',
|
||||
'displayField', 'primaryKey'
|
||||
));
|
||||
$actions = $this->Template->generate('actions', 'controller_actions');
|
||||
return $actions;
|
||||
}
|
||||
|
@ -309,7 +314,7 @@ class ControllerTask extends BakeTask {
|
|||
$contents = $this->Template->generate('classes', 'controller');
|
||||
|
||||
$path = $this->getPath();
|
||||
$filename = $path . $this->_controllerPath($controllerName) . '_controller.php';
|
||||
$filename = $path . $this->_controllerName($controllerName) . 'Controller.php';
|
||||
if ($this->createFile($filename, $contents)) {
|
||||
return $contents;
|
||||
}
|
||||
|
@ -336,8 +341,8 @@ class ControllerTask extends BakeTask {
|
|||
*/
|
||||
public function doHelpers() {
|
||||
return $this->_doPropertyChoices(
|
||||
__("Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?"),
|
||||
__("Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'")
|
||||
__d('cake_console', "Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?"),
|
||||
__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -348,8 +353,8 @@ class ControllerTask extends BakeTask {
|
|||
*/
|
||||
public function doComponents() {
|
||||
return $this->_doPropertyChoices(
|
||||
__("Would you like this controller to use any components?"),
|
||||
__("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'")
|
||||
__d('cake_console', "Would you like this controller to use any components?"),
|
||||
__d('cake_console', "Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -385,7 +390,7 @@ class ControllerTask extends BakeTask {
|
|||
$this->__tables = $this->Model->getAllTables($useDbConfig);
|
||||
|
||||
if ($this->interactive == true) {
|
||||
$this->out(__('Possible Controllers based on your current database:'));
|
||||
$this->out(__d('cake_console', 'Possible Controllers based on your current database:'));
|
||||
$this->_controllerNames = array();
|
||||
$count = count($this->__tables);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
|
@ -408,14 +413,14 @@ class ControllerTask extends BakeTask {
|
|||
$enteredController = '';
|
||||
|
||||
while ($enteredController == '') {
|
||||
$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');
|
||||
$enteredController = $this->in(__d('cake_console', "Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');
|
||||
if ($enteredController === 'q') {
|
||||
$this->out(__('Exit'));
|
||||
$this->out(__d('cake_console', 'Exit'));
|
||||
return $this->_stop();
|
||||
}
|
||||
|
||||
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
|
||||
$this->err(__("The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again."));
|
||||
$this->err(__d('cake_console', "The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again."));
|
||||
$enteredController = '';
|
||||
}
|
||||
}
|
||||
|
@ -436,24 +441,24 @@ class ControllerTask extends BakeTask {
|
|||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(
|
||||
__('Bake a controller for a model. Using options you can bake public, admin or both.')
|
||||
__d('cake_console', 'Bake a controller for a model. Using options you can bake public, admin or both.')
|
||||
)->addArgument('name', array(
|
||||
'help' => __('Name of the controller to bake. Can use Plugin.name to bake controllers into plugins.')
|
||||
'help' => __d('cake_console', 'Name of the controller to bake. Can use Plugin.name to bake controllers into plugins.')
|
||||
))->addOption('public', array(
|
||||
'help' => __('Bake a controller with basic crud actions (index, view, add, edit, delete).'),
|
||||
'help' => __d('cake_console', 'Bake a controller with basic crud actions (index, view, add, edit, delete).'),
|
||||
'boolean' => true
|
||||
))->addOption('admin', array(
|
||||
'help' => __('Bake a controller with crud actions for one of the Routing.prefixes.'),
|
||||
'help' => __d('cake_console', 'Bake a controller with crud actions for one of the Routing.prefixes.'),
|
||||
'boolean' => true
|
||||
))->addOption('plugin', array(
|
||||
'short' => 'p',
|
||||
'help' => __('Plugin to bake the controller into.')
|
||||
'help' => __d('cake_console', 'Plugin to bake the controller into.')
|
||||
))->addOption('connection', array(
|
||||
'short' => 'c',
|
||||
'help' => __('The connection the controller\'s model is on.')
|
||||
'help' => __d('cake_console', 'The connection the controller\'s model is on.')
|
||||
))->addSubcommand('all', array(
|
||||
'help' => __('Bake all controllers with CRUD methods.')
|
||||
))->epilog(__('Omitting all arguments and options will enter into an interactive mode.'));
|
||||
'help' => __d('cake_console', 'Bake all controllers with CRUD methods.')
|
||||
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
|
||||
}
|
||||
|
||||
/**
|
|
@ -104,7 +104,7 @@ class DbConfigTask extends Shell {
|
|||
}
|
||||
}
|
||||
|
||||
$driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql');
|
||||
$driver = $this->in('Driver:', array('mssql', 'mysql', 'oracle', 'postgres', 'sqlite'), 'mysql');
|
||||
|
||||
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
|
||||
if (strtolower($persistent) == 'n') {
|
||||
|
@ -351,7 +351,7 @@ class DbConfigTask extends Shell {
|
|||
* @return void
|
||||
*/
|
||||
public function getConfig() {
|
||||
App::import('Model', 'ConnectionManager', false);
|
||||
App::uses('ConnectionManager', 'Model');
|
||||
|
||||
$useDbConfig = 'default';
|
||||
$configs = get_class_vars($this->databaseClassName);
|
||||
|
@ -361,7 +361,7 @@ class DbConfigTask extends Shell {
|
|||
|
||||
$connections = array_keys($configs);
|
||||
if (count($connections) > 1) {
|
||||
$useDbConfig = $this->in(__('Use Database Config') .':', $connections, 'default');
|
||||
$useDbConfig = $this->in(__d('cake_console', 'Use Database Config') .':', $connections, 'default');
|
||||
}
|
||||
return $useDbConfig;
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ class DbConfigTask extends Shell {
|
|||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(
|
||||
__('Bake new database configuration settings.')
|
||||
__d('cake_console', 'Bake new database configuration settings.')
|
||||
);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'File');
|
||||
App::uses('File', 'Utility');
|
||||
/**
|
||||
* Language string extractor
|
||||
*
|
||||
|
@ -112,11 +112,11 @@ class ExtractTask extends Shell {
|
|||
$this->__paths = explode(',', $this->params['paths']);
|
||||
} else {
|
||||
$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 = __d('cake_console', "What is the full path you would like to extract?\nExample: %s\n[Q]uit [D]one", $defaultPath);
|
||||
while (true) {
|
||||
$response = $this->in($message, null, $defaultPath);
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__('Extract Aborted'));
|
||||
$this->out(__d('cake_console', 'Extract Aborted'));
|
||||
$this->_stop();
|
||||
} elseif (strtoupper($response) === 'D') {
|
||||
$this->out();
|
||||
|
@ -125,7 +125,7 @@ class ExtractTask extends Shell {
|
|||
$this->__paths[] = $response;
|
||||
$defaultPath = 'D';
|
||||
} else {
|
||||
$this->err(__('The directory path you supplied was not found. Please try again.'));
|
||||
$this->err(__d('cake_console', 'The directory path you supplied was not found. Please try again.'));
|
||||
}
|
||||
$this->out();
|
||||
}
|
||||
|
@ -134,17 +134,17 @@ class ExtractTask extends Shell {
|
|||
if (isset($this->params['output'])) {
|
||||
$this->__output = $this->params['output'];
|
||||
} else {
|
||||
$message = __("What is the full path you would like to output?\nExample: %s\n[Q]uit", $this->__paths[0] . DS . 'locale');
|
||||
$message = __d('cake_console', "What is the full path you would like to output?\nExample: %s\n[Q]uit", $this->__paths[0] . DS . 'locale');
|
||||
while (true) {
|
||||
$response = $this->in($message, null, $this->__paths[0] . DS . 'locale');
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__('Extract Aborted'));
|
||||
$this->out(__d('cake_console', 'Extract Aborted'));
|
||||
$this->_stop();
|
||||
} elseif (is_dir($response)) {
|
||||
$this->__output = $response . DS;
|
||||
break;
|
||||
} else {
|
||||
$this->err(__('The directory path you supplied was not found. Please try again.'));
|
||||
$this->err(__d('cake_console', 'The directory path you supplied was not found. Please try again.'));
|
||||
}
|
||||
$this->out();
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class ExtractTask extends Shell {
|
|||
$this->__merge = !(strtolower($this->params['merge']) === 'no');
|
||||
} else {
|
||||
$this->out();
|
||||
$response = $this->in(__('Would you like to merge all domains strings into the default.pot file?'), array('y', 'n'), 'n');
|
||||
$response = $this->in(__d('cake_console', 'Would you like to merge all domains strings into the default.pot file?'), array('y', 'n'), 'n');
|
||||
$this->__merge = strtolower($response) === 'y';
|
||||
}
|
||||
|
||||
|
@ -173,13 +173,13 @@ class ExtractTask extends Shell {
|
|||
function __extract() {
|
||||
$this->out();
|
||||
$this->out();
|
||||
$this->out(__('Extracting...'));
|
||||
$this->out(__d('cake_console', 'Extracting...'));
|
||||
$this->hr();
|
||||
$this->out(__('Paths:'));
|
||||
$this->out(__d('cake_console', 'Paths:'));
|
||||
foreach ($this->__paths as $path) {
|
||||
$this->out(' ' . $path);
|
||||
}
|
||||
$this->out(__('Output Directory: ') . $this->__output);
|
||||
$this->out(__d('cake_console', 'Output Directory: ') . $this->__output);
|
||||
$this->hr();
|
||||
$this->__extractTokens();
|
||||
$this->__buildFiles();
|
||||
|
@ -187,7 +187,7 @@ class ExtractTask extends Shell {
|
|||
$this->__paths = $this->__files = $this->__storage = array();
|
||||
$this->__strings = $this->__tokens = array();
|
||||
$this->out();
|
||||
$this->out(__('Done.'));
|
||||
$this->out(__d('cake_console', 'Done.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,17 +197,17 @@ class ExtractTask extends Shell {
|
|||
*/
|
||||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(__('CakePHP Language String Extraction:'))
|
||||
->addOption('app', array('help' => __('Directory where your application is located.')))
|
||||
->addOption('paths', array('help' => __('Comma separted list of paths, full paths are needed.')))
|
||||
return $parser->description(__d('cake_console', 'CakePHP Language String Extraction:'))
|
||||
->addOption('app', array('help' => __d('cake_console', 'Directory where your application is located.')))
|
||||
->addOption('paths', array('help' => __d('cake_console', 'Comma separted list of paths, full paths are needed.')))
|
||||
->addOption('merge', array(
|
||||
'help' => __('Merge all domain strings into the default.po file.'),
|
||||
'help' => __d('cake_console', 'Merge all domain strings into the default.po file.'),
|
||||
'choices' => array('yes', 'no')
|
||||
))
|
||||
->addOption('output', array('help' => __('Full path to output directory.')))
|
||||
->addOption('files', array('help' => __('Comma separated list of files, full paths are needed.')))
|
||||
->addOption('output', array('help' => __d('cake_console', 'Full path to output directory.')))
|
||||
->addOption('files', array('help' => __d('cake_console', 'Comma separated list of files, full paths are needed.')))
|
||||
->addOption('exclude', array(
|
||||
'help' => __('Comma separated list of directories to exclude. Any path containing a path segment with the provided values will be skipped. E.g. test,vendors')
|
||||
'help' => __d('cake_console', 'Comma separated list of directories to exclude. Any path containing a path segment with the provided values will be skipped. E.g. test,vendors')
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -217,25 +217,25 @@ class ExtractTask extends Shell {
|
|||
* @return void
|
||||
*/
|
||||
public function help() {
|
||||
$this->out(__('CakePHP Language String Extraction:'));
|
||||
$this->out(__d('cake_console', 'CakePHP Language String Extraction:'));
|
||||
$this->hr();
|
||||
$this->out(__('The Extract script generates .pot file(s) with translations'));
|
||||
$this->out(__('By default the .pot file(s) will be place in the locale directory of -app'));
|
||||
$this->out(__('By default -app is ROOT/app'));
|
||||
$this->out(__d('cake_console', 'The Extract script generates .pot file(s) with translations'));
|
||||
$this->out(__d('cake_console', 'By default the .pot file(s) will be place in the locale directory of -app'));
|
||||
$this->out(__d('cake_console', 'By default -app is ROOT/app'));
|
||||
$this->hr();
|
||||
$this->out(__('Usage: cake i18n extract <command> <param1> <param2>...'));
|
||||
$this->out(__d('cake_console', 'Usage: cake i18n extract <command> <param1> <param2>...'));
|
||||
$this->out();
|
||||
$this->out(__('Params:'));
|
||||
$this->out(__(' -app [path...]: directory where your application is located'));
|
||||
$this->out(__(' -root [path...]: path to install'));
|
||||
$this->out(__(' -core [path...]: path to cake directory'));
|
||||
$this->out(__(' -paths [comma separated list of paths, full path is needed]'));
|
||||
$this->out(__(' -merge [yes|no]: Merge all domains strings into the default.pot file'));
|
||||
$this->out(__(' -output [path...]: Full path to output directory'));
|
||||
$this->out(__(' -files: [comma separated list of files, full path to file is needed]'));
|
||||
$this->out(__d('cake_console', 'Params:'));
|
||||
$this->out(__d('cake_console', ' -app [path...]: directory where your application is located'));
|
||||
$this->out(__d('cake_console', ' -root [path...]: path to install'));
|
||||
$this->out(__d('cake_console', ' -core [path...]: path to cake directory'));
|
||||
$this->out(__d('cake_console', ' -paths [comma separated list of paths, full path is needed]'));
|
||||
$this->out(__d('cake_console', ' -merge [yes|no]: Merge all domains strings into the default.pot file'));
|
||||
$this->out(__d('cake_console', ' -output [path...]: Full path to output directory'));
|
||||
$this->out(__d('cake_console', ' -files: [comma separated list of files, full path to file is needed]'));
|
||||
$this->out();
|
||||
$this->out(__('Commands:'));
|
||||
$this->out(__(' cake i18n extract help: Shows this help message.'));
|
||||
$this->out(__d('cake_console', 'Commands:'));
|
||||
$this->out(__d('cake_console', ' cake i18n extract help: Shows this help message.'));
|
||||
$this->out();
|
||||
}
|
||||
|
||||
|
@ -248,7 +248,7 @@ class ExtractTask extends Shell {
|
|||
function __extractTokens() {
|
||||
foreach ($this->__files as $file) {
|
||||
$this->__file = $file;
|
||||
$this->out(__('Processing %s...', $file));
|
||||
$this->out(__d('cake_console', 'Processing %s...', $file));
|
||||
|
||||
$code = file_get_contents($file);
|
||||
$allTokens = token_get_all($code);
|
||||
|
@ -411,11 +411,11 @@ class ExtractTask extends Shell {
|
|||
$response = '';
|
||||
while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
|
||||
$this->out();
|
||||
$response = $this->in(__('Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename), array('y', 'n', 'a'), 'y');
|
||||
$response = $this->in(__d('cake_console', 'Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename), array('y', 'n', 'a'), 'y');
|
||||
if (strtoupper($response) === 'N') {
|
||||
$response = '';
|
||||
while ($response == '') {
|
||||
$response = $this->in(__("What would you like to name this file?\nExample: %s", 'new_' . $filename), null, 'new_' . $filename);
|
||||
$response = $this->in(__d('cake_console', "What would you like to name this file?\nExample: %s", 'new_' . $filename), null, 'new_' . $filename);
|
||||
$File = new File($this->__output . $response);
|
||||
$filename = $response;
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ class ExtractTask extends Shell {
|
|||
* @access private
|
||||
*/
|
||||
function __markerError($file, $line, $marker, $count) {
|
||||
$this->out(__("Invalid marker content in %s:%s\n* %s(", $file, $line, $marker), true);
|
||||
$this->out(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker), true);
|
||||
$count += 2;
|
||||
$tokenCount = count($this->__tokens);
|
||||
$parenthesis = 1;
|
|
@ -16,7 +16,10 @@
|
|||
* @since CakePHP(tm) v 1.3
|
||||
* @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.
|
||||
*
|
||||
|
@ -54,7 +57,7 @@ class FixtureTask extends BakeTask {
|
|||
*/
|
||||
public function __construct($stdout = null, $stderr = null, $stdin = null) {
|
||||
parent::__construct($stdout, $stderr, $stdin);
|
||||
$this->path = APP . 'tests' . DS . 'fixtures' . DS;
|
||||
$this->path = APP . 'tests' . DS . 'Fixture' . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,25 +68,25 @@ class FixtureTask extends BakeTask {
|
|||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(
|
||||
__('Generate fixtures for use with the test suite. You can use `bake fixture all` to bake all fixtures.')
|
||||
__d('cake_console', 'Generate fixtures for use with the test suite. You can use `bake fixture all` to bake all fixtures.')
|
||||
)->addArgument('name', array(
|
||||
'help' => __('Name of the fixture to bake. Can use Plugin.name to bake plugin fixtures.')
|
||||
'help' => __d('cake_console', 'Name of the fixture to bake. Can use Plugin.name to bake plugin fixtures.')
|
||||
))->addOption('count', array(
|
||||
'help' => __('When using generated data, the number of records to include in the fixture(s).'),
|
||||
'help' => __d('cake_console', 'When using generated data, the number of records to include in the fixture(s).'),
|
||||
'short' => 'n',
|
||||
'default' => 10
|
||||
))->addOption('connection', array(
|
||||
'help' => __('Which database configuration to use for baking.'),
|
||||
'help' => __d('cake_console', 'Which database configuration to use for baking.'),
|
||||
'short' => 'c',
|
||||
'default' => 'default'
|
||||
))->addOption('plugin', array(
|
||||
'help' => __('CamelCased name of the plugin to bake fixtures for.'),
|
||||
'help' => __d('cake_console', 'CamelCased name of the plugin to bake fixtures for.'),
|
||||
'short' => 'p',
|
||||
))->addOption('records', array(
|
||||
'help' => 'Used with --count and <name>/all commands to pull [n] records from the live tables, where [n] is either --count or the default of 10',
|
||||
'short' => 'r',
|
||||
'boolean' => true
|
||||
))->epilog(__('Omitting all arguments and options will enter into an interactive mode.'));;
|
||||
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,16 +158,16 @@ class FixtureTask extends BakeTask {
|
|||
*/
|
||||
public function importOptions($modelName) {
|
||||
$options = array();
|
||||
$doSchema = $this->in(__('Would you like to import schema for this fixture?'), array('y', 'n'), 'n');
|
||||
$doSchema = $this->in(__d('cake_console', 'Would you like to import schema for this fixture?'), array('y', 'n'), 'n');
|
||||
if ($doSchema == 'y') {
|
||||
$options['schema'] = $modelName;
|
||||
}
|
||||
$doRecords = $this->in(__('Would you like to use record importing for this fixture?'), array('y', 'n'), 'n');
|
||||
$doRecords = $this->in(__d('cake_console', 'Would you like to use record importing for this fixture?'), array('y', 'n'), 'n');
|
||||
if ($doRecords == 'y') {
|
||||
$options['records'] = true;
|
||||
}
|
||||
if ($doRecords == 'n') {
|
||||
$prompt = __("Would you like to build this fixture with data from %s's table?", $modelName);
|
||||
$prompt = __d('cake_console', "Would you like to build this fixture with data from %s's table?", $modelName);
|
||||
$fromTable = $this->in($prompt, array('y', 'n'), 'n');
|
||||
if (strtolower($fromTable) == 'y') {
|
||||
$options['fromTable'] = true;
|
||||
|
@ -182,10 +185,10 @@ class FixtureTask extends BakeTask {
|
|||
* @return string Baked fixture content
|
||||
*/
|
||||
public function bake($model, $useTable = false, $importOptions = array()) {
|
||||
if (!class_exists('CakeSchema')) {
|
||||
App::import('Model', 'CakeSchema', false);
|
||||
}
|
||||
$table = $schema = $records = $import = $modelImport = $recordImport = null;
|
||||
App::uses('CakeSchema', 'Model');
|
||||
$table = $schema = $records = $import = $modelImport = null;
|
||||
$importBits = array();
|
||||
|
||||
if (!$useTable) {
|
||||
$useTable = Inflector::tableize($model);
|
||||
} elseif ($useTable != Inflector::tableize($model)) {
|
||||
|
@ -194,16 +197,17 @@ class FixtureTask extends BakeTask {
|
|||
|
||||
if (!empty($importOptions)) {
|
||||
if (isset($importOptions['schema'])) {
|
||||
$modelImport = "'model' => '{$importOptions['schema']}'";
|
||||
$modelImport = true;
|
||||
$importBits[] = "'model' => '{$importOptions['schema']}'";
|
||||
}
|
||||
if (isset($importOptions['records'])) {
|
||||
$recordImport = "'records' => true";
|
||||
$importBits[] = "'records' => true";
|
||||
}
|
||||
if ($modelImport && $recordImport) {
|
||||
$modelImport .= ', ';
|
||||
if ($this->connection != 'default') {
|
||||
$importBits[] .= "'connection' => '{$this->connection}'";
|
||||
}
|
||||
if (!empty($modelImport) || !empty($recordImport)) {
|
||||
$import = sprintf("array(%s%s)", $modelImport, $recordImport);
|
||||
if (!empty($importBits)) {
|
||||
$import = sprintf("array(%s)", implode(', ', $importBits));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,7 +249,7 @@ class FixtureTask extends BakeTask {
|
|||
$vars = array_merge($defaults, $otherVars);
|
||||
|
||||
$path = $this->getPath();
|
||||
$filename = Inflector::underscore($model) . '_fixture.php';
|
||||
$filename = Inflector::camelize($model) . 'Fixture.php';
|
||||
|
||||
$this->Template->set('model', $model);
|
||||
$this->Template->set($vars);
|
||||
|
@ -264,7 +268,7 @@ class FixtureTask extends BakeTask {
|
|||
public function getPath() {
|
||||
$path = $this->path;
|
||||
if (isset($this->plugin)) {
|
||||
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'fixtures' . DS;
|
||||
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'Fixture' . DS;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
@ -383,14 +387,13 @@ class FixtureTask extends BakeTask {
|
|||
protected function _getRecordsFromTable($modelName, $useTable = null) {
|
||||
if ($this->interactive) {
|
||||
$condition = null;
|
||||
$prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10");
|
||||
$prompt = __d('cake_console', "Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10");
|
||||
while (!$condition) {
|
||||
$condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
|
||||
}
|
||||
} else {
|
||||
$condition = 'WHERE 1=1 LIMIT ' . (isset($this->params['count']) ? $this->params['count'] : 10);
|
||||
}
|
||||
App::import('Model', 'Model', false);
|
||||
$modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
|
||||
$records = $modelObject->find('all', array(
|
||||
'conditions' => $condition,
|
|
@ -17,7 +17,10 @@
|
|||
* @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.
|
||||
|
@ -71,7 +74,6 @@ class ModelTask extends BakeTask {
|
|||
*
|
||||
*/
|
||||
public function execute() {
|
||||
App::import('Model', 'Model', false);
|
||||
parent::execute();
|
||||
|
||||
if (empty($this->args)) {
|
||||
|
@ -110,7 +112,7 @@ class ModelTask extends BakeTask {
|
|||
continue;
|
||||
}
|
||||
$modelClass = Inflector::classify($table);
|
||||
$this->out(__('Baking %s', $modelClass));
|
||||
$this->out(__d('cake_console', 'Baking %s', $modelClass));
|
||||
$object = $this->_getModelObject($modelClass);
|
||||
if ($this->bake($object, false) && $unitTestExists) {
|
||||
$this->bakeFixture($modelClass);
|
||||
|
@ -149,7 +151,7 @@ class ModelTask extends BakeTask {
|
|||
$this->out($i + 1 .'. ' . $option);
|
||||
}
|
||||
if (empty($prompt)) {
|
||||
$prompt = __('Make a selection from the choices above');
|
||||
$prompt = __d('cake_console', 'Make a selection from the choices above');
|
||||
}
|
||||
$choice = $this->in($prompt, null, $default);
|
||||
if (intval($choice) > 0 && intval($choice) <= $max) {
|
||||
|
@ -188,7 +190,7 @@ class ModelTask extends BakeTask {
|
|||
$primaryKey = $this->findPrimaryKey($fields);
|
||||
}
|
||||
} else {
|
||||
$this->err(__('Table %s does not exist, cannot bake a model without a table.', $useTable));
|
||||
$this->err(__d('cake_console', 'Table %s does not exist, cannot bake a model without a table.', $useTable));
|
||||
$this->_stop();
|
||||
return false;
|
||||
}
|
||||
|
@ -197,13 +199,13 @@ class ModelTask extends BakeTask {
|
|||
$displayField = $this->findDisplayField($tempModel->schema());
|
||||
}
|
||||
|
||||
$prompt = __("Would you like to supply validation criteria \nfor the fields in your model?");
|
||||
$prompt = __d('cake_console', "Would you like to supply validation criteria \nfor the fields in your model?");
|
||||
$wannaDoValidation = $this->in($prompt, array('y','n'), 'y');
|
||||
if (array_search($useTable, $this->_tables) !== false && strtolower($wannaDoValidation) == 'y') {
|
||||
$validate = $this->doValidation($tempModel);
|
||||
}
|
||||
|
||||
$prompt = __("Would you like to define model associations\n(hasMany, hasOne, belongsTo, etc.)?");
|
||||
$prompt = __d('cake_console', "Would you like to define model associations\n(hasMany, hasOne, belongsTo, etc.)?");
|
||||
$wannaDoAssoc = $this->in($prompt, array('y','n'), 'y');
|
||||
if (strtolower($wannaDoAssoc) == 'y') {
|
||||
$associations = $this->doAssociations($tempModel);
|
||||
|
@ -211,24 +213,24 @@ class ModelTask extends BakeTask {
|
|||
|
||||
$this->out();
|
||||
$this->hr();
|
||||
$this->out(__('The following Model will be created:'));
|
||||
$this->out(__d('cake_console', 'The following Model will be created:'));
|
||||
$this->hr();
|
||||
$this->out("Name: " . $currentModelName);
|
||||
|
||||
if ($this->connection !== 'default') {
|
||||
$this->out(__("DB Config: %s", $this->connection));
|
||||
$this->out(__d('cake_console', "DB Config: %s", $this->connection));
|
||||
}
|
||||
if ($fullTableName !== Inflector::tableize($currentModelName)) {
|
||||
$this->out(__('DB Table: %s', $fullTableName));
|
||||
$this->out(__d('cake_console', 'DB Table: %s', $fullTableName));
|
||||
}
|
||||
if ($primaryKey != 'id') {
|
||||
$this->out(__('Primary Key: %s', $primaryKey));
|
||||
$this->out(__d('cake_console', 'Primary Key: %s', $primaryKey));
|
||||
}
|
||||
if (!empty($validate)) {
|
||||
$this->out(__('Validation: %s', print_r($validate, true)));
|
||||
$this->out(__d('cake_console', 'Validation: %s', print_r($validate, true)));
|
||||
}
|
||||
if (!empty($associations)) {
|
||||
$this->out(__('Associations:'));
|
||||
$this->out(__d('cake_console', 'Associations:'));
|
||||
$assocKeys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
foreach ($assocKeys as $assocKey) {
|
||||
$this->_printAssociation($currentModelName, $assocKey, $associations);
|
||||
|
@ -236,7 +238,7 @@ class ModelTask extends BakeTask {
|
|||
}
|
||||
|
||||
$this->hr();
|
||||
$looksGood = $this->in(__('Look okay?'), array('y','n'), 'y');
|
||||
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y','n'), 'y');
|
||||
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
$vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField');
|
||||
|
@ -281,7 +283,7 @@ class ModelTask extends BakeTask {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return $this->in(__('What is the primaryKey?'), null, $name);
|
||||
return $this->in(__d('cake_console', 'What is the primaryKey?'), null, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -292,12 +294,12 @@ class ModelTask extends BakeTask {
|
|||
*/
|
||||
public function findDisplayField($fields) {
|
||||
$fieldNames = array_keys($fields);
|
||||
$prompt = __("A displayField could not be automatically detected\nwould you like to choose one?");
|
||||
$prompt = __d('cake_console', "A displayField could not be automatically detected\nwould you like to choose one?");
|
||||
$continue = $this->in($prompt, array('y', 'n'));
|
||||
if (strtolower($continue) == 'n') {
|
||||
return false;
|
||||
}
|
||||
$prompt = __('Choose a field from the options above:');
|
||||
$prompt = __d('cake_console', 'Choose a field from the options above:');
|
||||
$choice = $this->inOptions($fieldNames, $prompt);
|
||||
return $fieldNames[$choice];
|
||||
}
|
||||
|
@ -308,7 +310,7 @@ class ModelTask extends BakeTask {
|
|||
* @param object $model Model to have validations generated for.
|
||||
* @return array $validate Array of user selected validations.
|
||||
*/
|
||||
public function doValidation(&$model) {
|
||||
public function doValidation($model) {
|
||||
if (!is_object($model)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -365,10 +367,10 @@ class ModelTask extends BakeTask {
|
|||
while ($anotherValidator == 'y') {
|
||||
if ($this->interactive) {
|
||||
$this->out();
|
||||
$this->out(__('Field: %s', $fieldName));
|
||||
$this->out(__('Type: %s', $metaData['type']));
|
||||
$this->out(__d('cake_console', 'Field: %s', $fieldName));
|
||||
$this->out(__d('cake_console', 'Type: %s', $metaData['type']));
|
||||
$this->hr();
|
||||
$this->out(__('Please select one of the following validation options:'));
|
||||
$this->out(__d('cake_console', 'Please select one of the following validation options:'));
|
||||
$this->hr();
|
||||
}
|
||||
|
||||
|
@ -376,8 +378,8 @@ class ModelTask extends BakeTask {
|
|||
for ($i = 1; $i < $defaultChoice; $i++) {
|
||||
$prompt .= $i . ' - ' . $this->_validations[$i] . "\n";
|
||||
}
|
||||
$prompt .= __("%s - Do not do any validation on this field.\n", $defaultChoice);
|
||||
$prompt .= __("... or enter in a valid regex validation string.\n");
|
||||
$prompt .= __d('cake_console', "%s - Do not do any validation on this field.\n", $defaultChoice);
|
||||
$prompt .= __d('cake_console', "... or enter in a valid regex validation string.\n");
|
||||
|
||||
$methods = array_flip($this->_validations);
|
||||
$guess = $defaultChoice;
|
||||
|
@ -400,11 +402,11 @@ class ModelTask extends BakeTask {
|
|||
if ($this->interactive === true) {
|
||||
$choice = $this->in($prompt, null, $guess);
|
||||
if (in_array($choice, $alreadyChosen)) {
|
||||
$this->out(__("You have already chosen that validation rule,\nplease choose again"));
|
||||
$this->out(__d('cake_console', "You have already chosen that validation rule,\nplease choose again"));
|
||||
continue;
|
||||
}
|
||||
if (!isset($this->_validations[$choice]) && is_numeric($choice)) {
|
||||
$this->out(__('Please make a valid selection.'));
|
||||
$this->out(__d('cake_console', 'Please make a valid selection.'));
|
||||
continue;
|
||||
}
|
||||
$alreadyChosen[] = $choice;
|
||||
|
@ -426,7 +428,7 @@ class ModelTask extends BakeTask {
|
|||
}
|
||||
}
|
||||
if ($this->interactive == true && $choice != $defaultChoice) {
|
||||
$anotherValidator = $this->in(__('Would you like to add another validation rule?'), array('y', 'n'), 'n');
|
||||
$anotherValidator = $this->in(__d('cake_console', 'Would you like to add another validation rule?'), array('y', 'n'), 'n');
|
||||
} else {
|
||||
$anotherValidator = 'n';
|
||||
}
|
||||
|
@ -440,12 +442,12 @@ class ModelTask extends BakeTask {
|
|||
* @param object $model
|
||||
* @return array $assocaitons
|
||||
*/
|
||||
public function doAssociations(&$model) {
|
||||
public function doAssociations($model) {
|
||||
if (!is_object($model)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->interactive === true) {
|
||||
$this->out(__('One moment while the associations are detected.'));
|
||||
$this->out(__d('cake_console', 'One moment while the associations are detected.'));
|
||||
}
|
||||
|
||||
$fields = $model->schema(true);
|
||||
|
@ -473,9 +475,9 @@ class ModelTask extends BakeTask {
|
|||
if ($this->interactive === true) {
|
||||
$this->hr();
|
||||
if (empty($associations)) {
|
||||
$this->out(__('None found.'));
|
||||
$this->out(__d('cake_console', 'None found.'));
|
||||
} else {
|
||||
$this->out(__('Please confirm the following associations:'));
|
||||
$this->out(__d('cake_console', 'Please confirm the following associations:'));
|
||||
$this->hr();
|
||||
$associations = $this->confirmAssociations($model, $associations);
|
||||
}
|
||||
|
@ -491,7 +493,7 @@ class ModelTask extends BakeTask {
|
|||
* @param array $associations Array of inprogress associations
|
||||
* @return array $associations with belongsTo added in.
|
||||
*/
|
||||
public function findBelongsTo(&$model, $associations) {
|
||||
public function findBelongsTo($model, $associations) {
|
||||
$fields = $model->schema(true);
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
$offset = strpos($fieldName, '_id');
|
||||
|
@ -520,7 +522,7 @@ class ModelTask extends BakeTask {
|
|||
* @param array $associations Array of inprogress associations
|
||||
* @return array $associations with hasOne and hasMany added in.
|
||||
*/
|
||||
public function findHasOneAndMany(&$model, $associations) {
|
||||
public function findHasOneAndMany($model, $associations) {
|
||||
$foreignKey = $this->_modelKey($model->name);
|
||||
foreach ($this->_tables as $otherTable) {
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
|
||||
|
@ -563,7 +565,7 @@ class ModelTask extends BakeTask {
|
|||
* @param array $associations Array of inprogress associations
|
||||
* @return array $associations with hasAndBelongsToMany added in.
|
||||
*/
|
||||
public function findHasAndBelongsToMany(&$model, $associations) {
|
||||
public function findHasAndBelongsToMany($model, $associations) {
|
||||
$foreignKey = $this->_modelKey($model->name);
|
||||
foreach ($this->_tables as $otherTable) {
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
|
||||
|
@ -603,7 +605,7 @@ class ModelTask extends BakeTask {
|
|||
* @param array $associations Array of associations to be confirmed.
|
||||
* @return array Array of confirmed associations
|
||||
*/
|
||||
public function confirmAssociations(&$model, $associations) {
|
||||
public function confirmAssociations($model, $associations) {
|
||||
foreach ($associations as $type => $settings) {
|
||||
if (!empty($associations[$type])) {
|
||||
$count = count($associations[$type]);
|
||||
|
@ -632,19 +634,19 @@ class ModelTask extends BakeTask {
|
|||
* @return array Array of associations.
|
||||
*/
|
||||
public function doMoreAssociations($model, $associations) {
|
||||
$prompt = __('Would you like to define some additional model associations?');
|
||||
$prompt = __d('cake_console', 'Would you like to define some additional model associations?');
|
||||
$wannaDoMoreAssoc = $this->in($prompt, array('y','n'), 'n');
|
||||
$possibleKeys = $this->_generatePossibleKeys();
|
||||
while (strtolower($wannaDoMoreAssoc) == 'y') {
|
||||
$assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
$this->out(__('What is the association type?'));
|
||||
$assocType = intval($this->inOptions($assocs, __('Enter a number')));
|
||||
$this->out(__d('cake_console', 'What is the association type?'));
|
||||
$assocType = intval($this->inOptions($assocs, __d('cake_console', 'Enter a number')));
|
||||
|
||||
$this->out(__("For the following options be very careful to match your setup exactly.\nAny spelling mistakes will cause errors."));
|
||||
$this->out(__d('cake_console', "For the following options be very careful to match your setup exactly.\nAny spelling mistakes will cause errors."));
|
||||
$this->hr();
|
||||
|
||||
$alias = $this->in(__('What is the alias for this association?'));
|
||||
$className = $this->in(__('What className will %s use?', $alias), null, $alias );
|
||||
$alias = $this->in(__d('cake_console', 'What is the alias for this association?'));
|
||||
$className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias );
|
||||
$suggestedForeignKey = null;
|
||||
|
||||
if ($assocType == 0) {
|
||||
|
@ -659,22 +661,22 @@ class ModelTask extends BakeTask {
|
|||
$showKeys = null;
|
||||
}
|
||||
} else {
|
||||
$otherTable = $this->in(__('What is the table for this model?'));
|
||||
$otherTable = $this->in(__d('cake_console', 'What is the table for this model?'));
|
||||
$showKeys = $possibleKeys[$otherTable];
|
||||
}
|
||||
$suggestedForeignKey = $this->_modelKey($model->name);
|
||||
}
|
||||
if (!empty($showKeys)) {
|
||||
$this->out(__('A helpful List of possible keys'));
|
||||
$foreignKey = $this->inOptions($showKeys, __('What is the foreignKey?'));
|
||||
$this->out(__d('cake_console', 'A helpful List of possible keys'));
|
||||
$foreignKey = $this->inOptions($showKeys, __d('cake_console', 'What is the foreignKey?'));
|
||||
$foreignKey = $showKeys[intval($foreignKey)];
|
||||
}
|
||||
if (!isset($foreignKey)) {
|
||||
$foreignKey = $this->in(__('What is the foreignKey? Specify your own.'), null, $suggestedForeignKey);
|
||||
$foreignKey = $this->in(__d('cake_console', 'What is the foreignKey? Specify your own.'), null, $suggestedForeignKey);
|
||||
}
|
||||
if ($assocType == 3) {
|
||||
$associationForeignKey = $this->in(__('What is the associationForeignKey?'), null, $this->_modelKey($model->name));
|
||||
$joinTable = $this->in(__('What is the joinTable?'));
|
||||
$associationForeignKey = $this->in(__d('cake_console', 'What is the associationForeignKey?'), null, $this->_modelKey($model->name));
|
||||
$joinTable = $this->in(__d('cake_console', 'What is the joinTable?'));
|
||||
}
|
||||
$associations[$assocs[$assocType]] = array_values((array)$associations[$assocs[$assocType]]);
|
||||
$count = count($associations[$assocs[$assocType]]);
|
||||
|
@ -686,7 +688,7 @@ class ModelTask extends BakeTask {
|
|||
$associations[$assocs[$assocType]][$i]['associationForeignKey'] = $associationForeignKey;
|
||||
$associations[$assocs[$assocType]][$i]['joinTable'] = $joinTable;
|
||||
}
|
||||
$wannaDoMoreAssoc = $this->in(__('Define another association?'), array('y','n'), 'y');
|
||||
$wannaDoMoreAssoc = $this->in(__d('cake_console', 'Define another association?'), array('y','n'), 'y');
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
|
@ -739,7 +741,7 @@ class ModelTask extends BakeTask {
|
|||
$out = $this->Template->generate('classes', 'model');
|
||||
|
||||
$path = $this->getPath();
|
||||
$filename = $path . Inflector::underscore($name) . '.php';
|
||||
$filename = $path . $name . '.php';
|
||||
$this->out("\nBaking model class for $name...", 1, Shell::QUIET);
|
||||
$this->createFile($filename, $out);
|
||||
ClassRegistry::flush();
|
||||
|
@ -767,7 +769,7 @@ class ModelTask extends BakeTask {
|
|||
$this->_tables = $this->getAllTables($useDbConfig);
|
||||
|
||||
if ($this->interactive === true) {
|
||||
$this->out(__('Possible Models based on your current database:'));
|
||||
$this->out(__d('cake_console', 'Possible Models based on your current database:'));
|
||||
$this->_modelNames = array();
|
||||
$count = count($this->_tables);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
|
@ -789,7 +791,6 @@ class ModelTask extends BakeTask {
|
|||
if (!isset($useDbConfig)) {
|
||||
$useDbConfig = $this->connection;
|
||||
}
|
||||
App::import('Model', 'ConnectionManager', false);
|
||||
|
||||
$db = ConnectionManager::getDataSource($useDbConfig);
|
||||
$useTable = Inflector::tableize($modelName);
|
||||
|
@ -798,11 +799,11 @@ class ModelTask extends BakeTask {
|
|||
|
||||
if (array_search($useTable, $this->_tables) === false) {
|
||||
$this->out();
|
||||
$this->out(__("Given your model named '%s',\nCake would expect a database table named '%s'", $modelName, $fullTableName));
|
||||
$tableIsGood = $this->in(__('Do you want to use this table?'), array('y','n'), 'y');
|
||||
$this->out(__d('cake_console', "Given your model named '%s',\nCake would expect a database table named '%s'", $modelName, $fullTableName));
|
||||
$tableIsGood = $this->in(__d('cake_console', 'Do you want to use this table?'), array('y','n'), 'y');
|
||||
}
|
||||
if (strtolower($tableIsGood) == 'n') {
|
||||
$useTable = $this->in(__('What is the name of the table?'));
|
||||
$useTable = $this->in(__d('cake_console', 'What is the name of the table?'));
|
||||
}
|
||||
return $useTable;
|
||||
}
|
||||
|
@ -818,7 +819,6 @@ class ModelTask extends BakeTask {
|
|||
if (!isset($useDbConfig)) {
|
||||
$useDbConfig = $this->connection;
|
||||
}
|
||||
App::import('Model', 'ConnectionManager', false);
|
||||
|
||||
$tables = array();
|
||||
$db = ConnectionManager::getDataSource($useDbConfig);
|
||||
|
@ -834,7 +834,7 @@ class ModelTask extends BakeTask {
|
|||
$tables = $db->listSources();
|
||||
}
|
||||
if (empty($tables)) {
|
||||
$this->err(__('Your database does not have any tables.'));
|
||||
$this->err(__d('cake_console', 'Your database does not have any tables.'));
|
||||
$this->_stop();
|
||||
}
|
||||
return $tables;
|
||||
|
@ -851,15 +851,15 @@ class ModelTask extends BakeTask {
|
|||
$enteredModel = '';
|
||||
|
||||
while ($enteredModel == '') {
|
||||
$enteredModel = $this->in(__("Enter a number from the list above,\ntype in the name of another model, or 'q' to exit"), null, 'q');
|
||||
$enteredModel = $this->in(__d('cake_console', "Enter a number from the list above,\ntype in the name of another model, or 'q' to exit"), null, 'q');
|
||||
|
||||
if ($enteredModel === 'q') {
|
||||
$this->out(__('Exit'));
|
||||
$this->out(__d('cake_console', 'Exit'));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) {
|
||||
$this->err(__("The model name you supplied was empty,\nor the number you selected was not an option. Please try again."));
|
||||
$this->err(__d('cake_console', "The model name you supplied was empty,\nor the number you selected was not an option. Please try again."));
|
||||
$enteredModel = '';
|
||||
}
|
||||
}
|
||||
|
@ -879,18 +879,18 @@ class ModelTask extends BakeTask {
|
|||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(
|
||||
__('Bake models.')
|
||||
__d('cake_console', 'Bake models.')
|
||||
)->addArgument('name', array(
|
||||
'help' => __('Name of the model to bake. Can use Plugin.name to bake plugin models.')
|
||||
'help' => __d('cake_console', 'Name of the model to bake. Can use Plugin.name to bake plugin models.')
|
||||
))->addSubcommand('all', array(
|
||||
'help' => __('Bake all model files with associations and validation.')
|
||||
'help' => __d('cake_console', 'Bake all model files with associations and validation.')
|
||||
))->addOption('plugin', array(
|
||||
'short' => 'p',
|
||||
'help' => __('Plugin to bake the model into.')
|
||||
'help' => __d('cake_console', 'Plugin to bake the model into.')
|
||||
))->addOption('connection', array(
|
||||
'short' => 'c',
|
||||
'help' => __('The connection the model table is on.')
|
||||
))->epilog(__('Omitting all arguments and options will enter into an interactive mode.'));
|
||||
'help' => __d('cake_console', 'The connection the model table is on.')
|
||||
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
|
||||
}
|
||||
|
||||
/**
|
|
@ -16,7 +16,9 @@
|
|||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'File');
|
||||
|
||||
App::uses('File', 'Utility');
|
||||
App::uses('Folder', 'Utility');
|
||||
|
||||
/**
|
||||
* Task class for creating a plugin
|
||||
|
@ -54,8 +56,8 @@ class PluginTask extends Shell {
|
|||
$plugin = Inflector::camelize($this->args[0]);
|
||||
$pluginPath = $this->_pluginPath($plugin);
|
||||
if (is_dir($pluginPath)) {
|
||||
$this->out(__('Plugin: %s', $plugin));
|
||||
$this->out(__('Path: %s', $pluginPath));
|
||||
$this->out(__d('cake_console', 'Plugin: %s', $plugin));
|
||||
$this->out(__d('cake_console', 'Path: %s', $pluginPath));
|
||||
} else {
|
||||
$this->_interactive($plugin);
|
||||
}
|
||||
|
@ -72,11 +74,11 @@ class PluginTask extends Shell {
|
|||
*/
|
||||
protected function _interactive($plugin = null) {
|
||||
while ($plugin === null) {
|
||||
$plugin = $this->in(__('Enter the name of the plugin in CamelCase format'));
|
||||
$plugin = $this->in(__d('cake_console', 'Enter the name of the plugin in CamelCase format'));
|
||||
}
|
||||
|
||||
if (!$this->bake($plugin)) {
|
||||
$this->error(__("An error occured trying to bake: %s in %s", $plugin, $this->path . Inflector::underscore($pluginPath)));
|
||||
$this->error(__d('cake_console', "An error occured trying to bake: %s in %s", $plugin, $this->path . Inflector::underscore($pluginPath)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,11 +97,11 @@ class PluginTask extends Shell {
|
|||
$this->findPath($pathOptions);
|
||||
}
|
||||
$this->hr();
|
||||
$this->out(__("<info>Plugin Name:</info> %s", $plugin));
|
||||
$this->out(__("<info>Plugin Directory:</info> %s", $this->path . $pluginPath));
|
||||
$this->out(__d('cake_console', "<info>Plugin Name:</info> %s", $plugin));
|
||||
$this->out(__d('cake_console', "<info>Plugin Directory:</info> %s", $this->path . $pluginPath));
|
||||
$this->hr();
|
||||
|
||||
$looksGood = $this->in(__('Look okay?'), array('y', 'n', 'q'), 'y');
|
||||
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n', 'q'), 'y');
|
||||
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
$Folder = new Folder($this->path . $pluginPath);
|
||||
|
@ -154,7 +156,7 @@ class PluginTask extends Shell {
|
|||
$this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
|
||||
|
||||
$this->hr();
|
||||
$this->out(__('<success>Created:</success> %s in %s', $plugin, $this->path . $pluginPath), 2);
|
||||
$this->out(__d('cake_console', '<success>Created:</success> %s in %s', $plugin, $this->path . $pluginPath), 2);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -172,7 +174,7 @@ class PluginTask extends Shell {
|
|||
foreach ($pathOptions as $i => $option) {
|
||||
$this->out($i + 1 .'. ' . $option);
|
||||
}
|
||||
$prompt = __('Choose a plugin path from the paths above.');
|
||||
$prompt = __d('cake_console', 'Choose a plugin path from the paths above.');
|
||||
$choice = $this->in($prompt);
|
||||
if (intval($choice) > 0 && intval($choice) <= $max) {
|
||||
$valid = true;
|
||||
|
@ -192,7 +194,7 @@ class PluginTask extends Shell {
|
|||
'Create the directory structure, AppModel and AppController classes for a new plugin. ' .
|
||||
'Can create plugins in any of your bootstrapped plugin paths.'
|
||||
)->addArgument('name', array(
|
||||
'help' => __('CamelCased name of the plugin to create.')
|
||||
'help' => __d('cake_console', 'CamelCased name of the plugin to create.')
|
||||
));
|
||||
|
||||
}
|
|
@ -17,7 +17,10 @@
|
|||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'File');
|
||||
|
||||
App::uses('File', 'Utility');
|
||||
App::uses('String', 'Utility');
|
||||
App::uses('Security', 'Utility');
|
||||
|
||||
/**
|
||||
* Task class for creating new project apps and plugins
|
||||
|
@ -49,16 +52,8 @@ class ProjectTask extends Shell {
|
|||
$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) {
|
||||
$prompt = __("What is the full path for this app including the app directory name?\n Example:");
|
||||
$prompt = __d('cake_console', "What is the full path for this app including the app directory name?\n Example:");
|
||||
$default = APP_PATH . 'myapp';
|
||||
$project = $this->in($prompt . $default, null, $default);
|
||||
}
|
||||
|
@ -66,7 +61,7 @@ class ProjectTask extends Shell {
|
|||
if ($project) {
|
||||
$response = false;
|
||||
while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
|
||||
$prompt = __('<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
|
||||
$prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
|
||||
$response = $this->in($prompt, array('y','n'), 'n');
|
||||
if (strtolower($response) === 'n') {
|
||||
$response = $project = false;
|
||||
|
@ -78,51 +73,51 @@ class ProjectTask extends Shell {
|
|||
if ($this->bake($project)) {
|
||||
$path = Folder::slashTerm($project);
|
||||
if ($this->createHome($path)) {
|
||||
$this->out(__(' * Welcome page created'));
|
||||
$this->out(__d('cake_console', ' * Welcome page created'));
|
||||
} else {
|
||||
$this->err(__('The Welcome page was <error>NOT</error> created'));
|
||||
$this->err(__d('cake_console', 'The Welcome page was <error>NOT</error> created'));
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if ($this->securitySalt($path) === true) {
|
||||
$this->out(__(' * Random hash key created for \'Security.salt\''));
|
||||
$this->out(__d('cake_console', ' * Random hash key created for \'Security.salt\''));
|
||||
} else {
|
||||
$this->err(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', CONFIGS . 'core.php'));
|
||||
$this->err(__d('cake_console', 'Unable to generate random hash for \'Security.salt\', you should change it in %s', CONFIGS . 'core.php'));
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if ($this->securityCipherSeed($path) === true) {
|
||||
$this->out(__(' * Random seed created for \'Security.cipherSeed\''));
|
||||
$this->out(__d('cake_console', ' * Random seed created for \'Security.cipherSeed\''));
|
||||
} else {
|
||||
$this->err(__('Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', CONFIGS . 'core.php'));
|
||||
$this->err(__d('cake_console', 'Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', CONFIGS . 'core.php'));
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if ($this->corePath($path) === true) {
|
||||
$this->out(__(' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH));
|
||||
$this->out(__(' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH));
|
||||
$this->out(__(' * <warning>Remember to check these value after moving to production server</warning>'));
|
||||
$this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH));
|
||||
$this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH));
|
||||
$this->out(__d('cake_console', ' * <warning>Remember to check these value after moving to production server</warning>'));
|
||||
} else {
|
||||
$this->err(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' .DS .'index.php'));
|
||||
$this->err(__d('cake_console', 'Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' .DS .'index.php'));
|
||||
$success = false;
|
||||
}
|
||||
if ($this->consolePath($path) === true) {
|
||||
$this->out(__(' * app/console/cake.php path set.'));
|
||||
$this->out(__d('cake_console', ' * app/Console/cake.php path set.'));
|
||||
} else {
|
||||
$this->err(__('Unable to set console path for app/console.'));
|
||||
$this->err(__d('cake_console', 'Unable to set console path for app/Console.'));
|
||||
$success = false;
|
||||
}
|
||||
|
||||
$Folder = new Folder($path);
|
||||
if (!$Folder->chmod($path . 'tmp', 0777)) {
|
||||
$this->err(__('Could not set permissions on %s', $path . DS .'tmp'));
|
||||
$this->out(__('chmod -R 0777 %s', $path . DS .'tmp'));
|
||||
$this->err(__d('cake_console', 'Could not set permissions on %s', $path . DS .'tmp'));
|
||||
$this->out(__d('cake_console', 'chmod -R 0777 %s', $path . DS .'tmp'));
|
||||
$success = false;
|
||||
}
|
||||
if ($success) {
|
||||
$this->out(__('<success>Project baked successfully!</success>'));
|
||||
$this->out(__d('cake_console', '<success>Project baked successfully!</success>'));
|
||||
} else {
|
||||
$this->out(__('Project baked but with <warning>some issues.</warning>.'));
|
||||
$this->out(__d('cake_console', 'Project baked but with <warning>some issues.</warning>.'));
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
@ -140,27 +135,35 @@ class ProjectTask extends Shell {
|
|||
* @access private
|
||||
*/
|
||||
function bake($path, $skel = null, $skip = array('empty')) {
|
||||
if (!$skel) {
|
||||
if (!$skel && !empty($this->params['skel'])) {
|
||||
$skel = $this->params['skel'];
|
||||
}
|
||||
while (!$skel) {
|
||||
$skel = $this->in(__("What is the path to the directory layout you wish to copy?\nExample: %s", APP, null, ROOT . DS . 'myapp' . DS));
|
||||
if ($skel == '') {
|
||||
$this->err(__('The directory path you supplied was empty. Please try again.'));
|
||||
$skel = $this->in(
|
||||
__d('cake_console', "What is the path to the directory layout you wish to copy?"),
|
||||
null,
|
||||
CAKE . 'Console' . DS . 'templates' . DS . 'skel'
|
||||
);
|
||||
if (!$skel) {
|
||||
$this->err(__d('cake_console', 'The directory path you supplied was empty. Please try again.'));
|
||||
} else {
|
||||
while (is_dir($skel) === false) {
|
||||
$skel = $this->in(__('Directory path does not exist please choose another:'));
|
||||
$skel = $this->in(
|
||||
__d('cake_console', 'Directory path does not exist please choose another:'),
|
||||
null,
|
||||
CAKE . 'Console' . DS . 'templates' . DS . 'skel'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$app = basename($path);
|
||||
|
||||
$this->out(__('<info>Skel Directory</info>: ') . $skel);
|
||||
$this->out(__('<info>Will be copied to</info>: ') . $path);
|
||||
$this->out(__d('cake_console', '<info>Skel Directory</info>: ') . $skel);
|
||||
$this->out(__d('cake_console', '<info>Will be copied to</info>: ') . $path);
|
||||
$this->hr();
|
||||
|
||||
$looksGood = $this->in(__('Look okay?'), array('y', 'n', 'q'), 'y');
|
||||
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n', 'q'), 'y');
|
||||
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
$Folder = new Folder($skel);
|
||||
|
@ -170,10 +173,10 @@ class ProjectTask extends Shell {
|
|||
|
||||
if ($Folder->copy(array('to' => $path, 'skip' => $skip))) {
|
||||
$this->hr();
|
||||
$this->out(__('<success>Created:</success> %s in %s', $app, $path));
|
||||
$this->out(__d('cake_console', '<success>Created:</success> %s in %s', $app, $path));
|
||||
$this->hr();
|
||||
} else {
|
||||
$this->err(__("<error>Could not create</error> '%s' properly.", $app));
|
||||
$this->err(__d('cake_console', "<error>Could not create</error> '%s' properly.", $app));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -183,7 +186,7 @@ class ProjectTask extends Shell {
|
|||
|
||||
return true;
|
||||
} elseif (strtolower($looksGood) == 'q') {
|
||||
$this->out(__('Bake Aborted.'));
|
||||
$this->out(__d('cake_console', 'Bake Aborted.'));
|
||||
} else {
|
||||
$this->execute(false);
|
||||
return false;
|
||||
|
@ -199,7 +202,7 @@ class ProjectTask extends Shell {
|
|||
public function createHome($dir) {
|
||||
$app = basename($dir);
|
||||
$path = $dir . 'views' . DS . 'pages' . DS;
|
||||
$source = CAKE . 'console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp';
|
||||
$source = LIBS . 'Console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp';
|
||||
include($source);
|
||||
return $this->createFile($path.'home.ctp', $output);
|
||||
}
|
||||
|
@ -212,10 +215,10 @@ class ProjectTask extends Shell {
|
|||
* @return boolean success
|
||||
*/
|
||||
public function consolePath($path) {
|
||||
$File = new File($path . 'console' . DS . 'cake.php');
|
||||
$File = new File($path . 'Console' . DS . 'cake.php');
|
||||
$contents = $File->read();
|
||||
if (preg_match('/(__CAKE_PATH__)/', $contents, $match)) {
|
||||
$path = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS;
|
||||
$path = LIBS . 'Console' . DS;
|
||||
$replacement = "'" . str_replace(DS, "' . DIRECTORY_SEPARATOR . '", $path) . "'";
|
||||
$result = str_replace($match[0], $replacement, $contents);
|
||||
if ($File->write($result)) {
|
||||
|
@ -236,9 +239,6 @@ class ProjectTask extends Shell {
|
|||
$File = new File($path . 'config' . DS . 'core.php');
|
||||
$contents = $File->read();
|
||||
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();
|
||||
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents);
|
||||
if ($File->write($result)) {
|
||||
|
@ -260,7 +260,7 @@ class ProjectTask extends Shell {
|
|||
$contents = $File->read();
|
||||
if (preg_match('/([\s]*Configure::write\(\'Security.cipherSeed\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
||||
if (!class_exists('Security')) {
|
||||
require LIBS . 'security.php';
|
||||
require LIBS . 'Utility' . DS . 'security.php';
|
||||
}
|
||||
$string = substr(bin2hex(Security::generateAuthKey()), 0, 30);
|
||||
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.cipherSeed\', \''.$string.'\');', $contents);
|
||||
|
@ -284,7 +284,7 @@ class ProjectTask extends Shell {
|
|||
$contents = $File->read();
|
||||
if (preg_match('/([\s]*define\(\'CAKE_CORE_INCLUDE_PATH\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
||||
$root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " DS . '" : "'";
|
||||
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', " . $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "');", $contents);
|
||||
$result = str_replace($match[0], "\n\t\tdefine('CAKE_CORE_INCLUDE_PATH', " . $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "');", $contents);
|
||||
if (!$File->write($result)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ class ProjectTask extends Shell {
|
|||
$File = new File($path . 'webroot' . DS . 'test.php');
|
||||
$contents = $File->read();
|
||||
if (preg_match('/([\s]*define\(\'CAKE_CORE_INCLUDE_PATH\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
||||
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', " . $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "');", $contents);
|
||||
$result = str_replace($match[0], "\n\t\tdefine('CAKE_CORE_INCLUDE_PATH', " . $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "');", $contents);
|
||||
if (!$File->write($result)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -316,8 +316,8 @@ class ProjectTask extends Shell {
|
|||
$path = (empty($this->configPath)) ? CONFIGS : $this->configPath;
|
||||
$File = new File($path . 'core.php');
|
||||
$contents = $File->read();
|
||||
if (preg_match('%([/\s]*Configure::write\(\'Routing.prefixes\',[\s\'a-z,\)\(]*\);)%', $contents, $match)) {
|
||||
$result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents);
|
||||
if (preg_match('%(\s*[/]*Configure::write\(\'Routing.prefixes\',[\s\'a-z,\)\(]*\);)%', $contents, $match)) {
|
||||
$result = str_replace($match[0], "\n" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents);
|
||||
if ($File->write($result)) {
|
||||
Configure::write('Routing.prefixes', array($name));
|
||||
return true;
|
||||
|
@ -343,7 +343,7 @@ class ProjectTask extends Shell {
|
|||
}
|
||||
if ($this->interactive) {
|
||||
$this->out();
|
||||
$this->out(__('You have more than one routing prefix configured'));
|
||||
$this->out(__d('cake_console', 'You have more than one routing prefix configured'));
|
||||
}
|
||||
$options = array();
|
||||
foreach ($prefixes as $i => $prefix) {
|
||||
|
@ -352,19 +352,19 @@ class ProjectTask extends Shell {
|
|||
$this->out($i + 1 . '. ' . $prefix);
|
||||
}
|
||||
}
|
||||
$selection = $this->in(__('Please choose a prefix to bake with.'), $options, 1);
|
||||
$selection = $this->in(__d('cake_console', 'Please choose a prefix to bake with.'), $options, 1);
|
||||
return $prefixes[$selection - 1] . '_';
|
||||
}
|
||||
if ($this->interactive) {
|
||||
$this->hr();
|
||||
$this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.');
|
||||
$this->out(__('What would you like the prefix route to be?'));
|
||||
$this->out(__('Example: www.example.com/admin/controller'));
|
||||
$this->out(__d('cake_console', 'What would you like the prefix route to be?'));
|
||||
$this->out(__d('cake_console', 'Example: www.example.com/admin/controller'));
|
||||
while ($admin == '') {
|
||||
$admin = $this->in(__('Enter a routing prefix:'), null, 'admin');
|
||||
$admin = $this->in(__d('cake_console', 'Enter a routing prefix:'), null, 'admin');
|
||||
}
|
||||
if ($this->cakeAdmin($admin) !== true) {
|
||||
$this->out(__('<error>Unable to write to</error> /app/config/core.php.'));
|
||||
$this->out(__d('cake_console', '<error>Unable to write to</error> /app/config/core.php.'));
|
||||
$this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.');
|
||||
$this->_stop();
|
||||
}
|
||||
|
@ -381,13 +381,14 @@ class ProjectTask extends Shell {
|
|||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(
|
||||
__('Generate a new CakePHP project skeleton.')
|
||||
__d('cake_console', 'Generate a new CakePHP project skeleton.')
|
||||
)->addArgument('name', array(
|
||||
'help' => __('Application directory to make, if it starts with "/" the path is absolute.')
|
||||
'help' => __d('cake_console', 'Application directory to make, if it starts with "/" the path is absolute.')
|
||||
))->addOption('empty', array(
|
||||
'help' => __('Create empty files in each of the directories. Good if you are using git')
|
||||
'help' => __d('cake_console', 'Create empty files in each of the directories. Good if you are using git')
|
||||
))->addOption('skel', array(
|
||||
'help' => __('The directory layout to use for the new application skeleton. Defaults to cake/console/templates/skel of CakePHP used to create the project.')
|
||||
'default' => current(App::core('Console')) . DS . 'templates' . DS . 'skel',
|
||||
'help' => __d('cake_console', '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
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'Folder');
|
||||
|
||||
App::uses('Folder', 'Utility');
|
||||
|
||||
class TemplateTask extends Shell {
|
||||
|
||||
|
@ -53,12 +54,13 @@ class TemplateTask extends Shell {
|
|||
* @return array Array of bake themes that are installed.
|
||||
*/
|
||||
protected function _findThemes() {
|
||||
$paths = App::path('shells');
|
||||
$core = array_pop($paths);
|
||||
$paths = App::path('Console');
|
||||
$core = current(App::core('Console'));
|
||||
$separator = DS === '/' ? '/' : '\\\\';
|
||||
$core = preg_replace('#shells' . $separator . '$#', '', $core);
|
||||
$paths[] = $core;
|
||||
|
||||
$Folder = new Folder($core . 'templates' . DS . 'default');
|
||||
|
||||
$contents = $Folder->read();
|
||||
$themeFolders = $contents[0];
|
||||
|
||||
|
@ -67,6 +69,7 @@ class TemplateTask extends Shell {
|
|||
$paths[] = $this->_pluginPath($plugin) . 'console' . DS . 'shells' . DS;
|
||||
$paths[] = $this->_pluginPath($plugin) . 'vendors' . DS . 'shells' . DS;
|
||||
}
|
||||
$paths[] = $core;
|
||||
|
||||
// TEMPORARY TODO remove when all paths are DS terminated
|
||||
foreach ($paths as $i => $path) {
|
||||
|
@ -167,8 +170,8 @@ class TemplateTask extends Shell {
|
|||
}
|
||||
|
||||
$this->hr();
|
||||
$this->out(__('You have more than one set of templates installed.'));
|
||||
$this->out(__('Please choose the template set you wish to use:'));
|
||||
$this->out(__d('cake_console', 'You have more than one set of templates installed.'));
|
||||
$this->out(__d('cake_console', 'Please choose the template set you wish to use:'));
|
||||
$this->hr();
|
||||
|
||||
$i = 1;
|
||||
|
@ -178,7 +181,7 @@ class TemplateTask extends Shell {
|
|||
$indexedPaths[$i] = $path;
|
||||
$i++;
|
||||
}
|
||||
$index = $this->in(__('Which bake theme would you like to use?'), range(1, $i - 1), 1);
|
||||
$index = $this->in(__d('cake_console', 'Which bake theme would you like to use?'), range(1, $i - 1), 1);
|
||||
$themeNames = array_keys($this->templatePaths);
|
||||
$this->params['theme'] = $themeNames[$index - 1];
|
||||
return $indexedPaths[$index];
|
||||
|
@ -205,7 +208,7 @@ class TemplateTask extends Shell {
|
|||
return $templatePath;
|
||||
}
|
||||
}
|
||||
$this->err(__('Could not find template for %s', $filename));
|
||||
$this->err(__d('cake_console', 'Could not find template for %s', $filename));
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,8 +17,8 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
include_once dirname(__FILE__) . DS . 'bake.php';
|
||||
App::import('Model', 'ClassRegistry');
|
||||
App::uses('BakeTask', 'Console/Command/Task');
|
||||
App::uses('ClassRegistry', 'Utility');
|
||||
|
||||
/**
|
||||
* Task class for creating and updating test files.
|
||||
|
@ -49,7 +49,13 @@ class TestTask extends BakeTask {
|
|||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
public $classTypes = array('Model', 'Controller', 'Component', 'Behavior', 'Helper');
|
||||
public $classTypes = array(
|
||||
'Model' => 'Model',
|
||||
'Controller' => 'Controller',
|
||||
'Component' => 'Controller/Component',
|
||||
'Behavior' => 'Model/Behavior',
|
||||
'Helper' => 'View/Helper'
|
||||
);
|
||||
|
||||
/**
|
||||
* Internal list of fixtures that have been added so far.
|
||||
|
@ -89,14 +95,14 @@ class TestTask extends BakeTask {
|
|||
protected function _interactive($type = null) {
|
||||
$this->interactive = true;
|
||||
$this->hr();
|
||||
$this->out(__('Bake Tests'));
|
||||
$this->out(__('Path: %s', $this->path));
|
||||
$this->out(__d('cake_console', 'Bake Tests'));
|
||||
$this->out(__d('cake_console', 'Path: %s', $this->path));
|
||||
$this->hr();
|
||||
|
||||
if ($type) {
|
||||
$type = Inflector::camelize($type);
|
||||
if (!in_array($type, $this->classTypes)) {
|
||||
$this->error(__('Incorrect type provided. Please choose one of %s', implode(', ', $this->classTypes)));
|
||||
if (!isset($this->classTypes[$type])) {
|
||||
$this->error(__d('cake_console', 'Incorrect type provided. Please choose one of %s', implode(', ', array_keys($this->classTypes))));
|
||||
}
|
||||
} else {
|
||||
$type = $this->getObjectType();
|
||||
|
@ -113,13 +119,17 @@ class TestTask extends BakeTask {
|
|||
*/
|
||||
public function bake($type, $className) {
|
||||
if ($this->typeCanDetectFixtures($type) && $this->isLoadableClass($type, $className)) {
|
||||
$this->out(__('Bake is detecting possible fixtures...'));
|
||||
$this->out(__d('cake_console', 'Bake is detecting possible fixtures...'));
|
||||
$testSubject = $this->buildTestSubject($type, $className);
|
||||
$this->generateFixtureList($testSubject);
|
||||
} elseif ($this->interactive) {
|
||||
$this->getUserFixtures();
|
||||
}
|
||||
$fullClassName = $this->getRealClassName($type, $className);
|
||||
$fullClassName = $className;
|
||||
|
||||
if (!$this->interactive) {
|
||||
$fullClassName = $this->getRealClassName($type, $className);
|
||||
}
|
||||
|
||||
$methods = array();
|
||||
if (class_exists($fullClassName)) {
|
||||
|
@ -154,20 +164,22 @@ class TestTask extends BakeTask {
|
|||
*/
|
||||
public function getObjectType() {
|
||||
$this->hr();
|
||||
$this->out(__('Select an object type:'));
|
||||
$this->out(__d('cake_console', 'Select an object type:'));
|
||||
$this->hr();
|
||||
|
||||
$keys = array();
|
||||
foreach ($this->classTypes as $key => $option) {
|
||||
$this->out(++$key . '. ' . $option);
|
||||
$keys[] = $key;
|
||||
$i = 0;
|
||||
foreach ($this->classTypes as $option => $package) {
|
||||
$this->out(++$i . '. ' . $option);
|
||||
$keys[] = $i;
|
||||
}
|
||||
$keys[] = 'q';
|
||||
$selection = $this->in(__('Enter the type of object to bake a test for or (q)uit'), $keys, 'q');
|
||||
$selection = $this->in(__d('cake_console', 'Enter the type of object to bake a test for or (q)uit'), $keys, 'q');
|
||||
if ($selection == 'q') {
|
||||
return $this->_stop();
|
||||
}
|
||||
return $this->classTypes[$selection - 1];
|
||||
$types = array_keys($this->classTypes);
|
||||
return $types[$selection - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,14 +189,28 @@ class TestTask extends BakeTask {
|
|||
* @return string Class name the user chose.
|
||||
*/
|
||||
public function getClassName($objectType) {
|
||||
$options = App::objects(strtolower($objectType));
|
||||
$this->out(__('Choose a %s class', $objectType));
|
||||
$type = strtolower($objectType);
|
||||
if ($this->plugin) {
|
||||
$path = Inflector::pluralize($type);
|
||||
if ($type === 'helper') {
|
||||
$path = 'View/Helper';
|
||||
} elseif ($type === 'component') {
|
||||
$path = 'Controller/Component';
|
||||
} elseif ($type === 'behavior') {
|
||||
$path = 'Model/Behavior';
|
||||
}
|
||||
$plugin = $this->plugin . '.';
|
||||
$options = App::objects($plugin . $type);
|
||||
} else {
|
||||
$options = App::objects($type);
|
||||
}
|
||||
$this->out(__d('cake_console', 'Choose a %s class', $objectType));
|
||||
$keys = array();
|
||||
foreach ($options as $key => $option) {
|
||||
$this->out(++$key . '. ' . $option);
|
||||
$keys[] = $key;
|
||||
}
|
||||
$selection = $this->in(__('Choose an existing class, or enter the name of a class that does not exist'));
|
||||
$selection = $this->in(__d('cake_console', 'Choose an existing class, or enter the name of a class that does not exist'));
|
||||
if (isset($options[$selection - 1])) {
|
||||
return $options[$selection - 1];
|
||||
}
|
||||
|
@ -243,7 +269,7 @@ class TestTask extends BakeTask {
|
|||
* @return string Real classname
|
||||
*/
|
||||
public function getRealClassName($type, $class) {
|
||||
if (strtolower($type) == 'model') {
|
||||
if (strtolower($type) == 'model' || empty($this->classTypes[$type])) {
|
||||
return $class;
|
||||
}
|
||||
return $class . $type;
|
||||
|
@ -276,7 +302,7 @@ class TestTask extends BakeTask {
|
|||
* @param object $subject The object you want to generate fixtures for.
|
||||
* @return array Array of fixtures to be included in the test.
|
||||
*/
|
||||
public function generateFixtureList(&$subject) {
|
||||
public function generateFixtureList($subject) {
|
||||
$this->_fixtures = array();
|
||||
if (is_a($subject, 'Model')) {
|
||||
$this->_processModel($subject);
|
||||
|
@ -293,7 +319,7 @@ class TestTask extends BakeTask {
|
|||
* @param Model $subject A Model class to scan for associations and pull fixtures off of.
|
||||
* @return void
|
||||
*/
|
||||
protected function _processModel(&$subject) {
|
||||
protected function _processModel($subject) {
|
||||
$this->_addFixture($subject->name);
|
||||
$associated = $subject->getAssociated();
|
||||
foreach ($associated as $alias => $type) {
|
||||
|
@ -317,7 +343,7 @@ class TestTask extends BakeTask {
|
|||
* @param Controller $subject A controller to pull model names off of.
|
||||
* @return void
|
||||
*/
|
||||
protected function _processController(&$subject) {
|
||||
protected function _processController($subject) {
|
||||
$subject->constructClasses();
|
||||
$models = array(Inflector::classify($subject->name));
|
||||
if (!empty($subject->uses)) {
|
||||
|
@ -352,10 +378,10 @@ class TestTask extends BakeTask {
|
|||
* @return array Array of fixtures the user wants to add.
|
||||
*/
|
||||
public function getUserFixtures() {
|
||||
$proceed = $this->in(__('Bake could not detect fixtures, would you like to add some?'), array('y','n'), 'n');
|
||||
$proceed = $this->in(__d('cake_console', 'Bake could not detect fixtures, would you like to add some?'), array('y','n'), 'n');
|
||||
$fixtures = array();
|
||||
if (strtolower($proceed) == 'y') {
|
||||
$fixtureList = $this->in(__("Please provide a comma separated list of the fixtures names you'd like to use.\nExample: 'app.comment, app.post, plugin.forums.post'"));
|
||||
$fixtureList = $this->in(__d('cake_console', "Please provide a comma separated list of the fixtures names you'd like to use.\nExample: 'app.comment, app.post, plugin.forums.post'"));
|
||||
$fixtureListTrimmed = str_replace(' ', '', $fixtureList);
|
||||
$fixtures = explode(',', $fixtureListTrimmed);
|
||||
}
|
||||
|
@ -403,12 +429,14 @@ class TestTask extends BakeTask {
|
|||
* @return string filename the test should be created on.
|
||||
*/
|
||||
public function testCaseFileName($type, $className) {
|
||||
$path = $this->getPath();;
|
||||
$path .= 'cases' . DS . strtolower($type) . 's' . DS;
|
||||
if (strtolower($type) == 'controller') {
|
||||
$path = $this->getPath() . 'Case' . DS;
|
||||
if (isset($this->classTypes[$type])) {
|
||||
$path .= $this->classTypes[$type] . DS;
|
||||
}
|
||||
if (!$this->interactive) {
|
||||
$className = $this->getRealClassName($type, $className);
|
||||
}
|
||||
return $path . Inflector::underscore($className) . '.test.php';
|
||||
return $path . Inflector::camelize($className) . 'Test.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -418,15 +446,29 @@ class TestTask extends BakeTask {
|
|||
*/
|
||||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(__('Bake test case skeletons for classes.'))
|
||||
return $parser->description(__d('cake_console', 'Bake test case skeletons for classes.'))
|
||||
->addArgument('type', array(
|
||||
'help' => __('Type of class to bake, can be any of the following: controller, model, helper, component or behavior.'),
|
||||
'help' => __d('cake_console', 'Type of class to bake, can be any of the following: controller, model, helper, component or behavior.'),
|
||||
'choices' => array('controller', 'model', 'helper', 'component', 'behavior')
|
||||
))->addArgument('name', array(
|
||||
'help' => __('An existing class to bake tests for.')
|
||||
'help' => __d('cake_console', 'An existing class to bake tests for.')
|
||||
))->addOption('plugin', array(
|
||||
'short' => 'p',
|
||||
'help' => __('CamelCased name of the plugin to bake tests for.')
|
||||
))->epilog(__('Omitting all arguments and options will enter into an interactive mode.'));
|
||||
'help' => __d('cake_console', 'CamelCased name of the plugin to bake tests for.')
|
||||
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path for output. Checks the plugin property
|
||||
* and returns the correct path.
|
||||
*
|
||||
* @return string Path to output.
|
||||
*/
|
||||
public function getPath() {
|
||||
$path = $this->path;
|
||||
if (isset($this->plugin)) {
|
||||
$path = $this->_pluginPath($this->plugin) . 'tests' . DS;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
|
@ -16,8 +16,9 @@
|
|||
* @since CakePHP(tm) v 1.2
|
||||
* @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.
|
||||
|
@ -146,7 +147,7 @@ class ViewTask extends BakeTask {
|
|||
protected function _methodsToBake() {
|
||||
$methods = array_diff(
|
||||
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;
|
||||
if (empty($methods)) {
|
||||
|
@ -188,7 +189,8 @@ class ViewTask extends BakeTask {
|
|||
$model = $this->_modelName($table);
|
||||
$this->controllerName = $this->_controllerName($model);
|
||||
$this->controllerPath = Inflector::underscore($this->controllerName);
|
||||
if (App::import('Model', $model)) {
|
||||
App::uses($model, 'Model');
|
||||
if (class_exists($model)) {
|
||||
$vars = $this->__loadController();
|
||||
if (!$actions) {
|
||||
$actions = $this->_methodsToBake();
|
||||
|
@ -219,17 +221,17 @@ class ViewTask extends BakeTask {
|
|||
|
||||
$this->controllerPath = strtolower(Inflector::underscore($this->controllerName));
|
||||
|
||||
$prompt = __("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", $this->controllerName);
|
||||
$prompt = __d('cake_console', "Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", $this->controllerName);
|
||||
$interactive = $this->in($prompt, array('y', 'n'), 'n');
|
||||
|
||||
if (strtolower($interactive) == 'n') {
|
||||
$this->interactive = false;
|
||||
}
|
||||
|
||||
$prompt = __("Would you like to create some CRUD views\n(index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller\nand model classes (including associated models).");
|
||||
$prompt = __d('cake_console', "Would you like to create some CRUD views\n(index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller\nand model classes (including associated models).");
|
||||
$wannaDoScaffold = $this->in($prompt, array('y','n'), 'y');
|
||||
|
||||
$wannaDoAdmin = $this->in(__("Would you like to create the views for admin routing?"), array('y','n'), 'n');
|
||||
$wannaDoAdmin = $this->in(__d('cake_console', "Would you like to create the views for admin routing?"), array('y','n'), 'n');
|
||||
|
||||
if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoAdmin) == 'y') {
|
||||
$vars = $this->__loadController();
|
||||
|
@ -248,7 +250,7 @@ class ViewTask extends BakeTask {
|
|||
}
|
||||
$this->hr();
|
||||
$this->out();
|
||||
$this->out(__("View Scaffolding Complete.\n"));
|
||||
$this->out(__d('cake_console', "View Scaffolding Complete.\n"));
|
||||
} else {
|
||||
$this->customAction();
|
||||
}
|
||||
|
@ -266,20 +268,21 @@ class ViewTask extends BakeTask {
|
|||
*/
|
||||
private function __loadController() {
|
||||
if (!$this->controllerName) {
|
||||
$this->err(__('Controller not found'));
|
||||
$this->err(__d('cake_console', 'Controller not found'));
|
||||
}
|
||||
|
||||
$import = $this->controllerName;
|
||||
$plugin = null;
|
||||
if ($this->plugin) {
|
||||
$import = $this->plugin . '.' . $this->controllerName;
|
||||
$plugin = $this->plugin . '.';
|
||||
}
|
||||
|
||||
if (!App::import('Controller', $import)) {
|
||||
$file = $this->controllerPath . '_controller.php';
|
||||
$this->err(__("The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", $file));
|
||||
$controllerClassName = $this->controllerName . 'Controller';
|
||||
App::uses($controllerClassName, $plugin . 'Controller');
|
||||
if (!class_exists($controllerClassName)) {
|
||||
$file = $controllerClassName . '.php';
|
||||
$this->err(__d('cake_console', "The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", $file));
|
||||
$this->_stop();
|
||||
}
|
||||
$controllerClassName = $this->controllerName . 'Controller';
|
||||
$controllerObj = new $controllerClassName();
|
||||
$controllerObj->plugin = $this->plugin;
|
||||
$controllerObj->constructClasses();
|
||||
|
@ -328,25 +331,25 @@ class ViewTask extends BakeTask {
|
|||
public function customAction() {
|
||||
$action = '';
|
||||
while ($action == '') {
|
||||
$action = $this->in(__('Action Name? (use lowercase_underscored function name)'));
|
||||
$action = $this->in(__d('cake_console', 'Action Name? (use lowercase_underscored function name)'));
|
||||
if ($action == '') {
|
||||
$this->out(__('The action name you supplied was empty. Please try again.'));
|
||||
$this->out(__d('cake_console', 'The action name you supplied was empty. Please try again.'));
|
||||
}
|
||||
}
|
||||
$this->out();
|
||||
$this->hr();
|
||||
$this->out(__('The following view will be created:'));
|
||||
$this->out(__d('cake_console', 'The following view will be created:'));
|
||||
$this->hr();
|
||||
$this->out(__('Controller Name: %s', $this->controllerName));
|
||||
$this->out(__('Action Name: %s', $action));
|
||||
$this->out(__('Path: %s', $this->params['app'] . DS . $this->controllerPath . DS . Inflector::underscore($action) . ".ctp"));
|
||||
$this->out(__d('cake_console', 'Controller Name: %s', $this->controllerName));
|
||||
$this->out(__d('cake_console', 'Action Name: %s', $action));
|
||||
$this->out(__d('cake_console', 'Path: %s', $this->params['app'] . DS . $this->controllerPath . DS . Inflector::underscore($action) . ".ctp"));
|
||||
$this->hr();
|
||||
$looksGood = $this->in(__('Look okay?'), array('y','n'), 'y');
|
||||
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y','n'), 'y');
|
||||
if (strtolower($looksGood) == 'y') {
|
||||
$this->bake($action, ' ');
|
||||
$this->_stop();
|
||||
} else {
|
||||
$this->out(__('Bake Aborted.'));
|
||||
$this->out(__d('cake_console', 'Bake Aborted.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -428,25 +431,25 @@ class ViewTask extends BakeTask {
|
|||
public function getOptionParser() {
|
||||
$parser = parent::getOptionParser();
|
||||
return $parser->description(
|
||||
__('Bake views for a controller, using built-in or custom templates.')
|
||||
__d('cake_console', 'Bake views for a controller, using built-in or custom templates.')
|
||||
)->addArgument('controller', array(
|
||||
'help' => __('Name of the controller views to bake. Can be Plugin.name as a shortcut for plugin baking.')
|
||||
'help' => __d('cake_console', 'Name of the controller views to bake. Can be Plugin.name as a shortcut for plugin baking.')
|
||||
))->addArgument('action', array(
|
||||
'help' => __("Will bake a single action's file. core templates are (index, add, edit, view)")
|
||||
'help' => __d('cake_console', "Will bake a single action's file. core templates are (index, add, edit, view)")
|
||||
))->addArgument('alias', array(
|
||||
'help' => __('Will bake the template in <action> but create the filename after <alias>.')
|
||||
'help' => __d('cake_console', 'Will bake the template in <action> but create the filename after <alias>.')
|
||||
))->addOption('plugin', array(
|
||||
'short' => 'p',
|
||||
'help' => __('Plugin to bake the view into.')
|
||||
'help' => __d('cake_console', 'Plugin to bake the view into.')
|
||||
))->addOption('admin', array(
|
||||
'help' => __('Set to only bake views for a prefix in Routing.prefixes'),
|
||||
'help' => __d('cake_console', 'Set to only bake views for a prefix in Routing.prefixes'),
|
||||
'boolean' => true
|
||||
))->addOption('connection', array(
|
||||
'short' => 'c',
|
||||
'help' => __('The connection the connected model is on.')
|
||||
'help' => __d('cake_console', 'The connection the connected model is on.')
|
||||
))->addSubcommand('all', array(
|
||||
'help' => __('Bake all CRUD action views for all controllers. Requires models and controllers to exist.')
|
||||
))->epilog(__('Omitting all arguments and options will enter into an interactive mode.'));
|
||||
'help' => __d('cake_console', 'Bake all CRUD action views for all controllers. Requires models and controllers to exist.')
|
||||
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -455,7 +458,7 @@ class ViewTask extends BakeTask {
|
|||
* @return array $associations
|
||||
* @access private
|
||||
*/
|
||||
private function __associations(&$model) {
|
||||
private function __associations($model) {
|
||||
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
$associations = array();
|
||||
|
|
@ -18,7 +18,13 @@
|
|||
* @since CakePHP(tm) v 1.2.0.4433
|
||||
* @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.
|
||||
|
@ -38,111 +44,113 @@ class TestSuiteShell extends Shell {
|
|||
'The CakePHP Testsuite allows you to run test cases from the command line',
|
||||
'If run with no command line arguments, a list of available core test cases will be shown'
|
||||
))->addArgument('category', array(
|
||||
'help' => __('app, core or name of a plugin.'),
|
||||
'help' => __d('cake_console', 'app, core or name of a plugin.'),
|
||||
'required' => true
|
||||
))->addArgument('file', array(
|
||||
'help' => __('file name with folder prefix and without the test.php suffix.'),
|
||||
'help' => __d('cake_console', 'file name with folder prefix and without the test.php suffix.'),
|
||||
'required' => false,
|
||||
))->addOption('log-junit', array(
|
||||
'help' => __('<file> Log test execution in JUnit XML format to file.'),
|
||||
'help' => __d('cake_console', '<file> Log test execution in JUnit XML format to file.'),
|
||||
'default' => false
|
||||
))->addOption('log-json', array(
|
||||
'help' => __('<file> Log test execution in TAP format to file.'),
|
||||
'help' => __d('cake_console', '<file> Log test execution in TAP format to file.'),
|
||||
'default' => false
|
||||
))->addOption('log-tap', array(
|
||||
'help' => __('<file> Log test execution in TAP format to file.'),
|
||||
'help' => __d('cake_console', '<file> Log test execution in TAP format to file.'),
|
||||
'default' => false
|
||||
))->addOption('log-dbus', array(
|
||||
'help' => __('Log test execution to DBUS.'),
|
||||
'help' => __d('cake_console', 'Log test execution to DBUS.'),
|
||||
'default' => false
|
||||
))->addOption('coverage-html', array(
|
||||
'help' => __('<dir> Generate code coverage report in HTML format.'),
|
||||
'help' => __d('cake_console', '<dir> Generate code coverage report in HTML format.'),
|
||||
'default' => false
|
||||
))->addOption('coverage-clover', array(
|
||||
'help' => __('<file> Write code coverage data in Clover XML format.'),
|
||||
'help' => __d('cake_console', '<file> Write code coverage data in Clover XML format.'),
|
||||
'default' => false
|
||||
))->addOption('testdox-html', array(
|
||||
'help' => __('<file> Write agile documentation in HTML format to file.'),
|
||||
'help' => __d('cake_console', '<file> Write agile documentation in HTML format to file.'),
|
||||
'default' => false
|
||||
))->addOption('testdox-text', array(
|
||||
'help' => __('<file> Write agile documentation in Text format to file.'),
|
||||
'help' => __d('cake_console', '<file> Write agile documentation in Text format to file.'),
|
||||
'default' => false
|
||||
))->addOption('filter', array(
|
||||
'help' => __('<pattern> Filter which tests to run.'),
|
||||
'help' => __d('cake_console', '<pattern> Filter which tests to run.'),
|
||||
'default' => false
|
||||
))->addOption('group', array(
|
||||
'help' => __('<name> Only runs tests from the specified group(s).'),
|
||||
'help' => __d('cake_console', '<name> Only runs tests from the specified group(s).'),
|
||||
'default' => false
|
||||
))->addOption('exclude-group', array(
|
||||
'help' => __('<name> Exclude tests from the specified group(s).'),
|
||||
'help' => __d('cake_console', '<name> Exclude tests from the specified group(s).'),
|
||||
'default' => false
|
||||
))->addOption('list-groups', array(
|
||||
'help' => __('List available test groups.'),
|
||||
'help' => __d('cake_console', 'List available test groups.'),
|
||||
'boolean' => true
|
||||
))->addOption('loader', array(
|
||||
'help' => __('TestSuiteLoader implementation to use.'),
|
||||
'help' => __d('cake_console', 'TestSuiteLoader implementation to use.'),
|
||||
'default' => false
|
||||
))->addOption('repeat', array(
|
||||
'help' => __('<times> Runs the test(s) repeatedly.'),
|
||||
'help' => __d('cake_console', '<times> Runs the test(s) repeatedly.'),
|
||||
'default' => false
|
||||
))->addOption('tap', array(
|
||||
'help' => __('Report test execution progress in TAP format.'),
|
||||
'help' => __d('cake_console', 'Report test execution progress in TAP format.'),
|
||||
'boolean' => true
|
||||
))->addOption('testdox', array(
|
||||
'help' => __('Report test execution progress in TestDox format.'),
|
||||
'help' => __d('cake_console', 'Report test execution progress in TestDox format.'),
|
||||
'default' => false,
|
||||
'boolean' => true
|
||||
))->addOption('no-colors', array(
|
||||
'help' => __('Do not use colors in output.'),
|
||||
'help' => __d('cake_console', 'Do not use colors in output.'),
|
||||
'boolean' => true
|
||||
))->addOption('stderr', array(
|
||||
'help' => __('Write to STDERR instead of STDOUT.'),
|
||||
'help' => __d('cake_console', 'Write to STDERR instead of STDOUT.'),
|
||||
'boolean' => true
|
||||
))->addOption('stop-on-error', array(
|
||||
'help' => __('Stop execution upon first error or failure.'),
|
||||
'help' => __d('cake_console', 'Stop execution upon first error or failure.'),
|
||||
'boolean' => true
|
||||
))->addOption('stop-on-failure', array(
|
||||
'help' => __('Stop execution upon first failure.'),
|
||||
'help' => __d('cake_console', 'Stop execution upon first failure.'),
|
||||
'boolean' => true
|
||||
))->addOption('stop-on-skipped ', array(
|
||||
'help' => __('Stop execution upon first skipped test.'),
|
||||
'help' => __d('cake_console', 'Stop execution upon first skipped test.'),
|
||||
'boolean' => true
|
||||
))->addOption('stop-on-incomplete', array(
|
||||
'help' => __('Stop execution upon first incomplete test.'),
|
||||
'help' => __d('cake_console', 'Stop execution upon first incomplete test.'),
|
||||
'boolean' => true
|
||||
))->addOption('strict', array(
|
||||
'help' => __('Mark a test as incomplete if no assertions are made.'),
|
||||
'help' => __d('cake_console', 'Mark a test as incomplete if no assertions are made.'),
|
||||
'boolean' => true
|
||||
))->addOption('wait', array(
|
||||
'help' => __('Waits for a keystroke after each test.'),
|
||||
'help' => __d('cake_console', 'Waits for a keystroke after each test.'),
|
||||
'boolean' => true
|
||||
))->addOption('process-isolation', array(
|
||||
'help' => __('Run each test in a separate PHP process.'),
|
||||
'help' => __d('cake_console', 'Run each test in a separate PHP process.'),
|
||||
'boolean' => true
|
||||
))->addOption('no-globals-backup', array(
|
||||
'help' => __('Do not backup and restore $GLOBALS for each test.'),
|
||||
'help' => __d('cake_console', 'Do not backup and restore $GLOBALS for each test.'),
|
||||
'boolean' => true
|
||||
))->addOption('static-backup ', array(
|
||||
'help' => __('Backup and restore static attributes for each test.'),
|
||||
'help' => __d('cake_console', 'Backup and restore static attributes for each test.'),
|
||||
'boolean' => true
|
||||
))->addOption('syntax-check', array(
|
||||
'help' => __('Try to check source files for syntax errors.'),
|
||||
'help' => __d('cake_console', 'Try to check source files for syntax errors.'),
|
||||
'boolean' => true
|
||||
))->addOption('bootstrap', array(
|
||||
'help' => __('<file> A "bootstrap" PHP file that is run before the tests.'),
|
||||
'help' => __d('cake_console', '<file> A "bootstrap" PHP file that is run before the tests.'),
|
||||
'default' => false
|
||||
))->addOption('configuraion', array(
|
||||
'help' => __('<file> Read configuration from XML file.'),
|
||||
))->addOption('configuration', array(
|
||||
'help' => __d('cake_console', '<file> Read configuration from XML file.'),
|
||||
'default' => false
|
||||
))->addOption('no-configuration', array(
|
||||
'help' => __('Ignore default configuration file (phpunit.xml).'),
|
||||
'help' => __d('cake_console', 'Ignore default configuration file (phpunit.xml).'),
|
||||
'boolean' => true
|
||||
))->addOption('include-path', array(
|
||||
'help' => __('<path(s)> Prepend PHP include_path with given path(s).'),
|
||||
'help' => __d('cake_console', '<path(s)> Prepend PHP include_path with given path(s).'),
|
||||
'default' => false
|
||||
))->addOption('directive', array(
|
||||
'help' => __('key[=value] Sets a php.ini value.'),
|
||||
'help' => __d('cake_console', 'key[=value] Sets a php.ini value.'),
|
||||
'default' => false
|
||||
))->addOption('fixture', array(
|
||||
'help' => __d('cake_console', 'Choose a custom fixture manager.'),
|
||||
));
|
||||
|
||||
return $parser;
|
||||
|
@ -154,18 +162,8 @@ class TestSuiteShell extends Shell {
|
|||
* @return void
|
||||
*/
|
||||
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->loadTestFramework();
|
||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,6 +176,7 @@ class TestSuiteShell extends Shell {
|
|||
return;
|
||||
}
|
||||
$params = array(
|
||||
'core' => false,
|
||||
'app' => false,
|
||||
'plugin' => null,
|
||||
'output' => 'text',
|
||||
|
@ -185,14 +184,16 @@ class TestSuiteShell extends Shell {
|
|||
|
||||
$category = $this->args[0];
|
||||
|
||||
if ($category == 'app') {
|
||||
if ($category == 'core') {
|
||||
$params['core'] = true;
|
||||
} elseif ($category == 'app') {
|
||||
$params['app'] = true;
|
||||
} elseif ($category != 'core') {
|
||||
$params['plugin'] = $category;
|
||||
}
|
||||
|
||||
if (isset($this->args[1])) {
|
||||
$params['case'] = Inflector::underscore($this->args[1]);
|
||||
$params['case'] = $this->args[1];
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
@ -231,7 +232,7 @@ class TestSuiteShell extends Shell {
|
|||
* @return void
|
||||
*/
|
||||
public function main() {
|
||||
$this->out(__('CakePHP Test Shell'));
|
||||
$this->out(__d('cake_console', 'CakePHP Test Shell'));
|
||||
$this->hr();
|
||||
|
||||
$args = $this->parseArgs();
|
||||
|
@ -251,12 +252,10 @@ class TestSuiteShell extends Shell {
|
|||
* @return void
|
||||
*/
|
||||
protected function run($runnerArgs, $options = array()) {
|
||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_runner.php';
|
||||
|
||||
restore_error_handler();
|
||||
restore_error_handler();
|
||||
|
||||
$testCli = new TestRunner($runnerArgs);
|
||||
$testCli = new CakeTestSuiteCommand('CakeTestLoader', $runnerArgs);
|
||||
$testCli->run($options);
|
||||
}
|
||||
|
||||
|
@ -267,7 +266,7 @@ class TestSuiteShell extends Shell {
|
|||
*/
|
||||
public function available() {
|
||||
$params = $this->parseArgs();
|
||||
$testCases = TestManager::getTestCaseList($params);
|
||||
$testCases = CakeTestLoader::generateTestList($params);
|
||||
$app = $params['app'];
|
||||
$plugin = $params['plugin'];
|
||||
|
||||
|
@ -282,7 +281,7 @@ class TestSuiteShell extends Shell {
|
|||
}
|
||||
|
||||
if (empty($testCases)) {
|
||||
$this->out(__("No test cases available \n\n"));
|
||||
$this->out(__d('cake_console', "No test cases available \n\n"));
|
||||
return $this->out($this->OptionParser->help());
|
||||
}
|
||||
|
||||
|
@ -290,15 +289,15 @@ class TestSuiteShell extends Shell {
|
|||
$i = 1;
|
||||
$cases = array();
|
||||
foreach ($testCases as $testCaseFile => $testCase) {
|
||||
$case = explode(DS, str_replace('.test.php', '', $testCase));
|
||||
$case[count($case) - 1] = Inflector::camelize($case[count($case) - 1]);
|
||||
$case = explode(DS, str_replace('Test.php', '', $testCase));
|
||||
$case[count($case) - 1] = $case[count($case) - 1];
|
||||
$case = implode('/', $case);
|
||||
$this->out("[$i] $case");
|
||||
$cases[$i] = $case;
|
||||
$i++;
|
||||
}
|
||||
|
||||
while ($choice = $this->in(__('What test case would you like to run?'), null, 'q')) {
|
||||
while ($choice = $this->in(__d('cake_console', 'What test case would you like to run?'), null, 'q')) {
|
||||
if (is_numeric($choice) && isset($cases[$choice])) {
|
||||
$this->args[0] = $category;
|
||||
$this->args[1] = $cases[$choice];
|
|
@ -16,8 +16,9 @@
|
|||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'ErrorHandler');
|
||||
require_once 'console_output.php';
|
||||
App::uses('ErrorHandler', 'Error');
|
||||
App::uses('ConsoleOutput', 'Console');
|
||||
App::uses('CakeLog', 'Log');
|
||||
|
||||
/**
|
||||
* Error Handler for Cake console. Does simple printing of the
|
||||
|
@ -57,7 +58,7 @@ class ConsoleErrorHandler extends ErrorHandler {
|
|||
public static function handleException(Exception $exception) {
|
||||
$stderr = self::getStderr();
|
||||
$stderr->write(sprintf(
|
||||
__("<error>Error:</error> %s\n%s"),
|
||||
__d('cake_console', "<error>Error:</error> %s\n%s"),
|
||||
$exception->getMessage(),
|
||||
$exception->getTraceAsString()
|
||||
));
|
||||
|
@ -79,11 +80,10 @@ class ConsoleErrorHandler extends ErrorHandler {
|
|||
}
|
||||
$stderr = self::getStderr();
|
||||
list($name, $log) = self::_mapErrorCode($code);
|
||||
$message = __('%s in [%s, line %s]', $description, $file, $line);
|
||||
$stderr->write(__("<error>%s Error:</error> %s\n", $name, $message));
|
||||
$message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line);
|
||||
$stderr->write(__d('cake_console', "<error>%s Error:</error> %s\n", $name, $message));
|
||||
|
||||
if (Configure::read('debug') == 0) {
|
||||
App::import('Core', 'CakeLog');
|
||||
CakeLog::write($log, $message);
|
||||
}
|
||||
}
|
|
@ -95,10 +95,10 @@ class ConsoleInputArgument {
|
|||
}
|
||||
$optional = '';
|
||||
if (!$this->isRequired()) {
|
||||
$optional = __(' <comment>(optional)</comment>');
|
||||
$optional = __d('cake_console', ' <comment>(optional)</comment>');
|
||||
}
|
||||
if (!empty($this->_choices)) {
|
||||
$optional .= __(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
|
||||
$optional .= __d('cake_console', ' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
|
||||
}
|
||||
return sprintf('%s%s%s', $name, $this->_help, $optional);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ class ConsoleInputArgument {
|
|||
}
|
||||
if (!in_array($value, $this->_choices)) {
|
||||
throw new ConsoleException(sprintf(
|
||||
__('"%s" is not a valid value for %s. Please use one of "%s"'),
|
||||
__d('cake_console', '"%s" is not a valid value for %s. Please use one of "%s"'),
|
||||
$value, $this->_name, implode(', ', $this->_choices)
|
||||
));
|
||||
}
|
|
@ -119,10 +119,10 @@ class ConsoleInputOption {
|
|||
public function help($width = 0) {
|
||||
$default = $short = '';
|
||||
if (!empty($this->_default) && $this->_default !== true) {
|
||||
$default = __(' <comment>(default: %s)</comment>', $this->_default);
|
||||
$default = __d('cake_console', ' <comment>(default: %s)</comment>', $this->_default);
|
||||
}
|
||||
if (!empty($this->_choices)) {
|
||||
$default .= __(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
|
||||
$default .= __d('cake_console', ' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
|
||||
}
|
||||
if (!empty($this->_short)) {
|
||||
$short = ', -' . $this->_short;
|
||||
|
@ -180,7 +180,7 @@ class ConsoleInputOption {
|
|||
}
|
||||
if (!in_array($value, $this->_choices)) {
|
||||
throw new ConsoleException(sprintf(
|
||||
__('"%s" is not a valid value for --%s. Please use one of "%s"'),
|
||||
__d('cake_console', '"%s" is not a valid value for --%s. Please use one of "%s"'),
|
||||
$value, $this->_name, implode(', ', $this->_choices)
|
||||
));
|
||||
}
|
|
@ -16,10 +16,15 @@
|
|||
* @since CakePHP(tm) v 2.0
|
||||
* @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';
|
||||
require_once CONSOLE_LIBS . 'console_input_subcommand.php';
|
||||
require_once CONSOLE_LIBS . 'help_formatter.php';
|
||||
|
||||
App::uses('TaskCollection', 'Console');
|
||||
App::uses('ConsoleOutput', 'Console');
|
||||
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
|
||||
|
@ -129,11 +134,11 @@ class ConsoleOptionParser {
|
|||
if ($defaultOptions) {
|
||||
$this->addOption('verbose', array(
|
||||
'short' => 'v',
|
||||
'help' => __('Enable verbose output.'),
|
||||
'help' => __d('cake_console', 'Enable verbose output.'),
|
||||
'boolean' => true
|
||||
))->addOption('quiet', array(
|
||||
'short' => 'q',
|
||||
'help' => __('Enable quiet output.'),
|
||||
'help' => __d('cake_console', 'Enable quiet output.'),
|
||||
'boolean' => true
|
||||
));
|
||||
}
|
||||
|
@ -456,7 +461,7 @@ class ConsoleOptionParser {
|
|||
foreach ($this->_args as $i => $arg) {
|
||||
if ($arg->isRequired() && !isset($args[$i]) && empty($params['help'])) {
|
||||
throw new ConsoleException(
|
||||
__('Missing required arguments. %s is required.', $arg->name())
|
||||
__d('cake_console', 'Missing required arguments. %s is required.', $arg->name())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -550,7 +555,7 @@ class ConsoleOptionParser {
|
|||
*/
|
||||
protected function _parseOption($name, $params) {
|
||||
if (!isset($this->_options[$name])) {
|
||||
throw new ConsoleException(__('Unknown option `%s`', $name));
|
||||
throw new ConsoleException(__d('cake_console', 'Unknown option `%s`', $name));
|
||||
}
|
||||
$option = $this->_options[$name];
|
||||
$isBoolean = $option->isBoolean();
|
||||
|
@ -584,7 +589,7 @@ class ConsoleOptionParser {
|
|||
}
|
||||
$next = count($args);
|
||||
if (!isset($this->_args[$next])) {
|
||||
throw new ConsoleException(__('Too many arguments.'));
|
||||
throw new ConsoleException(__d('cake_console', 'Too many arguments.'));
|
||||
}
|
||||
|
||||
if ($this->_args[$next]->validChoice($argument)) {
|
|
@ -14,7 +14,7 @@
|
|||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @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
|
||||
|
@ -69,7 +69,7 @@ class HelpFormatter {
|
|||
}
|
||||
$out[] = '';
|
||||
$out[] = sprintf(
|
||||
__('To see help on a subcommand use <info>`cake %s [subcommand] --help`</info>'),
|
||||
__d('cake_console', 'To see help on a subcommand use <info>`cake %s [subcommand] --help`</info>'),
|
||||
$parser->command()
|
||||
);
|
||||
$out[] = '';
|
|
@ -16,10 +16,13 @@
|
|||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @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';
|
||||
require_once CONSOLE_LIBS . 'console_input.php';
|
||||
require_once CONSOLE_LIBS . 'console_option_parser.php';
|
||||
|
||||
App::uses('TaskCollection', 'Console');
|
||||
App::uses('ConsoleOutput', 'Console');
|
||||
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.
|
||||
|
@ -557,7 +560,7 @@ class Shell extends Object {
|
|||
* @param string $message An optional error message
|
||||
*/
|
||||
public function error($title, $message = null) {
|
||||
$this->err(__('<error>Error:</error> %s', $title));
|
||||
$this->err(__d('cake_console', '<error>Error:</error> %s', $title));
|
||||
|
||||
if (!empty($message)) {
|
||||
$this->err($message);
|
||||
|
@ -593,31 +596,27 @@ class Shell extends Object {
|
|||
$this->out();
|
||||
|
||||
if (is_file($path) && $this->interactive === true) {
|
||||
$this->out(__('<warning>File `%s` exists</warning>', $path));
|
||||
$key = $this->in(__('Do you want to overwrite?'), array('y', 'n', 'q'), 'n');
|
||||
$this->out(__d('cake_console', '<warning>File `%s` exists</warning>', $path));
|
||||
$key = $this->in(__d('cake_console', 'Do you want to overwrite?'), array('y', 'n', 'q'), 'n');
|
||||
|
||||
if (strtolower($key) == 'q') {
|
||||
$this->out(__('<error>Quitting</error>.'), 2);
|
||||
$this->out(__d('cake_console', '<error>Quitting</error>.'), 2);
|
||||
$this->_stop();
|
||||
} elseif (strtolower($key) != 'y') {
|
||||
$this->out(__('Skip `%s`', $path), 2);
|
||||
$this->out(__d('cake_console', 'Skip `%s`', $path), 2);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->out(__('Creating file %s', $path));
|
||||
}
|
||||
|
||||
if (!class_exists('File')) {
|
||||
require LIBS . 'file.php';
|
||||
$this->out(__d('cake_console', 'Creating file %s', $path));
|
||||
}
|
||||
|
||||
if ($File = new File($path, true)) {
|
||||
$data = $File->prepare($contents);
|
||||
$File->write($data);
|
||||
$this->out(__('<success>Wrote</success> `%s`', $path));
|
||||
$this->out(__d('cake_console', '<success>Wrote</success> `%s`', $path));
|
||||
return true;
|
||||
} else {
|
||||
$this->err(__('<error>Could not write to `%s`</error>.', $path), 2);
|
||||
$this->err(__d('cake_console', '<error>Could not write to `%s`</error>.', $path), 2);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -628,7 +627,10 @@ class Shell extends Object {
|
|||
* @return boolean Success
|
||||
*/
|
||||
protected function _checkUnitTest() {
|
||||
if (App::import('vendor', 'simpletest' . DS . 'simpletest')) {
|
||||
if (App::import('Vendor', 'phpunit', array('file' => 'PHPUnit' . DS . 'Autoload.php'))) {
|
||||
return true;
|
||||
}
|
||||
if (@include 'PHPUnit' . DS . 'Autoload.php') {
|
||||
return true;
|
||||
}
|
||||
$prompt = 'PHPUnit is not installed. Do you want to bake unit test files anyway?';
|
||||
|
@ -661,7 +663,7 @@ class Shell extends Object {
|
|||
* @return string Path to controller
|
||||
*/
|
||||
protected function _controllerPath($name) {
|
||||
return strtolower(Inflector::underscore($name));
|
||||
return Inflector::underscore($name);
|
||||
}
|
||||
|
||||
/**
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue