Merge branch '1.3' of dev@code.cakephp.org:cakephp into 1.3

This commit is contained in:
nate 2009-07-31 11:54:01 -04:00
commit e47b1960ad
476 changed files with 28716 additions and 15566 deletions

View file

@ -20,22 +20,27 @@
* @since CakePHP(tm) v 0.10.8.2117
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* 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)
*
* $modelPaths = array('/full/path/to/models/', '/next/full/path/to/models/');
* $viewPaths = array('/full/path/to/views/', '/next/full/path/to/views/');
* $controllerPaths = array(/full/path/to/controllers/', '/next/full/path/to/controllers/');
* $pluginPaths = array('/full/path/to/plugins/', '/next/full/path/to/plugins/');
* $behaviorPaths = array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/');
* $componentPaths = array('/full/path/to/components/', '/next/full/path/to/components/');
* $helperPaths = array('/full/path/to/helpers/', '/next/full/path/to/helpers/');
* $vendorPaths = array('/full/path/to/vendors/', '/next/full/path/to/vendors/');
* $shellPaths = array('/full/path/to/shells/', '/next/full/path/to/shells/');
* $localePaths = array('/full/path/to/locale/', '/next/full/path/to/locale/';
* App::build(array(
* 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
* 'models' => array('/full/path/to/models/', '/next/full/path/to/models/'),
* 'views' => array('/full/path/to/views/', '/next/full/path/to/views/'),
* 'controllers' => array(/full/path/to/controllers/', '/next/full/path/to/controllers/'),
* 'datasources' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
* 'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
* 'components' => array('/full/path/to/components/', '/next/full/path/to/components/'),
* 'helpers' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'),
* 'vendors' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'),
* 'shells' => array('/full/path/to/shells/', '/next/full/path/to/shells/'),
* 'locales' => array('/full/path/to/locale/', '/next/full/path/to/locale/')
* ));
*
*/
/**
* As of 1.3, additional rules for the inflector are added below
*

View file

@ -93,7 +93,7 @@ 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 = Configure::corePaths('cake');
$corePath = App::core('cake');
if (isset($corePath[0])) {
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
} else {

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Basic Cake functionality.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Basic defines for timing functions.
*/
@ -34,6 +36,7 @@
define('WEEK', 7 * DAY);
define('MONTH', 30 * DAY);
define('YEAR', 365 * DAY);
/**
* Patch for PHP < 5.0
*/
@ -46,6 +49,7 @@ if (!function_exists('clone')) {
}');
}
}
/**
* Loads configuration files. Receives a set of configuration files
* to load.
@ -75,6 +79,7 @@ if (!function_exists('clone')) {
}
return true;
}
/**
* Loads component/components from LIBS. Takes optional number of parameters.
*
@ -91,6 +96,7 @@ if (!function_exists('clone')) {
require_once(LIBS . strtolower($file) . '.php');
}
}
/**
* Prints out debug information about given variable.
*
@ -118,6 +124,7 @@ if (!function_exists('clone')) {
}
}
if (!function_exists('getMicrotime')) {
/**
* Returns microtime for execution time checking
*
@ -129,6 +136,7 @@ if (!function_exists('getMicrotime')) {
}
}
if (!function_exists('sortByKey')) {
/**
* Sorts given $array by key $sortby.
*
@ -160,6 +168,7 @@ if (!function_exists('sortByKey')) {
}
}
if (!function_exists('array_combine')) {
/**
* Combines given identical arrays by using the first array's values as keys,
* and the second one's values as values. (Implemented for backwards compatibility with PHP4)
@ -188,6 +197,7 @@ if (!function_exists('array_combine')) {
return $output;
}
}
/**
* Convenience method for htmlspecialchars.
*
@ -208,6 +218,7 @@ if (!function_exists('array_combine')) {
}
return htmlspecialchars($text, ENT_QUOTES, $charset);
}
/**
* Returns an array of all the given parameters.
*
@ -228,6 +239,7 @@ if (!function_exists('array_combine')) {
$args = func_get_args();
return $args;
}
/**
* Constructs associative array from pairs of arguments.
*
@ -257,6 +269,7 @@ if (!function_exists('array_combine')) {
}
return $a;
}
/**
* Convenience method for echo().
*
@ -266,6 +279,7 @@ if (!function_exists('array_combine')) {
function e($text) {
echo $text;
}
/**
* Convenience method for strtolower().
*
@ -276,6 +290,7 @@ if (!function_exists('array_combine')) {
function low($str) {
return strtolower($str);
}
/**
* Convenience method for strtoupper().
*
@ -286,6 +301,7 @@ if (!function_exists('array_combine')) {
function up($str) {
return strtoupper($str);
}
/**
* Convenience method for str_replace().
*
@ -298,6 +314,7 @@ if (!function_exists('array_combine')) {
function r($search, $replace, $subject) {
return str_replace($search, $replace, $subject);
}
/**
* Print_r convenience function, which prints out <PRE> tags around
* the output of given array. Similar to debug().
@ -314,6 +331,7 @@ if (!function_exists('array_combine')) {
echo '</pre>';
}
}
/**
* Display parameters.
*
@ -329,6 +347,7 @@ if (!function_exists('array_combine')) {
}
return $p;
}
/**
* Merge a group of arrays
*
@ -350,6 +369,7 @@ if (!function_exists('array_combine')) {
}
return $r;
}
/**
* Gets an environment variable from available sources, and provides emulation
* for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on
@ -362,8 +382,8 @@ if (!function_exists('array_combine')) {
*/
function env($key) {
if ($key == 'HTTPS') {
if (isset($_SERVER) && !empty($_SERVER)) {
return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
if (isset($_SERVER['HTTPS'])) {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
}
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
}
@ -426,6 +446,7 @@ if (!function_exists('array_combine')) {
return null;
}
if (!function_exists('file_put_contents')) {
/**
* Writes data into file.
*
@ -453,6 +474,7 @@ if (!function_exists('file_put_contents')) {
return false;
}
}
/**
* Reads/writes temporary data to cache files or session.
*
@ -504,6 +526,7 @@ if (!function_exists('file_put_contents')) {
}
return $data;
}
/**
* Used to delete files in the cache directories, or clear contents of cache directories
*
@ -566,6 +589,7 @@ if (!function_exists('file_put_contents')) {
}
return false;
}
/**
* Recursively strips slashes from all values in an array
*
@ -583,6 +607,7 @@ if (!function_exists('file_put_contents')) {
}
return $values;
}
/**
* Returns a translated string if one is found; Otherwise, the submitted message.
*
@ -605,6 +630,7 @@ if (!function_exists('file_put_contents')) {
return I18n::translate($singular);
}
}
/**
* Returns correct plural form of message identified by $singular and $plural for count $count.
* Some languages have more than one form for plural messages dependent on the count.
@ -624,11 +650,12 @@ if (!function_exists('file_put_contents')) {
}
if ($return === false) {
echo I18n::translate($singular, $plural, null, 5, $count);
echo I18n::translate($singular, $plural, null, 6, $count);
} else {
return I18n::translate($singular, $plural, null, 5, $count);
return I18n::translate($singular, $plural, null, 6, $count);
}
}
/**
* Allows you to override the current domain for a single message lookup.
*
@ -651,6 +678,7 @@ if (!function_exists('file_put_contents')) {
return I18n::translate($msg, null, $domain);
}
}
/**
* Allows you to override the current domain for a single plural message lookup.
* Returns correct plural form of message identified by $singular and $plural for count $count
@ -672,11 +700,12 @@ if (!function_exists('file_put_contents')) {
}
if ($return === false) {
echo I18n::translate($singular, $plural, $domain, 5, $count);
echo I18n::translate($singular, $plural, $domain, 6, $count);
} else {
return I18n::translate($singular, $plural, $domain, 5, $count);
return I18n::translate($singular, $plural, $domain, 6, $count);
}
}
/**
* Allows you to override the current domain for a single message lookup.
* It also allows you to specify a category.
@ -713,6 +742,7 @@ if (!function_exists('file_put_contents')) {
return I18n::translate($msg, null, $domain, $category);
}
}
/**
* Allows you to override the current domain for a single plural message lookup.
* It also allows you to specify a category.
@ -723,13 +753,13 @@ if (!function_exists('file_put_contents')) {
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
* LC_CTYPE 0
* LC_NUMERIC 1
* LC_TIME 2
* LC_COLLATE 3
* LC_MONETARY 4
* LC_MESSAGES 5
* LC_ALL 6
* LC_ALL 0
* LC_COLLATE 1
* LC_CTYPE 2
* LC_MONETARY 3
* LC_NUMERIC 4
* LC_TIME 5
* LC_MESSAGES 6
*
* @param string $domain Domain
* @param string $singular Singular string to translate
@ -753,6 +783,7 @@ if (!function_exists('file_put_contents')) {
return I18n::translate($singular, $plural, $domain, $category, $count);
}
}
/**
* The category argument allows a specific category of the locale settings to be used for fetching a message.
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
@ -785,6 +816,7 @@ if (!function_exists('file_put_contents')) {
return I18n::translate($msg, null, null, $category);
}
}
/**
* Computes the difference of arrays using keys for comparison.
*
@ -819,6 +851,7 @@ if (!function_exists('file_put_contents')) {
return $valuesDiff;
}
}
/**
* Computes the intersection of arrays using keys for comparison
*
@ -837,6 +870,7 @@ if (!function_exists('file_put_contents')) {
return $res;
}
}
/**
* Shortcut to Log::write.
*
@ -850,6 +884,7 @@ if (!function_exists('file_put_contents')) {
$good = ' ';
CakeLog::write('error', str_replace($bad, $good, $message));
}
/**
* Searches include path for files.
*
@ -870,6 +905,7 @@ if (!function_exists('file_put_contents')) {
}
return false;
}
/**
* Convert forward slashes to underscores and removes first and last underscores in a string
*
@ -883,6 +919,7 @@ if (!function_exists('file_put_contents')) {
$string = str_replace('/', '_', $string);
return $string;
}
/**
* Implements http_build_query for PHP4.
*
@ -922,6 +959,7 @@ if (!function_exists('file_put_contents')) {
return implode($argSep, $out);
}
}
/**
* Wraps ternary operations. If $condition is a non-empty value, $val1 is returned, otherwise $val2.
* Don't use for isset() conditions, or wrap your variable with @ operator:

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* If the index.php file is used instead of an .htaccess file
* or if the user can not set the web root to use the public
@ -36,92 +38,112 @@
if (!defined('WEBROOT_DIR')) {
define('WEBROOT_DIR', 'webroot');
}
/**
* Path to the cake directory.
*/
define('CAKE', CORE_PATH.'cake'.DS);
/**
* Path to the application's directory.
*/
if (!defined('APP')) {
define('APP', ROOT.DS.APP_DIR.DS);
}
/**
* Path to the application's models directory.
*/
define('MODELS', APP.'models'.DS);
/**
* Path to model behaviors directory.
*/
define('BEHAVIORS', MODELS.'behaviors'.DS);
/**
* Path to the application's controllers directory.
*/
define('CONTROLLERS', APP.'controllers'.DS);
/**
* Path to the application's components directory.
*/
define('COMPONENTS', CONTROLLERS.'components'.DS);
/**
* Path to the application's views directory.
*/
define('VIEWS', APP.'views'.DS);
/**
* Path to the application's helpers directory.
*/
define('HELPERS', VIEWS.'helpers'.DS);
/**
* Path to the application's view's layouts directory.
*/
define('LAYOUTS', VIEWS.'layouts'.DS);
/**
* Path to the application's view's elements directory.
* It's supposed to hold pieces of PHP/HTML that are used on multiple pages
* and are not linked to a particular layout (like polls, footers and so on).
*/
define('ELEMENTS', VIEWS.'elements'.DS);
/**
* Path to the configuration files directory.
*/
if (!defined('CONFIGS')) {
define('CONFIGS', APP.'config'.DS);
}
/**
* Path to the libs directory.
*/
define('INFLECTIONS', CAKE.'config'.DS.'inflections'.DS);
/**
* Path to the libs directory.
*/
define('LIBS', CAKE.'libs'.DS);
/**
* Path to the public CSS directory.
*/
define('CSS', WWW_ROOT.'css'.DS);
/**
* Path to the public JavaScript directory.
*/
define('JS', WWW_ROOT.'js'.DS);
/**
* Path to the public images directory.
*/
define('IMAGES', WWW_ROOT.'img'.DS);
/**
* Path to the console libs direcotry.
*/
define('CONSOLE_LIBS', CAKE.'console'.DS.'libs'.DS);
/**
* Path to the tests directory.
*/
if (!defined('TESTS')) {
define('TESTS', APP.'tests'.DS);
}
/**
* Path to the core tests directory.
*/
if (!defined('CAKE_TESTS')) {
define('CAKE_TESTS', CAKE.'tests'.DS);
}
/**
* Path to the test suite.
*/
@ -131,48 +153,58 @@ if (!defined('CAKE_TESTS')) {
* Path to the controller test directory.
*/
define('CONTROLLER_TESTS', TESTS.'cases'.DS.'controllers'.DS);
/**
* Path to the components test directory.
*/
define('COMPONENT_TESTS', TESTS.'cases'.DS.'components'.DS);
/**
* Path to the helpers test directory.
*/
define('HELPER_TESTS', TESTS.'cases'.DS.'views'.DS.'helpers'.DS);
/**
* Path to the models' test directory.
*/
define('MODEL_TESTS', TESTS.'cases'.DS.'models'.DS);
/**
* Path to the lib test directory.
*/
define('LIB_TESTS', CAKE_TESTS.'cases'.DS.'lib'.DS);
/**
* Path to the temporary files directory.
*/
if (!defined('TMP')) {
define('TMP', APP.'tmp'.DS);
}
/**
* Path to the logs directory.
*/
define('LOGS', TMP.'logs'.DS);
/**
* Path to the cache files directory. It can be shared between hosts in a multi-server setup.
*/
define('CACHE', TMP.'cache'.DS);
/**
* Path to the vendors directory.
*/
if (!defined('VENDORS')) {
define('VENDORS', CAKE_CORE_INCLUDE_PATH.DS.'vendors'.DS);
}
/**
* Path to the Pear directory
* The purporse is to make it easy porting Pear libs into Cake
* without setting the include_path PHP variable.
*/
define('PEAR', VENDORS.'Pear'.DS);
/**
* Full url prefix
*/
@ -189,18 +221,21 @@ if (!defined('FULL_BASE_URL')) {
}
unset($httpHost, $s);
}
/**
* Web path to the public images directory.
*/
if (!defined('IMAGES_URL')) {
define('IMAGES_URL', 'img/');
}
/**
* Web path to the CSS files directory.
*/
if (!defined('CSS_URL')) {
define('CSS_URL', 'css/');
}
/**
* Web path to the js files directory.
*/

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Case Folding Properties.
*
@ -28,6 +29,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* The upper field is the decimal value of the upper case character
*

View file

@ -22,8 +22,6 @@
# @license http://www.opensource.org/licenses/mit-license.php The MIT License
#
################################################################################
clear
LIB=${0/%cake/}
APP=`pwd`

View file

@ -1,6 +1,7 @@
#!/usr/bin/php -q
<?php
/* SVN FILE: $Id$ */
/**
* Command-line code generation utility to automate programmer chores.
*
@ -25,6 +26,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Shell dispatcher
*
@ -32,6 +34,7 @@
* @subpackage cake.cake.console
*/
class ShellDispatcher {
/**
* Standard input stream.
*
@ -39,6 +42,7 @@ class ShellDispatcher {
* @access public
*/
var $stdin;
/**
* Standard output stream.
*
@ -46,6 +50,7 @@ class ShellDispatcher {
* @access public
*/
var $stdout;
/**
* Standard error stream.
*
@ -53,6 +58,7 @@ class ShellDispatcher {
* @access public
*/
var $stderr;
/**
* Contains command switches parsed from the command line.
*
@ -60,6 +66,7 @@ class ShellDispatcher {
* @access public
*/
var $params = array();
/**
* Contains arguments parsed from the command line.
*
@ -67,6 +74,7 @@ class ShellDispatcher {
* @access public
*/
var $args = array();
/**
* The file name of the shell that was invoked.
*
@ -74,6 +82,7 @@ class ShellDispatcher {
* @access public
*/
var $shell = null;
/**
* The class name of the shell that was invoked.
*
@ -81,6 +90,7 @@ class ShellDispatcher {
* @access public
*/
var $shellClass = null;
/**
* The command called if public methods are available.
*
@ -88,6 +98,7 @@ class ShellDispatcher {
* @access public
*/
var $shellCommand = null;
/**
* The path locations of shells.
*
@ -95,6 +106,7 @@ class ShellDispatcher {
* @access public
*/
var $shellPaths = array();
/**
* The path to the current shell location.
*
@ -102,6 +114,7 @@ class ShellDispatcher {
* @access public
*/
var $shellPath = null;
/**
* The name of the shell in camelized.
*
@ -109,6 +122,7 @@ class ShellDispatcher {
* @access public
*/
var $shellName = null;
/**
* Constructs this ShellDispatcher instance.
*
@ -117,19 +131,27 @@ class ShellDispatcher {
function ShellDispatcher($args = array()) {
$this->__construct($args);
}
/**
* Constructor
*
* @param array $args the argv.
* The execution of the script is stopped after dispatching the request with
* a status code of either 0 or 1 according to the result of the dispatch.
*
* @param array $args the argv
* @return void
* @access public
*/
function __construct($args = array()) {
set_time_limit(0);
$this->__initConstants();
$this->parseParams($args);
$this->_initEnvironment();
$this->__buildPaths();
$this->_stop($this->dispatch());
$this->_stop($this->dispatch() === false ? 1 : 0);
}
/**
* Defines core configuration.
*
@ -154,6 +176,7 @@ class ShellDispatcher {
}
require_once(CORE_PATH . 'cake' . DS . 'basics.php');
}
/**
* Defines current working environment.
*
@ -190,6 +213,7 @@ class ShellDispatcher {
$this->shiftArgs();
}
/**
* Builds the shell paths.
*
@ -224,6 +248,7 @@ class ShellDispatcher {
$this->shellPaths = array_values(array_unique(array_merge($paths, App::path('shells'))));
}
/**
* Initializes the environment and loads the Cake core.
*
@ -259,129 +284,163 @@ class ShellDispatcher {
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
Configure::buildPaths(array());
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
App::build();
}
Configure::write('debug', 1);
return true;
}
/**
* Clear the console
*
* @return void
* @access public
*/
function clear() {
if (empty($this->params['noclear'])) {
if ( DS === '/') {
passthru('clear');
} else {
passthru('cls');
}
}
}
/**
* Dispatches a CLI request
*
* @return boolean
* @access public
*/
function dispatch() {
if (isset($this->args[0])) {
$plugin = null;
$shell = $this->args[0];
if (strpos($shell, '.') !== false) {
list($plugin, $shell) = explode('.', $this->args[0]);
}
$arg = $this->shiftArgs();
$this->shell = $shell;
$this->shiftArgs();
$this->shellName = Inflector::camelize($this->shell);
$this->shellClass = $this->shellName . 'Shell';
if ($this->shell === 'help') {
$this->help();
} else {
$loaded = false;
foreach ($this->shellPaths as $path) {
$this->shellPath = $path . $this->shell . '.php';
$isPlugin = ($plugin && strpos($path, DS . $plugin . DS . 'vendors' . DS . 'shells' . DS) !== false);
if (($isPlugin && file_exists($this->shellPath)) || (!$plugin && file_exists($this->shellPath))) {
$loaded = true;
break;
}
}
if ($loaded) {
if (!class_exists('Shell')) {
require CONSOLE_LIBS . 'shell.php';
}
require $this->shellPath;
if (class_exists($this->shellClass)) {
$command = null;
if (isset($this->args[0])) {
$command = $this->args[0];
}
$this->shellCommand = Inflector::variable($command);
$shell = new $this->shellClass($this);
if (strtolower(get_parent_class($shell)) == 'shell') {
$shell->initialize();
$shell->loadTasks();
foreach ($shell->taskNames as $task) {
if (strtolower(get_parent_class($shell)) == 'shell') {
$shell->{$task}->initialize();
$shell->{$task}->loadTasks();
}
}
$task = Inflector::camelize($command);
if (in_array($task, $shell->taskNames)) {
$this->shiftArgs();
$shell->{$task}->startup();
if (isset($this->args[0]) && $this->args[0] == 'help') {
if (method_exists($shell->{$task}, 'help')) {
$shell->{$task}->help();
$this->_stop();
} else {
$this->help();
}
}
return $shell->{$task}->execute();
}
}
$classMethods = get_class_methods($shell);
$privateMethod = $missingCommand = false;
if ((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) {
$privateMethod = true;
}
if (!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) {
$missingCommand = true;
}
$protectedCommands = array(
'initialize','in','out','err','hr',
'createfile', 'isdir','copydir','object','tostring',
'requestaction','log','cakeerror', 'shelldispatcher',
'__initconstants','__initenvironment','__construct',
'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs'
);
if (in_array(strtolower($command), $protectedCommands)) {
$missingCommand = true;
}
if ($missingCommand && method_exists($shell, 'main')) {
$shell->startup();
return $shell->main();
} elseif (!$privateMethod && method_exists($shell, $command)) {
$this->shiftArgs();
$shell->startup();
return $shell->{$command}();
} else {
$this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'cake {$this->shell} help'.\n\n");
}
} else {
$this->stderr('Class '.$this->shellClass.' could not be loaded');
}
} else {
$this->help();
}
}
} else {
if (!$arg) {
$this->help();
return false;
}
if ($arg == 'help') {
$this->help();
return true;
}
if (strpos($arg, '.') !== false) {
list($plugin, $shell) = explode('.', $arg);
} else {
$plugin = null;
$shell = $arg;
}
$this->shell = $shell;
$this->shellName = Inflector::camelize($shell);
$this->shellClass = $this->shellName . 'Shell';
$arg = null;
if (isset($this->args[0])) {
$arg = $this->args[0];
$this->shellCommand = Inflector::variable($arg);
}
$Shell = $this->_getShell($plugin);
if (!$Shell) {
$title = sprintf(__('Error: Class %s could not be loaded.', true), $this->shellClass);
$this->stderr($title . "\n");
return false;
}
$methods = array();
if (is_a($Shell, 'Shell')) {
$Shell->initialize();
$Shell->loadTasks();
foreach ($Shell->taskNames as $task) {
if (is_a($Shell->{$task}, 'Shell')) {
$Shell->{$task}->initialize();
$Shell->{$task}->loadTasks();
}
}
$task = Inflector::camelize($arg);
if (in_array($task, $Shell->taskNames)) {
$this->shiftArgs();
$Shell->{$task}->startup();
if (isset($this->args[0]) && $this->args[0] == 'help') {
if (method_exists($Shell->{$task}, 'help')) {
$Shell->{$task}->help();
} else {
$this->help();
}
return true;
}
return $Shell->{$task}->execute();
}
$methods = array_diff(get_class_methods('Shell'), array('help'));
}
$methods = array_diff(get_class_methods($Shell), $methods);
$added = in_array(strtolower($arg), array_map('strtolower', $methods));
$private = $arg[0] == '_' && method_exists($Shell, $arg);
if (!$private) {
if ($added) {
$this->shiftArgs();
$Shell->startup();
return $Shell->{$arg}();
}
if (method_exists($Shell, 'main')) {
$Shell->startup();
return $Shell->main();
}
}
$title = sprintf(__('Error: Unknown %1$s command %2$s.', true), $this->shellName, $arg);
$message = sprintf(__('For usage try `cake %s help`', true), $this->shell);
$this->stderr($title . "\n" . $message . "\n");
return false;
}
/**
* Get shell to use, either plugin shell or application shell
*
* All paths in the shellPaths property are searched.
* shell, shellPath and shellClass properties are taken into account.
*
* @param string $plugin Optionally the name of a plugin
* @return mixed False if no shell could be found or an object on success
* @access protected
*/
function _getShell($plugin = null) {
foreach ($this->shellPaths as $path) {
$this->shellPath = $path . $this->shell . '.php';
$pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS;
if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) {
$loaded = true;
break;
}
}
if (!isset($loaded)) {
return false;
}
if (!class_exists('Shell')) {
require CONSOLE_LIBS . 'shell.php';
}
if (!class_exists($this->shellClass)) {
require $this->shellPath;
}
if (!class_exists($this->shellClass)) {
return false;
}
$Shell = new $this->shellClass($this);
return $Shell;
}
/**
* Prompts the user for input, and returns it.
*
@ -415,6 +474,7 @@ class ShellDispatcher {
}
return $result;
}
/**
* Outputs to the stdout filehandle.
*
@ -429,6 +489,7 @@ class ShellDispatcher {
fwrite($this->stdout, $string);
}
}
/**
* Outputs to the stderr filehandle.
*
@ -436,8 +497,9 @@ class ShellDispatcher {
* @access public
*/
function stderr($string) {
fwrite($this->stderr, 'Error: '. $string);
fwrite($this->stderr, $string);
}
/**
* Parses command line options
*
@ -446,13 +508,15 @@ class ShellDispatcher {
*/
function parseParams($params) {
$this->__parseParams($params);
$defaults = array('app' => 'app', 'root' => dirname(dirname(dirname(__FILE__))), 'working' => null, 'webroot' => 'webroot');
$params = array_merge($defaults, array_intersect_key($this->params, $defaults));
$isWin = array_filter(array_map('strpos', $params, array('\\')));
$isWin = false;
foreach ($defaults as $default => $value) {
if (strpos($params[$default], '\\') !== false) {
$isWin = true;
break;
}
}
$params = str_replace('\\', '/', $params);
if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) {
@ -464,7 +528,7 @@ class ShellDispatcher {
}
}
if ($params['app'][0] == '/' || preg_match('/([a-zA-Z])(:)/i', $params['app'], $matches)) {
if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
$params['root'] = dirname($params['app']);
} elseif (strpos($params['app'], '/')) {
$params['root'] .= '/' . dirname($params['app']);
@ -479,8 +543,9 @@ class ShellDispatcher {
$this->params = array_merge($this->params, $params);
}
/**
* Helper for recursively paraing params
* Helper for recursively parsing params
*
* @return array params
* @access private
@ -510,26 +575,24 @@ class ShellDispatcher {
}
}
}
/**
* Removes first argument and shifts other arguments up
*
* @return boolean False if there are no arguments
* @return mixed Null if there are no arguments otherwise the shifted argument
* @access public
*/
function shiftArgs() {
if (empty($this->args)) {
return false;
}
unset($this->args[0]);
$this->args = array_values($this->args);
return true;
return array_shift($this->args);
}
/**
* Shows console help
*
* @access public
*/
function help() {
$this->clear();
$this->stdout("\nWelcome to CakePHP v" . Configure::version() . " Console");
$this->stdout("---------------------------------------------------------------");
$this->stdout("Current Paths:");
@ -559,6 +622,7 @@ class ShellDispatcher {
} else {
sort($shells);
foreach ($shells as $shell) {
if ($shell !== 'shell.php') {
$this->stdout("\t " . str_replace('.php', '', $shell));
}
@ -568,8 +632,8 @@ class ShellDispatcher {
}
$this->stdout("\nTo run a command, type 'cake shell_name [args]'");
$this->stdout("To get help on a specific command, type 'cake shell_name help'");
$this->_stop();
}
/**
* Stop execution of the current script
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* ErrorHandler for Console Shells
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Error Handler for Cake console.
*
@ -31,6 +33,7 @@
* @subpackage cake.cake.console
*/
class ErrorHandler extends Object {
/**
* Standard output stream.
*
@ -38,6 +41,7 @@ class ErrorHandler extends Object {
* @access public
*/
var $stdout;
/**
* Standard error stream.
*
@ -45,6 +49,7 @@ class ErrorHandler extends Object {
* @access public
*/
var $stderr;
/**
* Class constructor.
*
@ -60,6 +65,7 @@ class ErrorHandler extends Object {
call_user_func_array(array(&$this, 'error404'), $messages);
}
}
/**
* Displays an error page (e.g. 404 Not found).
*
@ -71,6 +77,7 @@ class ErrorHandler extends Object {
$this->stderr($code . $name . $message."\n");
$this->_stop();
}
/**
* Convenience method to display a 404 page.
*
@ -84,6 +91,7 @@ class ErrorHandler extends Object {
'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)));
$this->_stop();
}
/**
* Renders the Missing Controller web page.
*
@ -96,6 +104,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
$this->_stop();
}
/**
* Renders the Missing Action web page.
*
@ -107,6 +116,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
$this->_stop();
}
/**
* Renders the Private Action web page.
*
@ -118,6 +128,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
$this->_stop();
}
/**
* Renders the Missing Table web page.
*
@ -129,6 +140,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
$this->_stop();
}
/**
* Renders the Missing Database web page.
*
@ -139,6 +151,7 @@ class ErrorHandler extends Object {
$this->stderr(__("Missing Database", true));
$this->_stop();
}
/**
* Renders the Missing View web page.
*
@ -150,6 +163,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
$this->_stop();
}
/**
* Renders the Missing Layout web page.
*
@ -161,6 +175,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
$this->_stop();
}
/**
* Renders the Database Connection web page.
*
@ -172,6 +187,7 @@ class ErrorHandler extends Object {
$this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
$this->_stop();
}
/**
* Renders the Missing Helper file web page.
*
@ -183,6 +199,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
$this->_stop();
}
/**
* Renders the Missing Helper class web page.
*
@ -194,6 +211,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
$this->_stop();
}
/**
* Renders the Missing Component file web page.
*
@ -205,6 +223,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
$this->_stop();
}
/**
* Renders the Missing Component class web page.
*
@ -216,6 +235,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
$this->_stop();
}
/**
* Renders the Missing Model class web page.
*
@ -227,6 +247,7 @@ class ErrorHandler extends Object {
$this->stderr(sprintf(__("Missing model '%s'", true), $className));
$this->_stop();
}
/**
* Outputs to the stdout filehandle.
*
@ -241,6 +262,7 @@ class ErrorHandler extends Object {
fwrite($this->stdout, $string);
}
}
/**
* Outputs to the stderr filehandle.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -26,6 +27,7 @@
*/
App::import('Component', 'Acl');
App::import('Model', 'DbAcl');
/**
* Shell for ACL management.
*
@ -33,6 +35,7 @@ App::import('Model', 'DbAcl');
* @subpackage cake.cake.console.libs
*/
class AclShell extends Shell {
/**
* Contains instance of AclComponent
*
@ -40,6 +43,7 @@ class AclShell extends Shell {
* @access public
*/
var $Acl;
/**
* Contains arguments parsed from the command line.
*
@ -47,6 +51,7 @@ class AclShell extends Shell {
* @access public
*/
var $args;
/**
* Contains database source to use
*
@ -54,6 +59,7 @@ class AclShell extends Shell {
* @access public
*/
var $dataSource = 'default';
/**
* Contains tasks to load and instantiate
*
@ -61,6 +67,7 @@ class AclShell extends Shell {
* @access public
*/
var $tasks = array('DbConfig');
/**
* Override startup of the Shell
*
@ -101,6 +108,7 @@ class AclShell extends Shell {
}
}
}
/**
* Override main() for help message hook
*
@ -122,6 +130,7 @@ class AclShell extends Shell {
$out .= __("For help, run the 'help' command. For help on a specific command, run 'help <command>'", true);
$this->out($out);
}
/**
* Creates an ARO/ACO node
*
@ -179,6 +188,7 @@ class AclShell extends Shell {
$this->err(sprintf(__("There was a problem creating a new %s '%s'.", true), $class, $this->args[2]));
}
}
/**
* Delete an ARO/ACO node.
*
@ -216,6 +226,7 @@ class AclShell extends Shell {
$this->out(sprintf(__("Node parent set to %s", true), $this->args[2]) . "\n", true);
}
}
/**
* Get path to specified ARO/ACO node.
*
@ -234,6 +245,7 @@ class AclShell extends Shell {
$this->out(str_repeat(' ', $i) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias'] . "\n");
}
}
/**
* Check permission for a given ARO to a given ACO.
*
@ -249,6 +261,7 @@ class AclShell extends Shell {
$this->out(sprintf(__("%s is not allowed.", true), $aro), true);
}
}
/**
* Grant permission for a given ARO to a given ACO.
*
@ -264,6 +277,7 @@ class AclShell extends Shell {
$this->out(__("Permission was not granted.", true), true);
}
}
/**
* Deny access for an ARO to an ACO.
*
@ -279,6 +293,7 @@ class AclShell extends Shell {
$this->out(__("Permission was not denied.", true), true);
}
}
/**
* Set an ARO to inhermit permission to an ACO.
*
@ -294,6 +309,7 @@ class AclShell extends Shell {
$this->out(__("Permission was not inherited.", true), true);
}
}
/**
* Show a specific ARO/ACO node.
*
@ -345,6 +361,7 @@ class AclShell extends Shell {
}
$this->hr();
}
/**
* Initialize ACL database.
*
@ -354,6 +371,7 @@ class AclShell extends Shell {
$this->Dispatch->args = array('schema', 'run', 'create', 'DbAcl');
$this->Dispatch->dispatch();
}
/**
* Show help screen.
*
@ -431,6 +449,7 @@ class AclShell extends Shell {
$this->out(sprintf(__("Command '%s' not found", true), $this->args[0]));
}
}
/**
* Check that first argument specifies a valid Node type (ARO/ACO)
*
@ -444,6 +463,7 @@ class AclShell extends Shell {
$this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[1]), __('Please specify which ACL object type you wish to create.', true));
}
}
/**
* Checks that given node exists
*
@ -465,6 +485,7 @@ class AclShell extends Shell {
}
return $possibility;
}
/**
* get params for standard Acl methods
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* API shell to get CakePHP core method signatures.
*
@ -32,6 +33,7 @@
* @subpackage cake.cake.console.libs
*/
class ApiShell extends Shell {
/**
* Map between short name for paths and real paths.
*
@ -39,6 +41,7 @@ class ApiShell extends Shell {
* @access public
*/
var $paths = array();
/**
* Override intialize of the Shell
*
@ -56,6 +59,7 @@ class ApiShell extends Shell {
'core' => LIBS
));
}
/**
* Override main() to handle action
*
@ -66,7 +70,7 @@ class ApiShell extends Shell {
return $this->help();
}
$type = low($this->args[0]);
$type = strtolower($this->args[0]);
if (isset($this->paths[$type])) {
$path = $this->paths[$type];
@ -202,7 +206,7 @@ class ApiShell extends Shell {
if (strpos($method, '__') === false && $method[0] != '_') {
$parsed[$method] = array(
'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
'comment' => str_replace(array('/*', '*/', '*'), '', trim($result[1][$key])),
'method' => $method,
'parameters' => trim($result[3][$key])
);

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* Command-line code generation utility to automate programmer chores.
*
@ -21,11 +20,9 @@
* @package cake
* @subpackage cake.cake.console.libs
* @since CakePHP(tm) v 1.2.0.5012
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Bake is a command-line code generation utility for automating programmer chores.
*
@ -34,13 +31,15 @@
* @link http://book.cakephp.org/view/113/Code-Generation-with-Bake
*/
class BakeShell extends Shell {
/**
* Contains tasks to load and instantiate
*
* @var array
* @access public
*/
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Test');
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Fixture', 'Test');
/**
* Override loadTasks() to handle paths
*
@ -50,14 +49,23 @@ class BakeShell extends Shell {
parent::loadTasks();
$task = Inflector::classify($this->command);
if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
$path = Inflector::underscore(Inflector::pluralize($this->command));
$this->{$task}->path = $this->params['working'] . DS . $path . DS;
if (empty($this->{$task}->path)) {
$path = Inflector::underscore(Inflector::pluralize($this->command));
$this->{$task}->path = $this->params['working'] . DS . $path . DS;
}
if (isset($this->params['connection'])) {
$this->{$task}->connection = $this->params['connection'];
}
if (isset($this->params['plugin'])) {
$this->{$task}->plugin = $this->params['plugin'];
}
if (!is_dir($this->{$task}->path)) {
$this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
$this->_stop();
}
}
}
/**
* Override main() to handle action
*
@ -82,6 +90,7 @@ class BakeShell extends Shell {
$this->out('[V]iew');
$this->out('[C]ontroller');
$this->out('[P]roject');
$this->out('[F]ixture');
$this->out('[Q]uit');
$classToBake = strtoupper($this->in(__('What would you like to Bake?', true), array('D', 'M', 'V', 'C', 'P', 'Q')));
@ -101,6 +110,9 @@ class BakeShell extends Shell {
case 'P':
$this->Project->execute();
break;
case 'F':
$this->Fixture->execute();
break;
case 'Q':
exit(0);
break;
@ -110,28 +122,33 @@ class BakeShell extends Shell {
$this->hr();
$this->main();
}
/**
* Quickly bake the MVC
*
* @access public
*/
function all() {
$ds = 'default';
$this->hr();
$this->out('Bake All');
$this->hr();
if (isset($this->params['connection'])) {
$ds = $this->params['connection'];
if (!isset($this->params['connection']) && empty($this->connection)) {
$this->connection = $this->DbConfig->getConfig();
}
if (empty($this->args)) {
$name = $this->Model->getName($ds);
$this->Model->interactive = true;
$name = $this->Model->getName($this->connection);
}
foreach (array('Model', 'Controller', 'View') as $task) {
$this->{$task}->connection = $this->connection;
$this->{$task}->interactive = false;
}
if (!empty($this->args[0])) {
$name = $this->args[0];
$this->Model->listAll($ds, false);
}
$modelExists = false;
@ -140,8 +157,8 @@ class BakeShell extends Shell {
$object = new $model();
$modelExists = true;
} else {
App::import('Model');
$object = new Model(array('name' => $name, 'ds' => $ds));
App::import('Model', 'Model', false);
$object = new Model(array('name' => $name, 'ds' => $this->connection));
}
$modelBaked = $this->Model->bake($object, false);
@ -149,6 +166,7 @@ class BakeShell extends Shell {
if ($modelBaked && $modelExists === false) {
$this->out(sprintf(__('%s Model was baked.', true), $model));
if ($this->_checkUnitTest()) {
$this->Model->bakeFixture($model);
$this->Model->bakeTest($model);
}
$modelExists = true;
@ -165,16 +183,13 @@ class BakeShell extends Shell {
if (App::import('Controller', $controller)) {
$this->View->args = array($controller);
$this->View->execute();
$this->out(sprintf(__('%s Views were baked.', true), $name));
}
$this->out(__('Bake All complete'));
$this->out(__('Bake All complete', true));
array_shift($this->args);
} else {
$this->err(__('Bake All could not continue without a valid model', true));
}
if (empty($this->args)) {
$this->all();
}
$this->_stop();
}

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,11 +25,13 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* @package cake
* @subpackage cake.cake.console.libs
*/
class ConsoleShell extends Shell {
/**
* Available binding types
*
@ -36,6 +39,7 @@ class ConsoleShell extends Shell {
* @access public
*/
var $associations = array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany');
/**
* Chars that describe invalid commands
*
@ -43,6 +47,7 @@ class ConsoleShell extends Shell {
* @access public
*/
var $badCommandChars = array('$', ';');
/**
* Available models
*
@ -50,6 +55,7 @@ class ConsoleShell extends Shell {
* @access public
*/
var $models = array();
/**
* Override intialize of the Shell
*
@ -74,6 +80,7 @@ class ConsoleShell extends Shell {
}
$this->_loadRoutes();
}
/**
* Prints the help message
*
@ -136,6 +143,7 @@ class ConsoleShell extends Shell {
$out .= "\tRoutes show";
$this->out($out);
}
/**
* Override main() to handle action
*
@ -269,8 +277,7 @@ class ConsoleShell extends Shell {
if ($this->_isValidModel($modelToSave)) {
// Extract the array of data we are trying to build
list($foo, $data) = explode("->save", $command);
$badChars = array("(", ")");
$data = str_replace($badChars, "", $data);
$data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data);
$saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));";
@eval($saveCommand);
$this->out('Saved record for ' . $modelToSave);
@ -321,6 +328,7 @@ class ConsoleShell extends Shell {
$command = '';
}
}
/**
* Tells if the specified model is included in the list of available models
*
@ -331,6 +339,7 @@ class ConsoleShell extends Shell {
function _isValidModel($modelToCheck) {
return in_array($modelToCheck, $this->models);
}
/**
* Reloads the routes configuration from config/routes.php, and compiles
* all routes found

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Shell for I18N management.
*
@ -31,6 +33,7 @@
* @subpackage cake.cake.console.libs
*/
class I18nShell extends Shell {
/**
* Contains database source to use
*
@ -38,6 +41,7 @@ class I18nShell extends Shell {
* @access public
*/
var $dataSource = 'default';
/**
* Contains tasks to load and instantiate
*
@ -45,6 +49,7 @@ class I18nShell extends Shell {
* @access public
*/
var $tasks = array('DbConfig', 'Extract');
/**
* Override startup of the Shell
*
@ -63,6 +68,7 @@ class I18nShell extends Shell {
}
}
}
/**
* Override main() for help message hook
*
@ -96,6 +102,7 @@ class I18nShell extends Shell {
$this->hr();
$this->main();
}
/**
* Initialize I18N database.
*
@ -105,6 +112,7 @@ class I18nShell extends Shell {
$this->Dispatch->args = array('schema', 'run', 'create', 'i18n');
$this->Dispatch->dispatch();
}
/**
* Show help screen.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Command-line database management utility to automate programmer chores.
*
@ -26,7 +27,8 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('File');
App::import('Model', 'CakeSchema');
App::import('Model', 'CakeSchema', false);
/**
* Schema is a command-line database management utility for automating programmer chores.
*
@ -35,6 +37,7 @@ App::import('Model', 'CakeSchema');
* @link http://book.cakephp.org/view/734/Schema-management-and-migrations
*/
class SchemaShell extends Shell {
/**
* is this a dry run?
*
@ -42,6 +45,7 @@ class SchemaShell extends Shell {
* @access private
*/
var $__dry = null;
/**
* Override initialize
*
@ -52,6 +56,7 @@ class SchemaShell extends Shell {
$this->out('Cake Schema Shell');
$this->hr();
}
/**
* Override startup
*
@ -85,6 +90,7 @@ class SchemaShell extends Shell {
$this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection'));
}
/**
* Override main
*
@ -93,6 +99,7 @@ class SchemaShell extends Shell {
function main() {
$this->help();
}
/**
* Read and output contents of schema object
* path to read as second arg
@ -109,6 +116,7 @@ class SchemaShell extends Shell {
$this->_stop();
}
}
/**
* Read database and Write schema object
* accepts a connection as first arg or path to save as second arg
@ -177,6 +185,7 @@ class SchemaShell extends Shell {
$this->_stop();
}
}
/**
* Dump Schema object to sql file
* if first arg == write, file will be written to sql file
@ -199,7 +208,7 @@ class SchemaShell extends Shell {
}
}
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$contents = "#". $Schema->name ." sql generated on: " . date('Y-m-d H:m:s') . " : ". time()."\n\n";
$contents = "#" . $Schema->name . " sql generated on: " . date('Y-m-d H:i:s') . " : " . time() . "\n\n";
$contents .= $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema);
if ($write) {
if (strpos($write, '.sql') === false) {
@ -217,6 +226,7 @@ class SchemaShell extends Shell {
$this->out($contents);
return $contents;
}
/**
* Run database commands: create, update
*
@ -275,6 +285,7 @@ class SchemaShell extends Shell {
$this->_stop();
}
}
/**
* Create database from Schema object
* Should be called via the run method
@ -318,6 +329,7 @@ class SchemaShell extends Shell {
$this->out(__('End create.', true));
}
/**
* Update database with Schema object
* Should be called via the run method
@ -356,6 +368,7 @@ class SchemaShell extends Shell {
$this->out(__('End update.', true));
}
/**
* Runs sql from __create() or __update()
*
@ -397,6 +410,7 @@ class SchemaShell extends Shell {
}
}
}
/**
* Displays help contents
*
@ -426,4 +440,4 @@ class SchemaShell extends Shell {
$this->_stop();
}
}
?>
?>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Base class for Shells
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Base class for command-line utilities for automating programmer chores.
*
@ -31,6 +33,7 @@
* @subpackage cake.cake.console.libs
*/
class Shell extends Object {
/**
* An instance of the ShellDispatcher object that loaded this script
*
@ -38,6 +41,7 @@ class Shell extends Object {
* @access public
*/
var $Dispatch = null;
/**
* If true, the script will ask for permission to perform actions.
*
@ -45,6 +49,7 @@ class Shell extends Object {
* @access public
*/
var $interactive = true;
/**
* Holds the DATABASE_CONFIG object for the app. Null if database.php could not be found,
* or the app does not exist.
@ -53,6 +58,7 @@ class Shell extends Object {
* @access public
*/
var $DbConfig = null;
/**
* Contains command switches parsed from the command line.
*
@ -60,6 +66,7 @@ class Shell extends Object {
* @access public
*/
var $params = array();
/**
* Contains arguments parsed from the command line.
*
@ -67,6 +74,7 @@ class Shell extends Object {
* @access public
*/
var $args = array();
/**
* The file name of the shell that was invoked.
*
@ -74,6 +82,7 @@ class Shell extends Object {
* @access public
*/
var $shell = null;
/**
* The class name of the shell that was invoked.
*
@ -81,6 +90,7 @@ class Shell extends Object {
* @access public
*/
var $className = null;
/**
* The command called if public methods are available.
*
@ -88,6 +98,7 @@ class Shell extends Object {
* @access public
*/
var $command = null;
/**
* The name of the shell in camelized.
*
@ -95,6 +106,7 @@ class Shell extends Object {
* @access public
*/
var $name = null;
/**
* An alias for the shell
*
@ -102,6 +114,7 @@ class Shell extends Object {
* @access public
*/
var $alias = null;
/**
* Contains tasks to load and instantiate
*
@ -109,6 +122,7 @@ class Shell extends Object {
* @access public
*/
var $tasks = array();
/**
* Contains the loaded tasks
*
@ -116,6 +130,7 @@ class Shell extends Object {
* @access public
*/
var $taskNames = array();
/**
* Contains models to load and instantiate
*
@ -123,6 +138,7 @@ class Shell extends Object {
* @access public
*/
var $uses = array();
/**
* Constructs this Shell instance.
*
@ -149,16 +165,17 @@ class Shell extends Object {
ClassRegistry::map($this->name, $this->alias);
if (!PHP5 && isset($this->args[0])) {
if (strpos($this->name, low(Inflector::camelize($this->args[0]))) !== false) {
if (strpos($this->name, strtolower(Inflector::camelize($this->args[0]))) !== false) {
$dispatch->shiftArgs();
}
if (low($this->command) == low(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
if (strtolower($this->command) == strtolower(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
$dispatch->shiftArgs();
}
}
$this->Dispatch =& $dispatch;
}
/**
* Initializes the Shell
* acts as constructor for subclasses
@ -169,6 +186,7 @@ class Shell extends Object {
function initialize() {
$this->_loadModels();
}
/**
* Starts up the the Shell
* allows for checking and configuring prior to command or main execution
@ -179,18 +197,21 @@ class Shell extends Object {
function startup() {
$this->_welcome();
}
/**
* Displays a header for the shell
*
* @access protected
*/
function _welcome() {
$this->Dispatch->clear();
$this->out("\nWelcome to CakePHP v" . Configure::version() . " Console");
$this->out("---------------------------------------------------------------");
$this->out('App : '. $this->params['app']);
$this->out('Path: '. $this->params['working']);
$this->hr();
}
/**
* Loads database file and constructs DATABASE_CONFIG class
* makes $this->DbConfig available to subclasses
@ -207,6 +228,7 @@ class Shell extends Object {
$this->out('Run \'bake\' to create the database configuration');
return false;
}
/**
* if var $uses = true
* Loads AppModel file and constructs AppModel class
@ -251,6 +273,7 @@ class Shell extends Object {
}
return false;
}
/**
* Loads tasks defined in var $tasks
*
@ -297,13 +320,14 @@ class Shell extends Object {
}
if (!isset($this->{$taskName})) {
$this->err("Task '".$taskName."' could not be loaded");
$this->err("Task '" . $taskName . "' could not be loaded");
$this->_stop();
}
}
return true;
}
/**
* Prompts the user for input, and returns it.
*
@ -329,7 +353,7 @@ class Shell extends Object {
}
}
if (is_array($options)) {
while ($in == '' || ($in && (!in_array(low($in), $options) && !in_array(up($in), $options)) && !in_array($in, $options))) {
while ($in == '' || ($in && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
$in = $this->Dispatch->getInput($prompt, $options, $default);
}
}
@ -337,68 +361,82 @@ class Shell extends Object {
return $in;
}
}
/**
* Outputs to the stdout filehandle.
* Outputs a single or multiple messages to stdout.
*
* @param string $string String to output.
* @param boolean $newline If true, the outputs gets an added newline.
* @param mixed $message A string or a an array of strings to output
* @param mixed $after Appended to message, if true a newline is used
* @access public
*/
function out($string, $newline = true) {
if (is_array($string)) {
$str = '';
foreach ($string as $message) {
$str .= $message ."\n";
}
$string = $str;
function out($message, $after = true) {
if (is_array($message)) {
$message = implode($this->nl(), $message);
}
return $this->Dispatch->stdout($string, $newline);
$this->Dispatch->stdout($message . $this->nl($after), false);
}
/**
* Outputs to the stderr filehandle.
* Outputs a single or multiple error messages to stderr.
*
* @param string $string Error text to output.
* @param mixed $message A string or a an array of strings to output
* @param mixed $after Appended to message, if true a newline is used
* @access public
*/
function err($string) {
if (is_array($string)) {
$str = '';
foreach ($string as $message) {
$str .= $message ."\n";
}
$string = $str;
function err($message, $after = true) {
if (is_array($message)) {
$message = implode($this->nl(), $message);
}
return $this->Dispatch->stderr($string."\n");
$this->Dispatch->stderr($message . $this->nl($after));
}
/**
* Returns a single or multiple linefeeds sequences.
*
* @param mixed $format If true returns a linefeed sequence, if false null,
* if a string is given that is returned,
* if an integer is given it is used as a multiplier to return multiple linefeed sequences
* @access public
* @return string
*/
function nl($format = true) {
if (is_string($format)) {
return $format . "\n";
}
if (is_int($format)) {
return str_repeat("\n", $format);
}
return $format ? "\n" : null;
}
/**
* Outputs a series of minus characters to the standard output, acts as a visual separator.
*
* @param boolean $newline If true, the outputs gets an added newline.
* @param mixed $surround If true, the outputs gets surrounded by newlines.
* @access public
*/
function hr($newline = false) {
if ($newline) {
$this->out("\n");
}
function hr($surround = false) {
$this->out(null, $surround);
$this->out('---------------------------------------------------------------');
if ($newline) {
$this->out("\n");
}
$this->out(null, $surround);
}
/**
* Displays a formatted error message and exits the application
* Displays a formatted error message
* and exits the application with status code 1
*
* @param string $title Title of the error message
* @param string $msg Error message
* @param string $title Title of the error
* @param string $message An optional error message
* @access public
*/
function error($title, $msg) {
$out = "$title\n";
$out .= "$msg\n";
$out .= "\n";
$this->err($out);
$this->_stop();
function error($title, $message = null) {
$this->err(sprintf(__('Error: %s', true), $title));
if (!empty($message)) {
$this->err($message);
}
$this->_stop(1);
}
/**
* Will check the number args matches otherwise throw an error
*
@ -414,6 +452,7 @@ class Shell extends Object {
$this->error("Wrong number of parameters: ".count($this->args), "Expected: {$expectedNum}\nPlease type 'cake {$this->shell} help' for help on usage of the {$this->name} {$command}");
}
}
/**
* Creates a file at given path
*
@ -427,10 +466,10 @@ class Shell extends Object {
$this->out("\n" . sprintf(__("Creating file %s", true), $path));
if (is_file($path) && $this->interactive === true) {
$key = $this->in(__("File exists, overwrite?", true). " {$path}", array('y', 'n', 'q'), 'n');
if (low($key) == 'q') {
if (strtolower($key) == 'q') {
$this->out(__("Quitting.", true) ."\n");
exit;
} elseif (low($key) != 'y') {
} elseif (strtolower($key) != 'y') {
$this->out(__("Skip", true) ." {$path}\n");
return false;
}
@ -449,6 +488,7 @@ class Shell extends Object {
return false;
}
}
/**
* Outputs usage text on the standard output. Implement it in subclasses.
*
@ -461,6 +501,7 @@ class Shell extends Object {
$this->Dispatch->help();
}
}
/**
* Action to create a Unit Test
*
@ -472,13 +513,14 @@ class Shell extends Object {
return true;
}
$unitTest = $this->in('SimpleTest is not installed. Do you want to bake unit test files anyway?', array('y','n'), 'y');
$result = low($unitTest) == 'y' || low($unitTest) == 'yes';
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';
if ($result) {
$this->out("\nYou can download SimpleTest from http://simpletest.org", true);
}
return $result;
}
/**
* Makes absolute file path easier to read
*
@ -488,38 +530,10 @@ class Shell extends Object {
*/
function shortPath($file) {
$shortPath = str_replace(ROOT, null, $file);
$shortPath = str_replace('..'.DS, '', $shortPath);
return r(DS.DS, DS, $shortPath);
}
/**
* Checks for Configure::read('Routing.admin') and forces user to input it if not enabled
*
* @return string Admin route to use
* @access public
*/
function getAdmin() {
$admin = '';
$cakeAdmin = null;
$adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute)) {
$cakeAdmin = $adminRoute . '_';
} else {
$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
$this->out('What would you like the admin route to be?');
$this->out('Example: www.example.com/admin/controller');
while ($admin == '') {
$admin = $this->in("What would you like the admin route to be?", null, 'admin');
}
if ($this->Project->cakeAdmin($admin) !== true) {
$this->out('Unable to write to /app/config/core.php.');
$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
$this->_stop();
} else {
$cakeAdmin = $admin . '_';
}
}
return $cakeAdmin;
$shortPath = str_replace('..' . DS, '', $shortPath);
return str_replace(DS . DS, DS, $shortPath);
}
/**
* Creates the proper controller path for the specified controller class name
*
@ -528,8 +542,9 @@ class Shell extends Object {
* @access protected
*/
function _controllerPath($name) {
return low(Inflector::underscore($name));
return strtolower(Inflector::underscore($name));
}
/**
* Creates the proper controller plural name for the specified controller class name
*
@ -540,6 +555,7 @@ class Shell extends Object {
function _controllerName($name) {
return Inflector::pluralize(Inflector::camelize($name));
}
/**
* Creates the proper controller camelized name (singularized) for the specified name
*
@ -550,6 +566,7 @@ class Shell extends Object {
function _modelName($name) {
return Inflector::camelize(Inflector::singularize($name));
}
/**
* Creates the proper singular model key for associations
*
@ -560,6 +577,7 @@ class Shell extends Object {
function _modelKey($name) {
return Inflector::underscore(Inflector::singularize($name)).'_id';
}
/**
* Creates the proper model name from a foreign key
*
@ -571,6 +589,7 @@ class Shell extends Object {
$name = str_replace('_id', '',$key);
return Inflector::camelize($name);
}
/**
* creates the singular name for use in views.
*
@ -581,6 +600,7 @@ class Shell extends Object {
function _singularName($name) {
return Inflector::variable(Inflector::singularize($name));
}
/**
* Creates the plural name for views
*
@ -591,6 +611,7 @@ class Shell extends Object {
function _pluralName($name) {
return Inflector::variable(Inflector::pluralize($name));
}
/**
* Creates the singular human name used in views
*
@ -601,6 +622,7 @@ class Shell extends Object {
function _singularHumanName($name) {
return Inflector::humanize(Inflector::underscore(Inflector::singularize($name)));
}
/**
* Creates the plural human name used in views
*
@ -611,5 +633,22 @@ class Shell extends Object {
function _pluralHumanName($name) {
return Inflector::humanize(Inflector::underscore(Inflector::pluralize($name)));
}
/**
* Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
*
* @param string $pluginName Name of the plugin you want ie. DebugKit
* @return string $path path to the correct plugin.
**/
function _pluginPath($pluginName) {
$pluginPaths = App::path('plugins');
$pluginDirName = Inflector::underscore($pluginName);
foreach ($pluginPaths as $path) {
if (is_dir($path . $pluginDirName)) {
return $path . $pluginDirName . DS ;
}
}
return $pluginPaths[0] . $pluginDirName . DS;
}
}
?>

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* The ControllerTask handles creating and updating controller files.
*
@ -8,22 +7,20 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc.
* Copyright 2005-2009, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs.tasks
* @since CakePHP(tm) v 1.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Task class for creating and updating controller files.
*
@ -31,6 +28,7 @@
* @subpackage cake.cake.console.libs.tasks
*/
class ControllerTask extends Shell {
/**
* Name of plugin
*
@ -38,13 +36,15 @@ class ControllerTask extends Shell {
* @access public
*/
var $plugin = null;
/**
* Tasks to be loaded by this Task
*
* @var array
* @access public
*/
var $tasks = array('Project');
var $tasks = array('Model', 'Test', 'Template', 'DbConfig', 'Project');
/**
* path to CONTROLLERS directory
*
@ -52,6 +52,7 @@ class ControllerTask extends Shell {
* @access public
*/
var $path = CONTROLLERS;
/**
* Override initialize
*
@ -59,6 +60,7 @@ class ControllerTask extends Shell {
*/
function initialize() {
}
/**
* Execution method always used for tasks
*
@ -70,16 +72,22 @@ class ControllerTask extends Shell {
}
if (isset($this->args[0])) {
if (!isset($this->connection)) {
$this->connection = 'default';
}
if (strtolower($this->args[0]) == 'all') {
return $this->all();
}
$controller = Inflector::camelize($this->args[0]);
$actions = null;
if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
$this->out('Baking scaffold for ' . $controller);
$this->out(__('Baking scaffold for ', true) . $controller);
$actions = $this->bakeActions($controller);
} else {
$actions = 'scaffold';
}
if ((isset($this->args[1]) && $this->args[1] == 'admin') || (isset($this->args[2]) && $this->args[2] == 'admin')) {
if ($admin = $this->getAdmin()) {
if ($admin = $this->Project->getAdmin()) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods');
if ($actions == 'scaffold') {
$actions = $this->bakeActions($controller, $admin);
@ -95,144 +103,169 @@ class ControllerTask extends Shell {
}
}
}
/**
* Bake All the controllers at once. Will only bake controllers for models that exist.
*
* @access public
* @return void
**/
function all() {
$this->interactive = false;
$this->listAll($this->connection, false);
ClassRegistry::config('Model', array('ds' => $this->connection));
$unitTestExists = $this->_checkUnitTest();
foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$controller = $this->_controllerName($model);
if (App::import('Model', $model)) {
$actions = $this->bakeActions($controller);
if ($this->bake($controller, $actions) && $unitTestExists) {
$this->bakeTest($controller);
}
}
}
}
/**
* Interactive
*
* @access private
*/
function __interactive($controllerName = false) {
if (!$controllerName) {
$this->interactive = true;
$this->hr();
$this->out(sprintf("Bake Controller\nPath: %s", $this->path));
$this->hr();
$actions = '';
$uses = array();
$helpers = array();
$components = array();
$wannaUseSession = 'y';
$wannaDoAdmin = 'n';
$wannaUseScaffold = 'n';
$wannaDoScaffolding = 'y';
$controllerName = $this->getName();
}
function __interactive() {
$this->interactive = true;
$this->hr();
$this->out("Baking {$controllerName}Controller");
$this->out(sprintf(__("Bake Controller\nPath: %s", true), $this->path));
$this->hr();
$controllerFile = low(Inflector::underscore($controllerName));
if (empty($this->connection)) {
$this->connection = $this->DbConfig->getConfig();
}
$controllerName = $this->getName();
$this->hr();
$this->out(sprintf(__('Baking %sController', true), $controllerName));
$this->hr();
$helpers = $components = array();
$actions = '';
$wannaUseSession = 'y';
$wannaBakeAdminCrud = 'n';
$useDynamicScaffold = 'n';
$wannaBakeCrud = 'y';
$controllerFile = strtolower(Inflector::underscore($controllerName));
$question[] = __("Would you like to build your controller interactively?", true);
if (file_exists($this->path . $controllerFile .'_controller.php')) {
$question[] = sprintf(__("Warning: Choosing no will overwrite the %sController.", true), $controllerName);
}
$doItInteractive = $this->in(join("\n", $question), array('y','n'), 'y');
$doItInteractive = $this->in(join("\n", $question), array('y', 'n'), 'y');
if (low($doItInteractive) == 'y' || low($doItInteractive) == 'yes') {
if (strtolower($doItInteractive) == 'y') {
$this->interactive = true;
$useDynamicScaffold = $this->in(
__("Would you like to use dynamic scaffolding?", true), array('y','n'), 'n'
);
$wannaUseScaffold = $this->in(__("Would you like to use scaffolding?", true), array('y','n'), 'n');
if (low($wannaUseScaffold) == 'n' || low($wannaUseScaffold) == 'no') {
$wannaDoScaffolding = $this->in(__("Would you like to include some basic class methods (index(), add(), view(), edit())?", true), array('y','n'), 'n');
if (low($wannaDoScaffolding) == 'y' || low($wannaDoScaffolding) == 'yes') {
$wannaDoAdmin = $this->in(__("Would you like to create the methods for admin routing?", true), array('y','n'), 'n');
}
$wannaDoHelpers = $this->in(__("Would you like this controller to use other helpers besides HtmlHelper and FormHelper?", true), array('y','n'), 'n');
if (low($wannaDoHelpers) == 'y' || low($wannaDoHelpers) == 'yes') {
$helpersList = $this->in(__("Please provide a comma separated list of the other helper names you'd like to use.\nExample: 'Ajax, Javascript, Time'", true));
$helpersListTrimmed = str_replace(' ', '', $helpersList);
$helpers = explode(',', $helpersListTrimmed);
}
$wannaDoComponents = $this->in(__("Would you like this controller to use any components?", true), array('y','n'), 'n');
if (low($wannaDoComponents) == 'y' || low($wannaDoComponents) == 'yes') {
$componentsList = $this->in(__("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'", true));
$componentsListTrimmed = str_replace(' ', '', $componentsList);
$components = explode(',', $componentsListTrimmed);
}
$wannaUseSession = $this->in(__("Would you like to use Sessions?", true), array('y','n'), 'y');
if (strtolower($useDynamicScaffold) == 'y') {
$wannaBakeCrud = 'n';
$actions = 'scaffold';
} else {
$wannaDoScaffolding = 'n';
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
$helpers = $this->doHelpers();
$components = $this->doComponents();
$wannaUseSession = $this->in(
__("Would you like to use Session flash messages?", true), array('y','n'), 'y'
);
}
} else {
$wannaDoScaffolding = $this->in(__("Would you like to include some basic class methods (index(), add(), view(), edit())?", true), array('y','n'), 'y');
if (low($wannaDoScaffolding) == 'y' || low($wannaDoScaffolding) == 'yes') {
$wannaDoAdmin = $this->in(__("Would you like to create the methods for admin routing?", true), array('y','n'), 'y');
}
}
$admin = false;
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
$admin = $this->getAdmin();
list($wannaBakeCrud, $wannaBakeCrud) = $this->_askAboutMethods();
}
if (low($wannaDoScaffolding) == 'y' || low($wannaDoScaffolding) == 'yes') {
$actions = $this->bakeActions($controllerName, null, in_array(low($wannaUseSession), array('y', 'yes')));
if ($admin) {
$actions .= $this->bakeActions($controllerName, $admin, in_array(low($wannaUseSession), array('y', 'yes')));
}
if (strtolower($wannaBakeCrud) == 'y') {
$actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) == 'y');
}
if (strtolower($wannaBakeAdminCrud) == 'y') {
$admin = $this->Project->getAdmin();
$actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) == 'y');
}
if ($this->interactive === true) {
$this->out('');
$this->hr();
$this->out('The following controller will be created:');
$this->hr();
$this->out("Controller Name: $controllerName");
if (low($wannaUseScaffold) == 'y' || low($wannaUseScaffold) == 'yes') {
$this->out(" var \$scaffold;");
$actions = 'scaffold';
}
if (count($helpers)) {
$this->out("Helpers: ", false);
foreach ($helpers as $help) {
if ($help != $helpers[count($helpers) - 1]) {
$this->out(ucfirst($help) . ", ", false);
} else {
$this->out(ucfirst($help));
}
}
}
if (count($components)) {
$this->out("Components: ", false);
foreach ($components as $comp) {
if ($comp != $components[count($components) - 1]) {
$this->out(ucfirst($comp) . ", ", false);
} else {
$this->out(ucfirst($comp));
}
}
}
$this->hr();
$this->confirmController($controllerName, $useDynamicScaffold, $helpers, $components);
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
$baked = $this->bake($controllerName, $actions, $helpers, $components, $uses);
if (strtolower($looksGood) == 'y') {
$baked = $this->bake($controllerName, $actions, $helpers, $components);
if ($baked && $this->_checkUnitTest()) {
$this->bakeTest($controllerName);
}
} else {
$this->__interactive($controllerName);
}
} else {
$baked = $this->bake($controllerName, $actions, $helpers, $components, $uses);
$baked = $this->bake($controllerName, $actions, $helpers, $components);
if ($baked && $this->_checkUnitTest()) {
$this->bakeTest($controllerName);
}
}
}
/**
* Confirm a to be baked controller with the user
*
* @return void
**/
function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
$this->out('');
$this->hr();
$this->out(__('The following controller will be created:', true));
$this->hr();
$this->out(sprintf(__("Controller Name:\n\t%s", true), $controllerName));
if (strtolower($useDynamicScaffold) == 'y') {
$this->out("var \$scaffold;");
}
$properties = array(
'helpers' => __("Helpers:", true),
'components' => __('Components:', true),
);
foreach ($properties as $var => $title) {
if (count($$var)) {
$output = '';
$length = count($$var);
foreach ($$var as $i => $propElement) {
if ($i != $length -1) {
$output .= ucfirst($propElement) . ', ';
} else {
$output .= ucfirst($propElement);
}
}
$this->out($title . "\n\t" . $output);
}
}
$this->hr();
}
/**
* Interact with the user and ask about which methods (admin or regular they want to bake)
*
* @return array Array containing (bakeRegular, bakeAdmin) answers
**/
function _askAboutMethods() {
$wannaBakeCrud = $this->in(
__("Would you like to create some basic class methods \n(index(), add(), view(), edit())?", true),
array('y','n'), 'n'
);
$wannaBakeAdminCrud = $this->in(
__("Would you like to create the basic class methods for admin routing?", true),
array('y','n'), 'n'
);
return array($wannaBakeCrud, $wannaBakeAdminCrud);
}
/**
* Bake scaffold actions
*
@ -247,151 +280,24 @@ class ControllerTask extends Shell {
if ($this->plugin) {
$modelImport = $this->plugin . '.' . $modelImport;
}
if (!App::import('Model', $modelImport)) {
$this->err(__('You must have a model for this class to build scaffold methods. Please try again.', true));
exit;
if (!App::import('Model', $currentModelName)) {
$this->err(__('You must have a model for this class to build basic methods. Please try again.', true));
$this->_stop();
}
$actions = null;
$modelObj =& new $currentModelName();
$modelObj =& ClassRegistry::init($currentModelName);
$controllerPath = $this->_controllerPath($controllerName);
$pluralName = $this->_pluralName($currentModelName);
$singularName = Inflector::variable($currentModelName);
$singularHumanName = Inflector::humanize($currentModelName);
$pluralHumanName = Inflector::humanize($controllerName);
$actions .= "\n";
$actions .= "\tfunction {$admin}index() {\n";
$actions .= "\t\t\$this->{$currentModelName}->recursive = 0;\n";
$actions .= "\t\t\$this->set('{$pluralName}', \$this->paginate());\n";
$actions .= "\t}\n";
$actions .= "\n";
$actions .= "\tfunction {$admin}view(\$id = null) {\n";
$actions .= "\t\tif (!\$id) {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\$this->Session->setFlash(__('Invalid {$singularHumanName}.', true));\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n";
}
$actions .= "\t\t}\n";
$actions .= "\t\t\$this->set('".$singularName."', \$this->{$currentModelName}->read(null, \$id));\n";
$actions .= "\t}\n";
$actions .= "\n";
/* ADD ACTION */
$compact = array();
$actions .= "\tfunction {$admin}add() {\n";
$actions .= "\t\tif (!empty(\$this->data)) {\n";
$actions .= "\t\t\t\$this->{$currentModelName}->create();\n";
$actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('The ".$singularHumanName." has been saved', true));\n";
$actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', true), array('action'=>'index'));\n";
}
$actions .= "\t\t\t} else {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('The {$singularHumanName} could not be saved. Please, try again.', true));\n";
}
$actions .= "\t\t\t}\n";
$actions .= "\t\t}\n";
foreach ($modelObj->hasAndBelongsToMany as $associationName => $relation) {
if (!empty($associationName)) {
$habtmModelName = $this->_modelName($associationName);
$habtmSingularName = $this->_singularName($associationName);
$habtmPluralName = $this->_pluralName($associationName);
$actions .= "\t\t\${$habtmPluralName} = \$this->{$currentModelName}->{$habtmModelName}->find('list');\n";
$compact[] = "'{$habtmPluralName}'";
}
}
foreach ($modelObj->belongsTo as $associationName => $relation) {
if (!empty($associationName)) {
$belongsToModelName = $this->_modelName($associationName);
$belongsToPluralName = $this->_pluralName($associationName);
$actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->find('list');\n";
$compact[] = "'{$belongsToPluralName}'";
}
}
if (!empty($compact)) {
$actions .= "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
}
$actions .= "\t}\n";
$actions .= "\n";
/* EDIT ACTION */
$compact = array();
$actions .= "\tfunction {$admin}edit(\$id = null) {\n";
$actions .= "\t\tif (!\$id && empty(\$this->data)) {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\$this->Session->setFlash(__('Invalid {$singularHumanName}', true));\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n";
}
$actions .= "\t\t}\n";
$actions .= "\t\tif (!empty(\$this->data)) {\n";
$actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('The ".$singularHumanName." has been saved', true));\n";
$actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\t\$this->flash(__('The ".$singularHumanName." has been saved.', true), array('action'=>'index'));\n";
}
$actions .= "\t\t\t} else {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('The {$singularHumanName} could not be saved. Please, try again.', true));\n";
}
$actions .= "\t\t\t}\n";
$actions .= "\t\t}\n";
$actions .= "\t\tif (empty(\$this->data)) {\n";
$actions .= "\t\t\t\$this->data = \$this->{$currentModelName}->read(null, \$id);\n";
$actions .= "\t\t}\n";
foreach ($modelObj->hasAndBelongsToMany as $associationName => $relation) {
if (!empty($associationName)) {
$habtmModelName = $this->_modelName($associationName);
$habtmSingularName = $this->_singularName($associationName);
$habtmPluralName = $this->_pluralName($associationName);
$actions .= "\t\t\${$habtmPluralName} = \$this->{$currentModelName}->{$habtmModelName}->find('list');\n";
$compact[] = "'{$habtmPluralName}'";
}
}
foreach ($modelObj->belongsTo as $associationName => $relation) {
if (!empty($associationName)) {
$belongsToModelName = $this->_modelName($associationName);
$belongsToPluralName = $this->_pluralName($associationName);
$actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->find('list');\n";
$compact[] = "'{$belongsToPluralName}'";
}
}
if (!empty($compact)) {
$actions .= "\t\t\$this->set(compact(".join(',', $compact)."));\n";
}
$actions .= "\t}\n";
$actions .= "\n";
$actions .= "\tfunction {$admin}delete(\$id = null) {\n";
$actions .= "\t\tif (!\$id) {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\$this->Session->setFlash(__('Invalid id for {$singularHumanName}', true));\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n";
}
$actions .= "\t\t}\n";
$actions .= "\t\tif (\$this->{$currentModelName}->delete(\$id)) {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\$this->Session->setFlash(__('{$singularHumanName} deleted', true));\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\$this->flash(__('{$singularHumanName} deleted', true), array('action'=>'index'));\n";
}
$actions .= "\t\t}\n";
$actions .= "\t}\n";
$actions .= "\n";
$this->Template->set(compact('admin', 'controllerPath', 'pluralName', 'singularName', 'singularHumanName',
'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName'));
$actions = $this->Template->generate('actions', 'controller_actions');
return $actions;
}
/**
* Assembles and writes a Controller file
*
@ -403,54 +309,24 @@ class ControllerTask extends Shell {
* @return string Baked controller
* @access private
*/
function bake($controllerName, $actions = '', $helpers = null, $components = null, $uses = null) {
$out = "<?php\n";
$out .= "class $controllerName" . "Controller extends {$this->plugin}AppController {\n\n";
$out .= "\tvar \$name = '$controllerName';\n";
function bake($controllerName, $actions = '', $helpers = null, $components = null) {
$isScaffold = ($actions === 'scaffold') ? true : false;
if (low($actions) == 'scaffold') {
$out .= "\tvar \$scaffold;\n";
} else {
if (count($uses)) {
$out .= "\tvar \$uses = array('" . $this->_modelName($controllerName) . "', ";
$this->Template->set('plugin', Inflector::camelize($this->plugin));
$this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold'));
$contents = $this->Template->generate('classes', 'controller');
foreach ($uses as $use) {
if ($use != $uses[count($uses) - 1]) {
$out .= "'" . $this->_modelName($use) . "', ";
} else {
$out .= "'" . $this->_modelName($use) . "'";
}
}
$out .= ");\n";
}
$out .= "\tvar \$helpers = array('Html', 'Form'";
if (count($helpers)) {
foreach ($helpers as $help) {
$out .= ", '" . Inflector::camelize($help) . "'";
}
}
$out .= ");\n";
if (count($components)) {
$out .= "\tvar \$components = array(";
foreach ($components as $comp) {
if ($comp != $components[count($components) - 1]) {
$out .= "'" . Inflector::camelize($comp) . "', ";
} else {
$out .= "'" . Inflector::camelize($comp) . "'";
}
}
$out .= ");\n";
}
$out .= $actions;
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'controllers' . DS;
}
$out .= "}\n";
$out .= "?>";
$filename = $this->path . $this->_controllerPath($controllerName) . '_controller.php';
return $this->createFile($filename, $out);
$filename = $path . $this->_controllerPath($controllerName) . '_controller.php';
if ($this->createFile($filename, $contents)) {
return $contents;
}
return false;
}
/**
* Assembles and writes a unit test file
*
@ -459,84 +335,93 @@ class ControllerTask extends Shell {
* @access private
*/
function bakeTest($className) {
$import = $className;
if ($this->plugin) {
$import = $this->plugin . '.' . $className;
}
$out = "App::import('Controller', '$import');\n\n";
$out .= "class Test{$className} extends {$className}Controller {\n";
$out .= "\tvar \$autoRender = false;\n}\n\n";
$out .= "class {$className}ControllerTest extends CakeTestCase {\n";
$out .= "\tvar \${$className} = null;\n\n";
$out .= "\tfunction startTest() {\n\t\t\$this->{$className} = new Test{$className}();";
$out .= "\n\t\t\$this->{$className}->constructClasses();\n\t}\n\n";
$out .= "\tfunction test{$className}ControllerInstance() {\n";
$out .= "\t\t\$this->assertTrue(is_a(\$this->{$className}, '{$className}Controller'));\n\t}\n\n";
$out .= "\tfunction endTest() {\n\t\tunset(\$this->{$className});\n\t}\n}\n";
$path = CONTROLLER_TESTS;
if (isset($this->plugin)) {
$pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
$path = APP . $pluginPath . 'tests' . DS . 'cases' . DS . 'controllers' . DS;
}
$filename = Inflector::underscore($className).'_controller.test.php';
$this->out("\nBaking unit test for $className...");
$header = '$Id';
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $className ."Controller Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
return $this->createFile($path . $filename, $content);
$this->Test->plugin = $this->plugin;
$this->Test->connection = $this->connection;
return $this->Test->bake('Controller', $className);
}
/**
* Outputs and gets the list of possible models or controllers from database
* Interact with the user and get a list of additional helpers
*
* @return array Helpers that the user wants to use.
**/
function doHelpers() {
return $this->_doPropertyChoices(
__("Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?", true),
__("Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'", true)
);
}
/**
* Interact with the user and get a list of additional components
*
* @return array Components the user wants to use.
**/
function doComponents() {
return $this->_doPropertyChoices(
__("Would you like this controller to use any components?", true),
__("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'", true)
);
}
/**
* Common code for property choice handling.
*
* @param string $prompt A yes/no question to precede the list
* @param sting $example A question for a comma separated list, with examples.
* @return array Array of values for property.
**/
function _doPropertyChoices($prompt, $example) {
$proceed = $this->in($prompt, array('y','n'), 'n');
$property = array();
if (strtolower($proceed) == 'y') {
$propertyList = $this->in($example);
$propertyListTrimmed = str_replace(' ', '', $propertyList);
$property = explode(',', $propertyListTrimmed);
}
return array_filter($property);
}
/**
* Outputs and gets the list of possible controllers from database
*
* @param string $useDbConfig Database configuration name
* @param boolean $interactive Whether you are using listAll interactively and want options output.
* @return array Set of controllers
* @access public
*/
function listAll($useDbConfig = 'default') {
$db =& ConnectionManager::getDataSource($useDbConfig);
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
if ($usePrefix) {
$tables = array();
foreach ($db->listSources() as $table) {
if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
$tables[] = substr($table, strlen($usePrefix));
}
function listAll($useDbConfig = null) {
if (is_null($useDbConfig)) {
$useDbConfig = $this->connection;
}
$this->__tables = $this->Model->getAllTables($useDbConfig);
if ($this->interactive == true) {
$this->out(__('Possible Controllers based on your current database:', true));
$this->_controllerNames = array();
$count = count($this->__tables);
for ($i = 0; $i < $count; $i++) {
$this->_controllerNames[] = $this->_controllerName($this->_modelName($this->__tables[$i]));
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
}
} else {
$tables = $db->listSources();
return $this->_controllerNames;
}
if (empty($tables)) {
$this->err(__('Your database does not have any tables.', true));
$this->_stop();
}
$this->__tables = $tables;
$this->out('Possible Controllers based on your current database:');
$this->_controllerNames = array();
$count = count($tables);
for ($i = 0; $i < $count; $i++) {
$this->_controllerNames[] = $this->_controllerName($this->_modelName($tables[$i]));
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
}
return $this->_controllerNames;
return $this->__tables;
}
/**
* Forces the user to specify the controller he wants to bake, and returns the selected controller name.
*
* @param string $useDbConfig Connection name to get a controller name for.
* @return string Controller name
* @access public
*/
function getName() {
$useDbConfig = 'default';
$controllers = $this->listAll($useDbConfig, 'Controllers');
function getName($useDbConfig = null) {
$controllers = $this->listAll($useDbConfig);
$enteredController = '';
while ($enteredController == '') {
$enteredController = $this->in(__("Enter a number from the list above, type in the name of another controller, or 'q' to exit", true), null, 'q');
$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit", true), null, 'q');
if ($enteredController === 'q') {
$this->out(__("Exit", true));
@ -544,8 +429,7 @@ class ControllerTask extends Shell {
}
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
$this->out(__('Error:', true));
$this->out(__("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.", true));
$this->err(__("The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again.", true));
$enteredController = '';
}
}
@ -555,9 +439,9 @@ class ControllerTask extends Shell {
} else {
$controllerName = Inflector::camelize($enteredController);
}
return $controllerName;
}
/**
* Displays help contents
*
@ -568,12 +452,26 @@ class ControllerTask extends Shell {
$this->out("Usage: cake bake controller <arg1> <arg2>...");
$this->hr();
$this->out('Commands:');
$this->out("\n\tcontroller <name>\n\t\tbakes controller with var \$scaffold");
$this->out("\n\tcontroller <name> scaffold\n\t\tbakes controller with scaffold actions.\n\t\t(index, view, add, edit, delete)");
$this->out("\n\tcontroller <name> scaffold admin\n\t\tbakes a controller with scaffold actions for both public and Configure::read('Routing.admin')");
$this->out("\n\tcontroller <name> admin\n\t\tbakes a controller with scaffold actions only for Configure::read('Routing.admin')");
$this->out('');
$this->out("controller <name>");
$this->out("\tbakes controller with var \$scaffold");
$this->out('');
$this->out("controller <name> scaffold");
$this->out("\tbakes controller with scaffold actions.");
$this->out("\t(index, view, add, edit, delete)");
$this->out('');
$this->out("controller <name> scaffold admin");
$this->out("\tbakes a controller with scaffold actions for both public");
$this->out("\tand Configure::read('Routing.admin')");
$this->out('');
$this->out("controller <name> admin");
$this->out("\tbakes a controller with scaffold actions only for");
$this->out("\tConfigure::read('Routing.admin')");
$this->out('');
$this->out("controller all");
$this->out("\tbakes all controllers with CRUD methods.");
$this->out("");
$this->_stop();
}
}
?>
?>

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* The DbConfig Task handles creating and updating the database.php
*
@ -8,25 +7,20 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs.tasks
* @since CakePHP(tm) v 1.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
if (!class_exists('File')) {
uses('file');
}
/**
* Task class for creating and updating the database configuration file.
*
@ -34,6 +28,7 @@ if (!class_exists('File')) {
* @subpackage cake.cake.console.libs.tasks
*/
class DbConfigTask extends Shell {
/**
* path to CONFIG directory
*
@ -41,6 +36,7 @@ class DbConfigTask extends Shell {
* @access public
*/
var $path = null;
/**
* Default configuration settings to use
*
@ -52,6 +48,15 @@ class DbConfigTask extends Shell {
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null
);
/**
* String name of the database config class name.
* Used for testing.
*
* @var string
**/
var $databaseClassName = 'DATABASE_CONFIG';
/**
* initialization callback
*
@ -61,6 +66,7 @@ class DbConfigTask extends Shell {
function initialize() {
$this->path = $this->params['working'] . DS . 'config' . DS;
}
/**
* Execution method always used for tasks
*
@ -72,6 +78,7 @@ class DbConfigTask extends Shell {
$this->_stop();
}
}
/**
* Interactive interface
*
@ -92,35 +99,27 @@ class DbConfigTask extends Shell {
if (preg_match('/[^a-z0-9_]/i', $name)) {
$name = '';
$this->out('The name may only contain unaccented latin characters, numbers or underscores');
}
else if (preg_match('/^[^a-z_]/i', $name)) {
} else if (preg_match('/^[^a-z_]/i', $name)) {
$name = '';
$this->out('The name must start with an unaccented latin character or an underscore');
}
}
$driver = '';
while ($driver == '') {
$driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'mysqli', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql');
}
$persistent = '';
while ($persistent == '') {
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
}
$driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'mysqli', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql');
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
if (low($persistent) == 'n') {
$persistent = 'false';
} else {
$persistent = 'true';
}
$host = '';
$host = '';
while ($host == '') {
$host = $this->in('Database Host:', null, 'localhost');
}
$port = '';
$port = '';
while ($port == '') {
$port = $this->in('Port?', null, 'n');
}
@ -128,8 +127,8 @@ class DbConfigTask extends Shell {
if (low($port) == 'n') {
$port = null;
}
$login = '';
$login = '';
while ($login == '') {
$login = $this->in('User:', null, 'root');
}
@ -141,43 +140,39 @@ class DbConfigTask extends Shell {
if ($password == '') {
$blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
if ($blank == 'y')
{
if ($blank == 'y') {
$blankPassword = true;
}
}
}
$database = '';
$database = '';
while ($database == '') {
$database = $this->in('Database Name:', null, 'cake');
}
$prefix = '';
$prefix = '';
while ($prefix == '') {
$prefix = $this->in('Table Prefix?', null, 'n');
}
if (low($prefix) == 'n') {
$prefix = null;
}
$encoding = '';
$encoding = '';
while ($encoding == '') {
$encoding = $this->in('Table encoding?', null, 'n');
}
if (low($encoding) == 'n') {
$encoding = null;
}
$schema = '';
$schema = '';
if ($driver == 'postgres') {
while ($schema == '') {
$schema = $this->in('Table schema?', null, 'n');
}
}
if (low($schema) == 'n') {
$schema = null;
}
@ -199,6 +194,7 @@ class DbConfigTask extends Shell {
config('database');
return true;
}
/**
* Output verification message and bake if it looks good
*
@ -240,11 +236,12 @@ class DbConfigTask extends Shell {
$this->hr();
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
if (strtolower($looksGood) == 'y') {
return $config;
}
return false;
}
/**
* Assembles and writes database.php
*
@ -262,7 +259,7 @@ class DbConfigTask extends Shell {
$oldConfigs = array();
if (file_exists($filename)) {
$db = new DATABASE_CONFIG;
$db = new $this->databaseClassName;
$temp = get_class_vars(get_class($db));
foreach ($temp as $configName => $info) {
@ -346,8 +343,28 @@ class DbConfigTask extends Shell {
$out .= "}\n";
$out .= "?>";
$filename = $this->path.'database.php';
$filename = $this->path . 'database.php';
return $this->createFile($filename, $out);
}
/**
* Get a user specified Connection name
*
* @return void
**/
function getConfig() {
$useDbConfig = 'default';
$configs = get_class_vars($this->databaseClassName);
if (!is_array($configs)) {
return $this->execute();
}
$connections = array_keys($configs);
if (count($connections) > 1) {
$useDbConfig = $this->in(__('Use Database Config', true) .':', $connections, 'default');
}
return $useDbConfig;
}
}
?>

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -8,22 +7,20 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs
* @since CakePHP(tm) v 1.2.0.5012
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Only used when -debug option
*/
@ -51,6 +48,7 @@
$categoryEcho = __c('Category string lookup line echo __c()', 5);
ob_end_clean();
/**
* Language string extractor
*
@ -58,6 +56,7 @@
* @subpackage cake.cake.console.libs
*/
class ExtractTask extends Shell{
/**
* Path to use when looking for strings
*
@ -65,6 +64,7 @@ class ExtractTask extends Shell{
* @access public
*/
var $path = null;
/**
* Files from where to extract
*
@ -72,6 +72,7 @@ class ExtractTask extends Shell{
* @access public
*/
var $files = array();
/**
* Filename where to deposit translations
*
@ -79,6 +80,7 @@ class ExtractTask extends Shell{
* @access private
*/
var $__filename = 'default';
/**
* True if all strings should be merged into one file
*
@ -86,6 +88,7 @@ class ExtractTask extends Shell{
* @access private
*/
var $__oneFile = true;
/**
* Current file being processed
*
@ -93,6 +96,7 @@ class ExtractTask extends Shell{
* @access private
*/
var $__file = null;
/**
* Extracted tokens
*
@ -100,6 +104,7 @@ class ExtractTask extends Shell{
* @access private
*/
var $__tokens = array();
/**
* Extracted strings
*
@ -107,6 +112,7 @@ class ExtractTask extends Shell{
* @access private
*/
var $__strings = array();
/**
* History of file versions
*
@ -114,6 +120,7 @@ class ExtractTask extends Shell{
* @access private
*/
var $__fileVersions = array();
/**
* Destination path
*
@ -121,6 +128,7 @@ class ExtractTask extends Shell{
* @access private
*/
var $__output = null;
/**
* Execution method always used for tasks
*
@ -180,6 +188,7 @@ class ExtractTask extends Shell{
}
$this->__extract();
}
/**
* Extract text
*
@ -212,6 +221,7 @@ class ExtractTask extends Shell{
}
$this->__extractTokens();
}
/**
* Show help options
*
@ -237,6 +247,7 @@ class ExtractTask extends Shell{
$this->out(__(' -debug: Perform self test.', true));
$this->out('');
}
/**
* Extract tokens out of all files to be processed
*
@ -281,6 +292,7 @@ class ExtractTask extends Shell{
$this->__writeFiles();
$this->out('Done.');
}
/**
* Will parse __(), __c() functions
*
@ -316,6 +328,7 @@ class ExtractTask extends Shell{
$count++;
}
}
/**
* Will parse __d(), __dc(), __n(), __dn(), __dcn()
*
@ -402,6 +415,7 @@ class ExtractTask extends Shell{
$count++;
}
}
/**
* Build the translate template file contents out of obtained strings
*
@ -464,6 +478,7 @@ class ExtractTask extends Shell{
$this->__store($filename, $output, $fileList);
}
}
/**
* Prepare a file to be stored
*
@ -491,6 +506,7 @@ class ExtractTask extends Shell{
return $storage;
}
}
/**
* Write the files that need to be stored
*
@ -539,6 +555,7 @@ class ExtractTask extends Shell{
fclose($fp);
}
}
/**
* Merge output files
*
@ -565,6 +582,7 @@ class ExtractTask extends Shell{
}
return $output;
}
/**
* Build the translation template header
*
@ -590,6 +608,7 @@ class ExtractTask extends Shell{
$output .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n\n";
return $output;
}
/**
* Find the version number of a file looking for SVN commands
*
@ -604,6 +623,7 @@ class ExtractTask extends Shell{
$this->__fileVersions[$file] = $version;
}
}
/**
* Format a string to be added as a translateable string
*
@ -622,6 +642,7 @@ class ExtractTask extends Shell{
$string = str_replace("\r\n", "\n", $string);
return addcslashes($string, "\0..\37\\\"");
}
/**
* Indicate an invalid marker on a processed file
*
@ -654,6 +675,7 @@ class ExtractTask extends Shell{
}
$this->out("\n", true);
}
/**
* Search the specified path for files that may contain translateable strings
*

View file

@ -0,0 +1,427 @@
<?php
/**
* The FixtureTask handles creating and updating fixture files.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs.tasks
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Task class for creating and updating fixtures files.
*
* @package cake
* @subpackage cake.cake.console.libs.tasks
*/
class FixtureTask extends Shell {
/**
* Name of plugin
*
* @var string
* @access public
*/
var $plugin = null;
/**
* Tasks to be loaded by this Task
*
* @var array
* @access public
*/
var $tasks = array('DbConfig', 'Model', 'Template');
/**
* path to fixtures directory
*
* @var string
* @access public
*/
var $path = null;
/**
* The db connection being used for baking
*
* @var string
**/
var $connection = null;
/**
* Schema instance
*
* @var object
**/
var $_Schema = null;
/**
* Override initialize
*
* @access public
*/
function __construct(&$dispatch) {
parent::__construct($dispatch);
$this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
if (!class_exists('CakeSchema')) {
App::import('Model', 'CakeSchema', false);
}
}
/**
* Execution method always used for tasks
* Handles dispatching to interactive, named, or all processess.
*
* @access public
*/
function execute() {
if (empty($this->args)) {
$this->__interactive();
}
if (isset($this->args[0])) {
if (!isset($this->connection)) {
$this->connection = 'default';
}
if (strtolower($this->args[0]) == 'all') {
return $this->all();
}
$model = Inflector::camelize($this->args[0]);
$this->bake($model);
}
}
/**
* Bake All the Fixtures at once. Will only bake fixtures for models that exist.
*
* @access public
* @return void
**/
function all() {
$this->interactive = false;
$tables = $this->Model->listAll($this->connection, false);
foreach ($tables as $table) {
$model = $this->_modelName($table);
$this->bake($model);
}
}
/**
* Interactive baking function
*
* @access private
*/
function __interactive() {
$this->interactive = true;
$this->hr();
$this->out(sprintf("Bake Fixture\nPath: %s", $this->path));
$this->hr();
$useDbConfig = $this->connection;
if (!isset($this->connection)) {
$this->connection = $this->DbConfig->getConfig();
}
$modelName = $this->Model->getName($this->connection);
$useTable = $this->Model->getTable($modelName, $this->connection);
$importOptions = $this->importOptions($modelName);
$this->bake($modelName, $useTable, $importOptions);
}
/**
* Interacts with the User to setup an array of import options. For a fixture.
*
* @param string $modelName Name of model you are dealing with.
* @return array Array of import options.
**/
function importOptions($modelName) {
$options = array();
$doSchema = $this->in(__('Would you like to import schema for this fixture?', true), array('y', 'n'), 'n');
if ($doSchema == 'y') {
$options['schema'] = $modelName;
}
$doRecords = $this->in(__('Would you like to use record importing for this fixture?', true), array('y', 'n'), 'n');
if ($doRecords == 'y') {
$options['records'] = true;
}
if ($doRecords == 'n') {
$prompt = sprintf(__("Would you like to build this fixture with data from %s's table?", true), $modelName);
$fromTable = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($fromTable) == 'y') {
$options['fromTable'] = true;
}
}
return $options;
}
/**
* Assembles and writes a Fixture file
*
* @param string $model Name of model to bake.
* @param string $useTable Name of table to use.
* @param array $importOptions Options for var $import
* @return string Baked fixture
* @access private
*/
function bake($model, $useTable = false, $importOptions = array()) {
$table = $schema = $records = $import = $modelImport = $recordImport = null;
if (!$useTable) {
$useTable = Inflector::tableize($model);
} elseif ($useTable != Inflector::tableize($model)) {
$table = $useTable;
}
if (!empty($importOptions)) {
if (isset($importOptions['schema'])) {
$modelImport = "'model' => '{$importOptions['schema']}'";
}
if (isset($importOptions['records'])) {
$recordImport = "'records' => true";
}
if ($modelImport && $recordImport) {
$modelImport .= ', ';
}
if (!empty($modelImport) || !empty($recordImport)) {
$import = sprintf("array(%s%s)", $modelImport, $recordImport);
}
}
$this->_Schema = new CakeSchema();
$data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection));
if (!isset($data['tables'][$useTable])) {
$this->err('Could not find your selected table ' . $useTable);
return false;
}
$tableInfo = $data['tables'][$useTable];
if (is_null($modelImport)) {
$schema = $this->_generateSchema($tableInfo);
}
if (!isset($importOptions['records']) && !isset($importOptions['fromTable'])) {
$recordCount = 1;
if (isset($this->params['count'])) {
$recordCount = $this->params['count'];
}
$records = $this->_makeRecordString($this->_generateRecords($tableInfo, $recordCount));
}
if (isset($importOptions['fromTable'])) {
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
}
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields'));
return $out;
}
/**
* Generate the fixture file, and write to disk
*
* @param string $model name of the model being generated
* @param string $fixture Contents of the fixture file.
* @access public
* @return void
**/
function generateFixtureFile($model, $otherVars) {
$defaults = array('table' => null, 'schema' => null, 'records' => null, 'import' => null, 'fields' => null);
$vars = array_merge($defaults, $otherVars);
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'fixtures' . DS;
}
$filename = Inflector::underscore($model) . '_fixture.php';
$this->Template->set('model', $model);
$this->Template->set($vars);
$content = $this->Template->generate('classes', 'fixture');
$this->out("\nBaking test fixture for $model...");
$this->createFile($path . $filename, $content);
return $content;
}
/**
* Generates a string representation of a schema.
*
* @param array $table Table schema array
* @return string fields definitions
**/
function _generateSchema($tableInfo) {
$cols = array();
$out = "array(\n";
foreach ($tableInfo as $field => $fieldInfo) {
if (is_array($fieldInfo)) {
if ($field != 'indexes') {
$col = "\t\t'{$field}' => array('type'=>'" . $fieldInfo['type'] . "', ";
$col .= join(', ', $this->_Schema->__values($fieldInfo));
} else {
$col = "\t\t'indexes' => array(";
$props = array();
foreach ((array)$fieldInfo as $key => $index) {
$props[] = "'{$key}' => array(".join(', ', $this->_Schema->__values($index)).")";
}
$col .= join(', ', $props);
}
$col .= ")";
$cols[] = $col;
}
}
$out .= join(",\n", $cols);
$out .= "\n\t)";
return $out;
}
/**
* Generate String representation of Records
*
* @param array $table Table schema array
* @return array Array of records to use in the fixture.
**/
function _generateRecords($tableInfo, $recordCount = 1) {
$records = array();
for ($i = 0; $i < $recordCount; $i++) {
$record = array();
foreach ($tableInfo as $field => $fieldInfo) {
if (empty($fieldInfo['type'])) {
continue;
}
switch ($fieldInfo['type']) {
case 'integer':
$insert = $i + 1;
break;
case 'string';
$isPrimaryUuid = (
isset($fieldInfo['key']) && strtolower($fieldInfo['key']) == 'primary' &&
isset($fieldInfo['length']) && $fieldInfo['length'] == 36
);
if ($isPrimaryUuid) {
$insert = String::uuid();
} else {
$insert = "Lorem ipsum dolor sit amet";
if (!empty($fieldInfo['length'])) {
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
}
}
$insert = "'$insert'";
break;
case 'timestamp':
$ts = time();
$insert = "'$ts'";
break;
case 'datetime':
$ts = date('Y-m-d H:i:s');
$insert = "'$ts'";
break;
case 'date':
$ts = date('Y-m-d');
$insert = "'$ts'";
break;
case 'time':
$ts = date('H:i:s');
$insert = "'$ts'";
break;
case 'boolean':
$insert = 1;
break;
case 'text':
$insert = "'Lorem ipsum dolor sit amet, aliquet feugiat.";
$insert .= " Convallis morbi fringilla gravida,";
$insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
$insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
$insert .= " vestibulum massa neque ut et, id hendrerit sit,";
$insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
$insert .= " duis vestibulum nunc mattis convallis.'";
break;
}
$record[$field] = $insert;
}
$records[] = $record;
}
return $records;
}
/**
* Convert a $records array into a a string.
*
* @param array $records Array of records to be converted to string
* @return string A string value of the $records array.
**/
function _makeRecordString($records) {
$out = "array(\n";
foreach ($records as $record) {
$values = array();
foreach ($record as $field => $value) {
$values[] = "\t\t\t'$field' => $value";
}
$out .= "\t\tarray(\n";
$out .= implode(",\n", $values);
$out .= "\n\t\t),\n";
}
$out .= "\t)";
return $out;
}
/**
* Interact with the user to get a custom SQL condition and use that to extract data
* to build a fixture.
*
* @param string $modelName name of the model to take records from.
* @param string $useTable Name of table to use.
* @return array Array of records.
**/
function _getRecordsFromTable($modelName, $useTable = null) {
$condition = null;
$prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true);
while (!$condition) {
$condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
}
App::import('Model', 'Model', false);
$modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
$records = $modelObject->find('all', array(
'conditions' => $condition,
'recursive' => -1
));
$db =& $modelObject->getDataSource();
$schema = $modelObject->schema();
$out = array();
foreach ($records as $record) {
$row = array();
foreach ($record[$modelObject->alias] as $field => $value) {
$row[$field] = $db->value($value, $schema[$field]['type']);
}
$out[] = $row;
}
return $out;
}
/**
* Displays help contents
*
* @access public
*/
function help() {
$this->hr();
$this->out("Usage: cake bake fixture <arg1> <params>");
$this->hr();
$this->out('Commands:');
$this->out("\nfixture <name>\n\tbakes fixture with specified name.");
$this->out("\nfixture all\n\tbakes all fixtures.");
$this->out("");
$this->out('Parameters:');
$this->out("\t-count When using generated data, the number of records to include in the fixture(s).");
$this->out("\t-connection Which database configuration to use for baking.");
$this->out("\t-plugin lowercased_underscored name of plugin to bake fixtures for.");
$this->out("");
$this->_stop();
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* The Plugin Task handles creating an empty plugin, ready to be used
*
@ -8,25 +7,20 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs.tasks
* @since CakePHP(tm) v 1.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
if (!class_exists('File')) {
uses('file');
}
/**
* Task class for creating a plugin
*
@ -34,11 +28,13 @@ if (!class_exists('File')) {
* @subpackage cake.cake.console.libs.tasks
*/
class PluginTask extends Shell {
/**
* Tasks
*
*/
var $tasks = array('Model', 'Controller', 'View');
/**
* path to CONTROLLERS directory
*
@ -46,6 +42,7 @@ class PluginTask extends Shell {
* @access public
*/
var $path = null;
/**
* initialize
*
@ -54,6 +51,7 @@ class PluginTask extends Shell {
function initialize() {
$this->path = APP . 'plugins' . DS;
}
/**
* Execution method always used for tasks
*
@ -62,27 +60,27 @@ class PluginTask extends Shell {
function execute() {
if (empty($this->params['skel'])) {
$this->params['skel'] = '';
if (is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) {
$this->params['skel'] = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel') === true) {
$this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel';
}
}
$plugin = null;
if (isset($this->args[0])) {
$plugin = Inflector::camelize($this->args[0]);
$pluginPath = Inflector::underscore($plugin) . DS;
$pluginPath = $this->_pluginPath($plugin);
$this->Dispatch->shiftArgs();
if (is_dir($this->path . $pluginPath)) {
$this->out(sprintf('Plugin: %s', $plugin));
$this->out(sprintf('Path: %s', $this->path . $pluginPath));
$this->hr();
if (is_dir($pluginPath)) {
$this->out(sprintf(__('Plugin: %s', true), $plugin));
$this->out(sprintf(__('Path: %s', true), $pluginPath));
} elseif (isset($this->args[0])) {
$this->err(sprintf('%s in path %s not found.', $plugin, $this->path . $pluginPath));
$this->err(sprintf(__('%s in path %s not found.', true), $plugin, $pluginPath));
$this->_stop();
} else {
$this->__interactive($plugin);
}
} else {
return $this->__interactive();
}
if (isset($this->args[0])) {
@ -90,13 +88,13 @@ class PluginTask extends Shell {
$this->Dispatch->shiftArgs();
if (in_array($task, $this->tasks)) {
$this->{$task}->plugin = $plugin;
$this->{$task}->path = $this->path . $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS;
$this->{$task}->path = $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS;
if (!is_dir($this->{$task}->path)) {
$this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
}
$this->{$task}->loadTasks();
$this->{$task}->execute();
return $this->{$task}->execute();
}
}
}
@ -125,28 +123,49 @@ class PluginTask extends Shell {
* @return bool
*/
function bake($plugin) {
$pluginPath = Inflector::underscore($plugin);
$pathOptions = App::path('plugins');
if (count($pathOptions) > 1) {
$this->findPath($pathOptions);
}
$this->hr();
$this->out("Plugin Name: $plugin");
$this->out("Plugin Directory: {$this->path}{$pluginPath}");
$this->out(sprintf(__("Plugin Name: %s", true), $plugin));
$this->out(sprintf(__("Plugin Directory: %s", true), $this->path . $pluginPath));
$this->hr();
$looksGood = $this->in(__('Look okay?', true), array('y', 'n', 'q'), 'y');
$looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
if (strtolower($looksGood) == 'y') {
$verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');
$Folder = new Folder($this->path . $pluginPath);
$directories = array('models' . DS . 'behaviors', 'controllers' . DS . 'components', 'views' . DS . 'helpers');
$Folder =& new Folder($this->path . $pluginPath);
$directories = array(
'config' . DS . 'sql',
'models' . DS . 'behaviors',
'controllers' . DS . 'components',
'views' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'components',
'tests' . DS . 'cases' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'behaviors',
'tests' . DS . 'cases' . DS . 'controllers',
'tests' . DS . 'cases' . DS . 'models',
'tests' . DS . 'groups',
'tests' . DS . 'fixtures',
'vendors' . DS . 'img',
'vendors' . DS . 'js',
'vendors' . DS . 'css',
'vendors' . DS . 'shells'
);
foreach ($directories as $directory) {
$Folder->create($this->path . $pluginPath . DS . $directory);
$dirPath = $this->path . $pluginPath . DS . $directory;
$Folder->create($dirPath);
$File =& new File($dirPath . DS . 'empty', true);
}
if (low($verbose) == 'y' || low($verbose) == 'yes') {
if (strtolower($verbose) == 'y') {
foreach ($Folder->messages() as $message) {
$this->out($message);
}
@ -180,6 +199,28 @@ class PluginTask extends Shell {
return true;
}
/**
* find and change $this->path to the user selection
*
* @return void
**/
function findPath($pathOptions) {
$valid = false;
$max = count($pathOptions);
while (!$valid) {
foreach ($pathOptions as $i => $option) {
$this->out($i + 1 .'. ' . $option);
}
$prompt = __('Choose a plugin path from the paths above.', true);
$choice = $this->in($prompt);
if (intval($choice) > 0 && intval($choice) <= $max) {
$valid = true;
}
}
$this->path = $pathOptions[$choice - 1];
}
/**
* Help
*
@ -191,10 +232,18 @@ class PluginTask extends Shell {
$this->out("Usage: cake bake plugin <arg1> <arg2>...");
$this->hr();
$this->out('Commands:');
$this->out("\n\tplugin <name>\n\t\tbakes plugin directory structure");
$this->out("\n\tplugin <name> model\n\t\tbakes model. Run 'cake bake model help' for more info.");
$this->out("\n\tplugin <name> controller\n\t\tbakes controller. Run 'cake bake controller help' for more info.");
$this->out("\n\tplugin <name> view\n\t\tbakes view. Run 'cake bake view help' for more info.");
$this->out('');
$this->out("plugin <name>");
$this->out("\tbakes plugin directory structure");
$this->out('');
$this->out("plugin <name> model");
$this->out("\tbakes model. Run 'cake bake model help' for more info.");
$this->out('');
$this->out("plugin <name> controller");
$this->out("\tbakes controller. Run 'cake bake controller help' for more info.");
$this->out('');
$this->out("plugin <name> view");
$this->out("\tbakes view. Run 'cake bake view help' for more info.");
$this->out("");
$this->_stop();
}

View file

@ -1,32 +1,25 @@
<?php
/* SVN FILE: $Id$ */
/**
* The Project Task handles creating the base application
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.scripts.bake
* @subpackage cake.cake.console.bake
* @since CakePHP(tm) v 1.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
if (!class_exists('File')) {
uses('file');
}
/**
* Task class for creating new project apps and plugins
*
@ -34,6 +27,14 @@ if (!class_exists('File')) {
* @subpackage cake.cake.console.libs.tasks
*/
class ProjectTask extends Shell {
/**
* configs path (used in testing).
*
* @var string
**/
var $configPath = null;
/**
* Checks that given project path does not already exist, and
* finds the app directory in it. Then it calls bake() with that information.
@ -68,7 +69,7 @@ class ProjectTask extends Shell {
if ($project) {
$response = false;
while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
$response = $this->in('A project already exists in this location: '.$project.' Overwrite?', array('y','n'), 'n');
$response = $this->in('A project already exists in this location: ' . $project . ' Overwrite?', array('y','n'), 'n');
if (strtolower($response) === 'n') {
$response = $project = false;
}
@ -108,6 +109,7 @@ class ProjectTask extends Shell {
return true;
}
}
/**
* Looks for a skeleton template of a Cake application,
* and if not found asks the user for a path. When there is a path
@ -144,7 +146,7 @@ class ProjectTask extends Shell {
$looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
if (strtolower($looksGood) == 'y') {
$verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');
$Folder = new Folder($skel);
@ -153,24 +155,25 @@ class ProjectTask extends Shell {
$this->out(sprintf(__("Created: %s in %s", true), $app, $path));
$this->hr();
} else {
$this->err(" '".$app."' could not be created properly");
$this->err(" '" . $app . "' could not be created properly");
return false;
}
if (low($verbose) == 'y' || low($verbose) == 'yes') {
if (strtolower($verbose) == 'y') {
foreach ($Folder->messages() as $message) {
$this->out($message);
}
}
return true;
} elseif (low($looksGood) == 'q' || low($looksGood) == 'quit') {
} elseif (strtolower($looksGood) == 'q') {
$this->out('Bake Aborted.');
} else {
$this->execute(false);
return false;
}
}
/**
* Writes a file with a default home page to the project.
*
@ -181,9 +184,10 @@ class ProjectTask extends Shell {
function createHome($dir) {
$app = basename($dir);
$path = $dir . 'views' . DS . 'pages' . DS;
include(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'views'.DS.'home.ctp');
include(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'default'.DS.'views'.DS.'home.ctp');
return $this->createFile($path.'home.ctp', $output);
}
/**
* Generates and writes 'Security.salt'
*
@ -207,6 +211,7 @@ class ProjectTask extends Shell {
}
return false;
}
/**
* Generates and writes CAKE_CORE_INCLUDE_PATH
*
@ -219,7 +224,7 @@ class ProjectTask extends Shell {
$File =& new File($path . 'webroot' . DS . 'index.php');
$contents = $File->read();
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents);
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents);
if (!$File->write($result)) {
return false;
}
@ -230,7 +235,7 @@ class ProjectTask extends Shell {
$File =& new File($path . 'webroot' . DS . 'test.php');
$contents = $File->read();
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents);
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents);
if (!$File->write($result)) {
return false;
}
@ -240,6 +245,7 @@ class ProjectTask extends Shell {
return true;
}
}
/**
* Enables Configure::read('Routing.admin') in /app/config/core.php
*
@ -248,7 +254,8 @@ class ProjectTask extends Shell {
* @access public
*/
function cakeAdmin($name) {
$File =& new File(CONFIGS . 'core.php');
$path = (empty($this->configPath)) ? CONFIGS : $this->configPath;
$File =& new File($path . 'core.php');
$contents = $File->read();
if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.admin\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) {
$result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.admin\', \''.$name.'\');', $contents);
@ -262,6 +269,34 @@ class ProjectTask extends Shell {
return false;
}
}
/**
* Checks for Configure::read('Routing.admin') and forces user to input it if not enabled
*
* @return string Admin route to use
* @access public
*/
function getAdmin() {
$admin = '';
$cakeAdmin = null;
$adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute)) {
return $adminRoute . '_';
}
$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
$this->out('What would you like the admin route to be?');
$this->out('Example: www.example.com/admin/controller');
while ($admin == '') {
$admin = $this->in("What would you like the admin route to be?", null, 'admin');
}
if ($this->cakeAdmin($admin) !== true) {
$this->out('Unable to write to /app/config/core.php.');
$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
$this->_stop();
}
return $admin . '_';
}
/**
* Help
*
@ -273,7 +308,10 @@ class ProjectTask extends Shell {
$this->out("Usage: cake bake project <arg1>");
$this->hr();
$this->out('Commands:');
$this->out("\n\tproject <name>\n\t\tbakes app directory structure.\n\t\tif <name> begins with '/' path is absolute.");
$this->out('');
$this->out("project <name>");
$this->out("\tbakes app directory structure.");
$this->out("\tif <name> begins with '/' path is absolute.");
$this->out("");
$this->_stop();
}

View file

@ -0,0 +1,191 @@
<?php
/**
* Template Task can generate templated output Used in other Tasks
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.console.libs.tasks
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class TemplateTask extends Shell {
/**
* variables to add to template scope
*
* @var array
**/
var $templateVars = array();
/**
* Paths to look for templates on.
* Contains a list of $theme => $path
*
* @var array
**/
var $templatePaths = array();
/**
* Initialize callback. Setup paths for the template task.
*
* @access public
* @return void
**/
function initialize() {
$this->templatePaths = $this->_findThemes();
}
/**
* Find the paths to all the installed shell themes in the app.
*
* Bake themes are directories not named `skel` inside a `vendors/shells/templates` path.
*
* @return array Array of bake themes that are installed.
**/
function _findThemes() {
$paths = $this->Dispatch->shellPaths;
$themes = array();
foreach ($paths as $path) {
$Folder =& new Folder($path . 'templates', false);
$contents = $Folder->read();
$subDirs = $contents[0];
foreach ($subDirs as $dir) {
if (empty($dir) || $dir == 'skel') {
continue;
}
$templateDir = $path . 'templates' . DS . $dir . DS;
$themes[$dir] = $templateDir;
}
}
return $themes;
}
/**
* Set variable values to the template scope
*
* @param mixed $one A string or an array of data.
* @param mixed $two Value in case $one is a string (which then works as the key).
* Unused if $one is an associative array, otherwise serves as the values to $one's keys.
* @return void
*/
function set($one, $two = null) {
$data = null;
if (is_array($one)) {
if (is_array($two)) {
$data = array_combine($one, $two);
} else {
$data = $one;
}
} else {
$data = array($one => $two);
}
if ($data == null) {
return false;
}
foreach ($data as $name => $value) {
$this->templateVars[$name] = $value;
}
}
/**
* Runs the template
*
* @param string $directory directory / type of thing you want
* @param string $filename template name
* @param string $vars Additional vars to set to template scope.
* @access public
* @return contents of generated code template
**/
function generate($directory, $filename, $vars = null) {
if ($vars !== null) {
$this->set($vars);
}
if (empty($this->templatePaths)) {
$this->initialize();
}
$themePath = $this->getThemePath();
$templateFile = $this->_findTemplate($themePath, $directory, $filename);
if ($templateFile) {
extract($this->templateVars);
ob_start();
ob_implicit_flush(0);
include($templateFile);
$content = ob_get_clean();
return $content;
}
return '';
}
/**
* Find the theme name for the current operation.
* If there is only one theme in $templatePaths it will be used.
* If there is a -theme param in the cli args, it will be used.
* If there is more than one installed theme user interaction will happen
*
* @return string returns the path to the selected theme.
**/
function getThemePath() {
if (count($this->templatePaths) == 1) {
$paths = array_values($this->templatePaths);
return $paths[0];
}
if (!empty($this->params['theme']) && isset($this->templatePaths[$this->params['theme']])) {
return $this->templatePaths[$this->params['theme']];
}
$this->hr();
$this->out(__('You have more than one set of templates installed.', true));
$this->out(__('Please choose the template set you wish to use:', true));
$this->hr();
$i = 1;
$indexedPaths = array();
foreach ($this->templatePaths as $key => $path) {
$this->out($i . '. ' . $key);
$indexedPaths[$i] = $path;
$i++;
}
$index = $this->in(__('Which bake theme would you like to use?', true), range(1, $i - 1), 1);
$themeNames = array_keys($this->templatePaths);
$this->Dispatch->params['theme'] = $themeNames[$index - 1];
return $indexedPaths[$index];
}
/**
* Find a template inside a directory inside a path.
* Will scan all other theme dirs if the template is not found in the first directory.
*
* @param string $path The initial path to look for the file on. If it is not found fallbacks will be used.
* @param string $directory Subdirectory to look for ie. 'views', 'objects'
* @param string $filename lower_case_underscored filename you want.
* @access public
* @return string filename will exit program if template is not found.
**/
function _findTemplate($path, $directory, $filename) {
$themeFile = $path . $directory . DS . $filename . '.ctp';
if (file_exists($themeFile)) {
return $themeFile;
}
foreach ($this->templatePaths as $path) {
$templatePath = $path . $directory . DS . $filename . '.ctp';
if (file_exists($templatePath)) {
return $templatePath;
}
}
$this->err(sprintf(__('Could not find template for %s', true), $filename));
$this->_stop();
return false;
}
}
?>

View file

@ -1,29 +1,24 @@
<?php
/* SVN FILE: $Id$ */
/**
* The TestTask handles creating and updating test files.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs.tasks
* @since CakePHP(tm) v 1.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Task class for creating and updating test files.
*
@ -31,6 +26,7 @@
* @subpackage cake.cake.console.libs.tasks
*/
class TestTask extends Shell {
/**
* Name of plugin
*
@ -38,6 +34,7 @@ class TestTask extends Shell {
* @access public
*/
var $plugin = null;
/**
* path to TESTS directory
*
@ -45,6 +42,35 @@ class TestTask extends Shell {
* @access public
*/
var $path = TESTS;
/**
* Tasks used.
*
* @var array
**/
var $tasks = array('Template');
/**
* class types that methods can be generated for
*
* @var array
**/
var $classTypes = array('Model', 'Controller', 'Component', 'Behavior', 'Helper');
/**
* Internal list of fixtures that have been added so far.
*
* @var string
**/
var $_fixtures = array();
/**
* Flag for interactive mode
*
* @var boolean
**/
var $interactive = false;
/**
* Execution method always used for tasks
*
@ -60,144 +86,332 @@ class TestTask extends Shell {
}
if (count($this->args) > 1) {
$class = Inflector::underscore($this->args[0]);
if ($this->bake($class, $this->args[1])) {
$type = Inflector::underscore($this->args[0]);
if ($this->bake($type, $this->args[1])) {
$this->out('done');
}
}
}
/**
* Handles interactive baking
*
* @access private
*/
function __interactive($class = null) {
function __interactive($type = null) {
$this->interactive = true;
$this->hr();
$this->out(sprintf("Bake Tests\nPath: %s", $this->path));
$this->out(__('Bake Tests', true));
$this->out(sprintf(__("Path: %s", true), $this->path));
$this->hr();
$key = null;
$options = array('Behavior', 'Helper', 'Component', 'Model', 'Controller');
if ($class !== null) {
$class = Inflector::camelize($class);
if (in_array($class, $options)) {
$key = array_search($class);
$selection = null;
if ($type) {
$type = Inflector::camelize($type);
if (!in_array($type, $this->classTypes)) {
unset($type);
}
}
while ($class == null) {
$cases = array();
$this->hr();
$this->out("Select a class:");
$this->hr();
$keys = array();
foreach ($options as $key => $option) {
$this->out(++$key . '. ' . $option);
$keys[] = $key;
}
$keys[] = 'q';
$key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');
if ($key != 'q') {
if (isset($options[--$key])) {
$class = $options[$key];
}
if ($class) {
$name = $this->in(__("Enter the name for the test or (q)uit", true), null, 'q');
if ($name !== 'q') {
$case = null;
while ($case !== 'q') {
$case = $this->in(__("Enter a test case or (q)uit", true), null, 'q');
if ($case !== 'q') {
$cases[] = $case;
}
}
if ($this->bake($class, $name, $cases)) {
$this->out(__("Test baked\n", true));
$type = null;
}
$class = null;
}
}
} else {
$this->_stop();
}
if (!$type) {
$type = $this->getObjectType();
}
$className = $this->getClassName($type);
return $this->bake($type, $className);
}
/**
* Writes File
* Completes final steps for generating data to create test case.
*
* @param string $type Type of object to bake test case for ie. Model, Controller
* @param string $className the 'cake name' for the class ie. Posts for the PostsController
* @access public
*/
function bake($class, $name = null, $cases = array()) {
if (!$name) {
return false;
function bake($type, $className) {
if ($this->typeCanDetectFixtures($type) && $this->isLoadableClass($type, $className)) {
$this->out(__('Bake is detecting possible fixtures..', true));
$testSubject =& $this->buildTestSubject($type, $className);
$this->generateFixtureList($testSubject);
} elseif ($this->interactive) {
$this->getUserFixtures();
}
$fullClassName = $this->getRealClassName($type, $className);
$methods = array();
if (class_exists($fullClassName)) {
$methods = $this->getTestableMethods($fullClassName);
}
$mock = $this->hasMockClass($type, $fullClassName);
$construction = $this->generateConstructor($type, $fullClassName);
$plugin = null;
if ($this->plugin) {
$plugin = $this->plugin . '.';
}
if (!is_array($cases)) {
$cases = array($cases);
}
$this->Template->set('fixtures', $this->_fixtures);
$this->Template->set('plugin', $plugin);
$this->Template->set(compact('className', 'methods', 'type', 'fullClassName', 'mock', 'construction'));
$out = $this->Template->generate('classes', 'test');
if (strpos($this->path, $class) === false) {
$this->filePath = $this->path . 'cases' . DS . Inflector::tableize($class) . DS;
$filename = $this->testCaseFileName($type, $className);
$made = $this->createFile($filename, $out);
if ($made) {
return $out;
}
$class = Inflector::classify($class);
$name = Inflector::classify($name);
$import = $name;
if (isset($this->plugin)) {
$import = $this->plugin . '.' . $name;
}
$extras = $this->__extras($class);
$out = "App::import('$class', '$import');\n";
if ($class == 'Model') {
$class = null;
}
$out .= "class Test{$name} extends {$name}{$class} {\n";
$out .= "{$extras}";
$out .= "}\n\n";
$out .= "class {$name}{$class}Test extends CakeTestCase {\n";
$out .= "\n\tfunction startTest() {";
$out .= "\n\t\t\$this->{$name} = new Test{$name}();";
$out .= "\n\t}\n";
$out .= "\n\tfunction test{$name}Instance() {\n";
$out .= "\t\t\$this->assertTrue(is_a(\$this->{$name}, '{$name}{$class}'));\n\t}\n";
foreach ($cases as $case) {
$case = Inflector::classify($case);
$out .= "\n\tfunction test{$case}() {\n\n\t}\n";
}
$out .= "}\n";
$this->out("Baking unit test for $name...");
$this->out($out);
$ok = $this->in(__('Is this correct?', true), array('y', 'n'), 'y');
if ($ok == 'n') {
return false;
}
$header = '$Id';
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $name ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
return $this->createFile($this->filePath . Inflector::underscore($name) . '.test.php', $content);
return false;
}
/**
* Handles the extra stuff needed
* Interact with the user and get their chosen type. Can exit the script.
*
* @access private
*/
function __extras($class) {
$extras = null;
switch ($class) {
case 'Model':
$extras = "\n\tvar \$cacheSources = false;";
$extras .= "\n\tvar \$useDbConfig = 'test_suite';\n";
break;
* @return string Users chosen type.
**/
function getObjectType() {
$this->hr();
$this->out(__("Select an object type:", true));
$this->hr();
$keys = array();
foreach ($this->classTypes as $key => $option) {
$this->out(++$key . '. ' . $option);
$keys[] = $key;
}
return $extras;
$keys[] = 'q';
$selection = $this->in(__("Enter the type of object to bake a test for or (q)uit", true), $keys, 'q');
if ($selection == 'q') {
return $this->_stop();
}
return $this->classTypes[$selection - 1];
}
/**
* Get the user chosen Class name for the chosen type
*
* @param string $objectType Type of object to list classes for i.e. Model, Controller.
* @return string Class name the user chose.
**/
function getClassName($objectType) {
$options = Configure::listObjects(strtolower($objectType));
$this->out(sprintf(__('Choose a %s class', true), $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', true));
if (isset($options[$selection - 1])) {
return $options[$selection - 1];
}
return $selection;
}
/**
* Checks whether the chosen type can find its own fixtures.
* Currently only model, and controller are supported
*
* @return boolean
**/
function typeCanDetectFixtures($type) {
$type = strtolower($type);
return ($type == 'controller' || $type == 'model');
}
/**
* Check if a class with the given type is loaded or can be loaded.
*
* @return boolean
**/
function isLoadableClass($type, $class) {
return App::import($type, $class);
}
/**
* Construct an instance of the class to be tested.
* So that fixtures can be detected
*
* @return object
**/
function &buildTestSubject($type, $class) {
ClassRegistry::flush();
App::import($type, $class);
$class = $this->getRealClassName($type, $class);
if (strtolower($type) == 'model') {
$instance =& ClassRegistry::init($class);
} else {
$instance =& new $class();
}
return $instance;
}
/**
* Gets the real class name from the cake short form.
*
* @return string Real classname
**/
function getRealClassName($type, $class) {
if (strtolower($type) == 'model') {
return $class;
}
return $class . $type;
}
/**
* Get methods declared in the class given.
* No parent methods will be returned
*
* @param string $className Name of class to look at.
* @return array Array of method names.
**/
function getTestableMethods($className) {
$classMethods = get_class_methods($className);
$parentMethods = get_class_methods(get_parent_class($className));
$thisMethods = array_diff($classMethods, $parentMethods);
$out = array();
foreach ($thisMethods as $method) {
if (substr($method, 0, 1) != '_') {
$out[] = $method;
}
}
return $out;
}
/**
* Generate the list of fixtures that will be required to run this test based on
* loaded models.
*
* @param object The object you want to generate fixtures for.
* @return array Array of fixtures to be included in the test.
**/
function generateFixtureList(&$subject) {
$this->_fixtures = array();
if (is_a($subject, 'Model')) {
$this->_processModel($subject);
} elseif (is_a($subject, 'Controller')) {
$this->_processController($subject);
}
return array_values($this->_fixtures);
}
/**
* Process a model recursively and pull out all the
* model names converting them to fixture names.
*
* @return void
* @access protected
**/
function _processModel(&$subject) {
$this->_addFixture($subject->name);
$associated = $subject->getAssociated();
foreach ($associated as $alias => $type) {
$className = $subject->{$alias}->name;
if (!isset($this->_fixtures[$className])) {
$this->_processModel($subject->{$alias});
}
if ($type == 'hasAndBelongsToMany') {
$joinModel = Inflector::classify($subject->hasAndBelongsToMany[$alias]['joinTable']);
if (!isset($this->_fixtures[$joinModel])) {
$this->_processModel($subject->{$joinModel});
}
}
}
}
/**
* Process all the models attached to a controller
* and generate a fixture list.
*
* @return void
* @access protected
**/
function _processController(&$subject) {
$subject->constructClasses();
$models = array(Inflector::classify($subject->name));
if (!empty($subject->uses)) {
$models = $subject->uses;
}
foreach ($models as $model) {
$this->_processModel($subject->{$model});
}
}
/**
* Add classname to the fixture list.
* Sets the app. or plugin.plugin_name. prefix.
*
* @return void
* @access protected
**/
function _addFixture($name) {
$parent = get_parent_class($name);
$prefix = 'app.';
if (strtolower($parent) != 'appmodel' && strtolower(substr($parent, -8)) == 'appmodel') {
$pluginName = substr($parent, 0, strlen($parent) -8);
$prefix = 'plugin.' . Inflector::underscore($pluginName) . '.';
}
$fixture = $prefix . Inflector::underscore($name);
$this->_fixtures[$name] = $fixture;
}
/**
* Interact with the user to get additional fixtures they want to use.
*
* @return void
**/
function getUserFixtures() {
$proceed = $this->in(__('Bake could not detect fixtures, would you like to add some?', true), 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'", true));
$fixtureListTrimmed = str_replace(' ', '', $fixtureList);
$fixtures = explode(',', $fixtureListTrimmed);
}
$this->_fixtures = array_merge($this->_fixtures, $fixtures);
return $fixtures;
}
/**
* Is a mock class required for this type of test?
* Controllers require a mock class.
*
* @return boolean
**/
function hasMockClass($type) {
$type = strtolower($type);
return $type == 'controller';
}
/**
* Generate a constructor code snippet for the type and classname
*
* @return string Constructor snippet for the thing you are building.
**/
function generateConstructor($type, $fullClassName) {
$type = strtolower($type);
if ($type == 'model') {
return "ClassRegistry::init('$fullClassName');\n";
}
if ($type == 'controller') {
return "new Test$fullClassName();\n\t\t\$this->{$fullClassName}->constructClasses();\n";
}
return "new $fullClassName()\n";
}
/**
* make the filename for the test case. resolve the suffixes for controllers
* and get the plugin path if needed.
*
* @return string filename the test should be created on
**/
function testCaseFileName($type, $className) {
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests' . DS;
}
$path .= 'cases' . DS . Inflector::tableize($type) . DS;
if (strtolower($type) == 'controller') {
$className = $this->getRealClassName($type, $className);
}
return $path . Inflector::underscore($className) . '.test.php';
}
}
?>

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* The View Tasks handles creating and updating view files.
*
@ -8,23 +7,21 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs.tasks
* @since CakePHP(tm) v 1.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'Controller');
App::import('Controller', 'Controller', false);
/**
* Task class for creating and updating view files.
*
@ -32,6 +29,7 @@ App::import('Core', 'Controller');
* @subpackage cake.cake.console.libs.tasks
*/
class ViewTask extends Shell {
/**
* Name of plugin
*
@ -39,13 +37,15 @@ class ViewTask extends Shell {
* @access public
*/
var $plugin = null;
/**
* Tasks to be loaded by this Task
*
* @var array
* @access public
*/
var $tasks = array('Project', 'Controller');
var $tasks = array('Project', 'Controller', 'DbConfig', 'Template');
/**
* path to VIEWS directory
*
@ -53,6 +53,7 @@ class ViewTask extends Shell {
* @access public
*/
var $path = VIEWS;
/**
* Name of the controller being used
*
@ -60,6 +61,7 @@ class ViewTask extends Shell {
* @access public
*/
var $controllerName = null;
/**
* Path to controller to put views
*
@ -67,6 +69,7 @@ class ViewTask extends Shell {
* @access public
*/
var $controllerPath = null;
/**
* The template file to use
*
@ -74,6 +77,7 @@ class ViewTask extends Shell {
* @access public
*/
var $template = null;
/**
* Actions to use for scaffolding
*
@ -81,6 +85,7 @@ class ViewTask extends Shell {
* @access public
*/
var $scaffoldActions = array('index', 'view', 'add', 'edit');
/**
* Override initialize
*
@ -88,6 +93,7 @@ class ViewTask extends Shell {
*/
function initialize() {
}
/**
* Execution method always used for tasks
*
@ -99,6 +105,9 @@ class ViewTask extends Shell {
}
if (isset($this->args[0])) {
if (!isset($this->connection)) {
$this->connection = 'default';
}
$controller = $action = $alias = null;
$this->controllerName = Inflector::camelize($this->args[0]);
$this->controllerPath = Inflector::underscore($this->controllerName);
@ -115,37 +124,92 @@ class ViewTask extends Shell {
$action = $this->template;
}
if (strtolower($this->args[0]) == 'all') {
return $this->all();
}
if (in_array($action, $this->scaffoldActions)) {
$this->bake($action, true);
} elseif ($action) {
$this->bake($action, true);
} else {
$vars = $this->__loadController();
if ($vars) {
$methods = array_diff(
array_map('strtolower', get_class_methods($this->controllerName . 'Controller')),
array_map('strtolower', get_class_methods('appcontroller'))
);
if (empty($methods)) {
$methods = $this->scaffoldActions;
}
$adminDelete = null;
$adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute)) {
$adminDelete = $adminRoute.'_delete';
}
foreach ($methods as $method) {
if ($method{0} != '_' && !in_array($method, array('delete', $adminDelete))) {
$content = $this->getContent($method, $vars);
$this->bake($method, $content);
$methods = $this->_methodsToBake();
$methods = array_diff(
array_map('strtolower', get_class_methods($this->controllerName . 'Controller')),
array_map('strtolower', get_class_methods('appcontroller'))
);
if (empty($methods)) {
$methods = $this->scaffoldActions;
}
$adminRoute = Configure::read('Routing.admin');
if ($adminRoute && isset($this->params['admin'])) {
foreach ($methods as $i => $method) {
if (strpos($method, $adminRoute . '_') === false) {
unset($methods[$i]);
}
}
}
$adminDelete = null;
if (!empty($adminRoute)) {
$adminDelete = $adminRoute . '_delete';
}
foreach ($methods as $method) {
if ($method{0} != '_' && !in_array($method, array('delete', $adminDelete))) {
$content = $this->getContent($method, $vars);
$this->bake($method, $content);
}
}
}
}
}
/**
* Get a list of actions that can / should have views baked for them.
*
* @return array Array of action names that should be baked
**/
function _methodsToBake() {
$methods = array_diff(
array_map('strtolower', get_class_methods($this->controllerName . 'Controller')),
array_map('strtolower', get_class_methods('appcontroller'))
);
if (empty($methods)) {
$methods = $this->scaffoldActions;
}
$adminRoute = Configure::read('Routing.admin');
foreach ($methods as $i => $method) {
if ($method == 'delete' || $method = $adminRoute . '_delete' || $method{0} == '_') {
unset($methods[$i]);
}
if ($adminRoute && isset($this->params['admin']) && strpos($method, $adminRoute . '_') === false) {
unset($methods[$i]);
}
}
return $methods;
}
/**
* Bake All views for All controllers.
*
* @return void
**/
function all() {
$actions = $this->scaffoldActions;
$this->Controller->interactive = false;
$tables = $this->Controller->listAll($this->connection, false);
$this->interactive = false;
foreach ($tables as $table) {
$model = $this->_modelName($table);
$this->controllerName = $this->_controllerName($model);
$this->controllerPath = Inflector::underscore($this->controllerName);
if (App::import('Model', $model)) {
$vars = $this->__loadController();
$this->bakeActions($actions, $vars);
}
}
}
/**
* Handles interactive baking
*
@ -155,72 +219,51 @@ class ViewTask extends Shell {
$this->hr();
$this->out(sprintf("Bake View\nPath: %s", $this->path));
$this->hr();
$wannaDoAdmin = 'n';
$wannaDoScaffold = 'y';
$this->interactive = false;
if (empty($this->connection)) {
$this->connection = $this->DbConfig->getConfig();
}
$this->Controller->connection = $this->connection;
$this->controllerName = $this->Controller->getName();
$this->controllerPath = low(Inflector::underscore($this->controllerName));
$this->controllerPath = strtolower(Inflector::underscore($this->controllerName));
$interactive = $this->in("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$this->controllerName} views if it exist.", array('y','n'), 'y');
$prompt = sprintf(__("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", true), $this->controllerName);
$interactive = $this->in($prompt, array('y', 'n'), 'n');
if (low($interactive) == 'y' || low($interactive) == 'yes') {
$this->interactive = true;
$wannaDoScaffold = $this->in("Would you like to create some scaffolded views (index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller and model classes (including associated models).", array('y','n'), 'n');
if (strtolower($interactive) == 'n') {
$this->interactive = false;
}
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
$wannaDoAdmin = $this->in("Would you like to create the views for admin routing?", array('y','n'), 'y');
}
$admin = 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).", true);
$wannaDoScaffold = $this->in($prompt, array('y','n'), 'y');
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
$admin = $this->getAdmin();
}
$wannaDoAdmin = $this->in(__("Would you like to create the views for admin routing?", true), array('y','n'), 'n');
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
$actions = $this->scaffoldActions;
if ($admin) {
foreach ($actions as $action) {
$actions[] = $admin . $action;
}
}
if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoAdmin) == 'y') {
$vars = $this->__loadController();
if ($vars) {
foreach ($actions as $action) {
$content = $this->getContent($action, $vars);
$this->bake($action, $content);
if (strtolower($wannaDoScaffold) == 'y') {
$actions = $this->scaffoldActions;
$this->bakeActions($actions, $vars);
}
if (strtolower($wannaDoAdmin) == 'y') {
$admin = $this->Project->getAdmin();
$regularActions = $this->scaffoldActions;
$adminActions = array();
foreach ($regularActions as $action) {
$adminActions[] = $admin . $action;
}
$this->bakeActions($adminActions, $vars);
}
$this->hr();
$this->out('');
$this->out('View Scaffolding Complete.'."\n");
$this->out(__("View Scaffolding Complete.\n", true));
} else {
$action = '';
while ($action == '') {
$action = $this->in('Action Name? (use camelCased function name)');
if ($action == '') {
$this->out('The action name you supplied was empty. Please try again.');
}
}
$this->out('');
$this->hr();
$this->out('The following view will be created:');
$this->hr();
$this->out("Controller Name: {$this->controllerName}");
$this->out("Action Name: {$action}");
$this->out("Path: ".$this->params['app'] . DS . $this->controllerPath . DS . Inflector::underscore($action) . ".ctp");
$this->hr();
$looksGood = $this->in('Look okay?', array('y','n'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
$this->bake($action);
$this->_stop();
} else {
$this->out('Bake Aborted.');
}
$this->customAction();
}
}
/**
* Loads Controller and sets variables for the template
* Available template variables
@ -247,7 +290,7 @@ class ViewTask extends Shell {
$this->_stop();
}
$controllerClassName = $this->controllerName . 'Controller';
$controllerObj = & new $controllerClassName();
$controllerObj =& new $controllerClassName();
$controllerObj->constructClasses();
$modelClass = $controllerObj->modelClass;
$modelObj =& ClassRegistry::getObject($controllerObj->modelKey);
@ -277,6 +320,50 @@ class ViewTask extends Shell {
return compact('modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'singularHumanName', 'pluralHumanName', 'fields','associations');
}
/**
* Bake a view file for each of the supplied actions
*
* @param array $actions Array of actions to make files for.
* @return void
**/
function bakeActions($actions, $vars) {
foreach ($actions as $action) {
$content = $this->getContent($action, $vars);
$this->bake($action, $content);
}
}
/**
* handle creation of baking a custom action view file
*
* @return void
**/
function customAction() {
$action = '';
while ($action == '') {
$action = $this->in(__('Action Name? (use lowercase_underscored function name)', true));
if ($action == '') {
$this->out(__('The action name you supplied was empty. Please try again.', true));
}
}
$this->out('');
$this->hr();
$this->out(__('The following view will be created:', true));
$this->hr();
$this->out(sprintf(__('Controller Name: %s', true), $this->controllerName));
$this->out(sprintf(__('Action Name: %s', true), $action));
$this->out(sprintf(__('Path: %s', true), $this->params['app'] . DS . $this->controllerPath . DS . Inflector::underscore($action) . ".ctp"));
$this->hr();
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
if (strtolower($looksGood) == 'y') {
$this->bake($action);
$this->_stop();
} else {
$this->out(__('Bake Aborted.', true));
}
}
/**
* Assembles and writes bakes the view file.
*
@ -287,21 +374,16 @@ class ViewTask extends Shell {
*/
function bake($action, $content = '') {
if ($content === true) {
$content = $this->getContent();
$content = $this->getContent($action);
}
$filename = $this->path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp';
$Folder =& new Folder($this->path . $this->controllerPath, true);
$errors = $Folder->errors();
if (empty($errors)) {
$path = $Folder->slashTerm($Folder->pwd());
return $this->createFile($filename, $content);
} else {
foreach ($errors as $error) {
$this->err($error);
}
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'views' . DS;
}
return false;
$filename = $path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp';
return $this->createFile($filename, $content);
}
/**
* Builds content from template and variables
*
@ -318,35 +400,29 @@ class ViewTask extends Shell {
$adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) {
$template = str_replace($adminRoute.'_', '', $template);
$template = str_replace($adminRoute . '_', '', $template);
}
if (in_array($template, array('add', 'edit'))) {
$action = $template;
$template = 'form';
}
$loaded = false;
foreach ($this->Dispatch->shellPaths as $path) {
$templatePath = $path . 'templates' . DS . 'views' . DS .Inflector::underscore($template).'.ctp';
if (file_exists($templatePath) && is_file($templatePath)) {
$loaded = true;
break;
}
}
if (!$vars) {
$vars = $this->__loadController();
}
if ($loaded) {
extract($vars);
ob_start();
ob_implicit_flush(0);
include($templatePath);
$content = ob_get_clean();
return $content;
$this->Template->set('action', $action);
$this->Template->set('plugin', $this->plugin);
$this->Template->set($vars);
$output = $this->Template->generate('views', $template);
if (!empty($output)) {
return $output;
}
$this->hr();
$this->err(sprintf(__('Template for %s could not be found', true), $template));
return false;
}
/**
* Displays help contents
*
@ -357,12 +433,28 @@ class ViewTask extends Shell {
$this->out("Usage: cake bake view <arg1> <arg2>...");
$this->hr();
$this->out('Commands:');
$this->out("\n\tview <controller>\n\t\twill read the given controller for methods\n\t\tand bake corresponding views.\n\t\tIf var scaffold is found it will bake the scaffolded actions\n\t\t(index,view,add,edit)");
$this->out("\n\tview <controller> <action>\n\t\twill bake a template. core templates: (index, add, edit, view)");
$this->out("\n\tview <controller> <template> <alias>\n\t\twill use the template specified but name the file based on the alias");
$this->out("");
$this->out('');
$this->out("view <controller>");
$this->out("\tWill read the given controller for methods");
$this->out("\tand bake corresponding views.");
$this->out("\tUsing the -admin flag will only bake views for actions");
$this->out("\tthat begin with Routing.admin.");
$this->out("\tIf var scaffold is found it will bake the CRUD actions");
$this->out("\t(index,view,add,edit)");
$this->out('');
$this->out("view <controller> <action>");
$this->out("\tWill bake a template. core templates: (index, add, edit, view)");
$this->out('');
$this->out("view <controller> <template> <alias>");
$this->out("\tWill use the template specified");
$this->out("\tbut name the file based on the alias");
$this->out('');
$this->out("view all");
$this->out("\tBake all CRUD action views for all controllers.");
$this->out("\tRequires that models and controllers exist.");
$this->_stop();
}
/**
* Returns associations for controllers models.
*

View file

@ -0,0 +1,142 @@
<?php
/**
* Bake Template for Controller action generation.
*
*
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.console.libs.template.objects
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
function <?php echo $admin ?>index() {
$this-><?php echo $currentModelName ?>->recursive = 0;
$this->set('<?php echo $pluralName ?>', $this->paginate());
}
function <?php echo $admin ?>view($id = null) {
if (!$id) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('Invalid <?php echo $singularHumanName ?>', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
<?php endif; ?>
}
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
}
<?php $compact = array(); ?>
function <?php echo $admin ?>add() {
if (!empty($this->data)) {
$this-><?php echo $currentModelName; ?>->create();
if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('<?php echo $currentModelName; ?> saved.', true), array('action' => 'index'));
<?php endif; ?>
} else {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo $singularHumanName; ?> could not be saved. Please, try again.', true));
<?php endif; ?>
}
}
<?php
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
foreach ($modelObj->{$assoc} as $associationName => $relation):
if (!empty($associationName)):
$otherModelName = $this->_modelName($associationName);
$otherPluralName = $this->_pluralName($associationName);
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
$compact[] = "'{$otherPluralName}'";
endif;
endforeach;
endforeach;
if (!empty($compact)):
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
endif;
?>
}
<?php $compact = array(); ?>
function <?php echo $admin; ?>edit($id = null) {
if (!$id && empty($this->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('Invalid <?php echo $singularHumanName; ?>', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
<?php endif; ?>
}
if (!empty($this->data)) {
if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('The <?php echo $singularHumanName; ?> has been saved.', true), array('action' => 'index'));
<?php endif; ?>
} else {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo $singularHumanName; ?> could not be saved. Please, try again.', true));
<?php endif; ?>
}
}
if (empty($this->data)) {
$this->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
}
<?php
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
foreach ($modelObj->{$assoc} as $associationName => $relation):
if (!empty($associationName)):
$otherModelName = $this->_modelName($associationName);
$otherPluralName = $this->_pluralName($associationName);
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
$compact[] = "'{$otherPluralName}'";
endif;
endforeach;
endforeach;
if (!empty($compact)):
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
endif;
?>
}
function <?php echo $admin; ?>delete($id = null) {
if (!$id) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('Invalid id for <?php echo $singularHumanName; ?>', true));
$this->redirect(array('action'=>'index'));
<?php else: ?>
$this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
<?php endif; ?>
}
if ($this-><?php echo $currentModelName; ?>->del($id)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('<?php echo $singularHumanName; ?> deleted', true));
$this->redirect(array('action'=>'index'));
<?php else: ?>
$this->flash(__('<?php echo $singularHumanName; ?> deleted', true), array('action' => 'index'));
<?php endif; ?>
}
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('<?php echo $singularHumanName; ?> was not deleted', true));
<?php else: ?>
$this->flash(__('<?php echo $singularHumanName; ?> was not deleted', true), array('action' => 'index'));
<?php endif; ?>
$this->redirect(array('action' => 'index'));
}

View file

@ -0,0 +1,57 @@
<?php
/**
* Controller bake template file
*
* Allows templating of Controllers generated from bake.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
echo "<?php\n";
?>
class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>AppController {
var $name = '<?php echo $controllerName; ?>';
<?php if ($isScaffold): ?>
var $scaffold;
<?php else: ?>
<?php
echo "\tvar \$helpers = array('Html', 'Form'";
if (count($helpers)):
foreach ($helpers as $help):
echo ", '" . Inflector::camelize($help) . "'";
endforeach;
endif;
echo ");\n";
if (count($components)):
echo "\tvar \$components = array(";
for ($i = 0, $len = count($components); $i < $len; $i++):
if ($i != $len - 1):
echo "'" . Inflector::camelize($components[$i]) . "', ";
else:
echo "'" . Inflector::camelize($components[$i]) . "'";
endif;
endfor;
echo ");\n";
endif;
echo $actions;
endif; ?>
}
<?php echo "?>"; ?>

View file

@ -0,0 +1,42 @@
<?php
/**
* Fixture Template file
*
* Fixture Template used when baking fixtures with bake
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
<?php echo '<?php' . "\n"; ?>
/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:m:s') . " : ". time(); ?> */
class <?php echo $model; ?>Fixture extends CakeTestFixture {
var $name = '<?php echo $model; ?>';
<?php if ($table): ?>
var $table = '<?php echo $table; ?>';
<?php endif; ?>
<?php if ($import): ?>
var $import = <?php echo $import; ?>;
<?php endif; ?>
<?php if ($schema): ?>
var $fields = <?php echo $schema; ?>;
<?php endif;?>
<?php if ($records): ?>
var $records = <?php echo $records; ?>;
<?php endif;?>
}
<?php echo '?>'; ?>

View file

@ -0,0 +1,130 @@
<?php
/**
* Model template file.
*
* Used by bake to create new Model files.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.console.libs.templates.objects
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
echo "<?php\n"; ?>
class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel {
var $name = '<?php echo $name; ?>';
<?php if ($useDbConfig != 'default'): ?>
var $useDbConfig = '<?php echo $useDbConfig; ?>';
<?php endif;?>
<?php if ($useTable && $useTable !== Inflector::tableize($name)):
$table = "'$useTable'";
echo "\tvar \$useTable = $table;\n";
endif;
if ($primaryKey !== 'id'): ?>
var $primaryKey = '<?php echo $primaryKey; ?>';
<?php endif;
if ($displayField): ?>
var $displayField = '<?php echo $displayField; ?>';
<?php endif;
if (!empty($validate)):
echo "\tvar \$validate = array(\n";
foreach ($validate as $field => $validations):
echo "\t\t'$field' => array(\n";
foreach ($validations as $key => $validator):
echo "\t\t\t'$key' => array('rule' => array('$validator')),\n";
endforeach;
echo "\t\t),\n";
endforeach;
echo "\t);\n";
endif;
?>
//The Associations below have been created with all possible keys, those that are not needed can be removed
<?php
foreach (array('hasOne', 'belongsTo') as $assocType):
if (!empty($associations[$assocType])):
$typeCount = count($associations[$assocType]);
echo "\n\tvar \$$assocType = array(";
foreach ($associations[$assocType] as $i => $relation):
$out = "\n\t\t'{$relation['alias']}' => array(\n";
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
$out .= "\t\t\t'conditions' => '',\n";
$out .= "\t\t\t'fields' => '',\n";
$out .= "\t\t\t'order' => ''\n";
$out .= "\t\t)";
if ($i + 1 < $typeCount) {
$out .= ",";
}
echo $out;
endforeach;
echo "\n\t);\n";
endif;
endforeach;
if (!empty($associations['hasMany'])):
$belongsToCount = count($associations['hasMany']);
echo "\n\tvar \$hasMany = array(";
foreach ($associations['hasMany'] as $i => $relation):
$out = "\n\t\t'{$relation['alias']}' => array(\n";
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
$out .= "\t\t\t'dependent' => false,\n";
$out .= "\t\t\t'conditions' => '',\n";
$out .= "\t\t\t'fields' => '',\n";
$out .= "\t\t\t'order' => '',\n";
$out .= "\t\t\t'limit' => '',\n";
$out .= "\t\t\t'offset' => '',\n";
$out .= "\t\t\t'exclusive' => '',\n";
$out .= "\t\t\t'finderQuery' => '',\n";
$out .= "\t\t\t'counterQuery' => ''\n";
$out .= "\t\t)";
if ($i + 1 < $belongsToCount) {
$out .= ",";
}
echo $out;
endforeach;
echo "\n\t);\n\n";
endif;
if (!empty($associations['hasAndBelongsToMany'])):
$habtmCount = count($associations['hasAndBelongsToMany']);
echo "\n\tvar \$hasAndBelongsToMany = array(";
foreach ($associations['hasAndBelongsToMany'] as $i => $relation):
$out = "\n\t\t'{$relation['alias']}' => array(\n";
$out .= "\t\t\t'className' => '{$relation['className']}',\n";
$out .= "\t\t\t'joinTable' => '{$relation['joinTable']}',\n";
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n";
$out .= "\t\t\t'associationForeignKey' => '{$relation['associationForeignKey']}',\n";
$out .= "\t\t\t'unique' => true,\n";
$out .= "\t\t\t'conditions' => '',\n";
$out .= "\t\t\t'fields' => '',\n";
$out .= "\t\t\t'order' => '',\n";
$out .= "\t\t\t'limit' => '',\n";
$out .= "\t\t\t'offset' => '',\n";
$out .= "\t\t\t'finderQuery' => '',\n";
$out .= "\t\t\t'deleteQuery' => '',\n";
$out .= "\t\t\t'insertQuery' => ''\n";
$out .= "\t\t)";
if ($i + 1 < $habtmCount) {
$out .= ",";
}
echo $out;
endforeach;
echo "\n\t);\n\n";
endif;
?>
}
<?php echo '?>'; ?>

View file

@ -0,0 +1,57 @@
<?php
/**
* Test Case bake template
*
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.console.libs.templates.objects
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
echo "<?php\n";
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n";
?>
App::import('<?php echo $type; ?>', '<?php echo $plugin . $className;?>');
<?php if ($mock and strtolower($type) == 'controller'): ?>
class Test<?php echo $fullClassName; ?> extends <?php echo $fullClassName; ?> {
var $autoRender = false;
function redirect($url, $status = null, $exit = true) {
$this->redirectUrl = $url;
}
}
<?php endif; ?>
class <?php echo $fullClassName; ?>TestCase extends CakeTestCase {
<?php if (!empty($fixtures)): ?>
var $fixtures = array('<?php echo join("', '", $fixtures); ?>');
<?php endif; ?>
function startTest() {
$this-><?php echo $className . ' =& ' . $construction; ?>
}
function endTest() {
unset($this-><?php echo $className;?>);
ClassRegistry::flush();
}
<?php foreach ($methods as $method): ?>
function test<?php echo Inflector::classify($method); ?>() {
}
<?php endforeach;?>
}
<?php echo '?>'; ?>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5
@ -25,7 +26,7 @@
<div class="<?php echo $pluralVar;?> form">
<?php echo "<?php echo \$form->create('{$modelClass}');?>\n";?>
<fieldset>
<legend><?php echo "<?php __('".Inflector::humanize($action)." {$singularHumanName}');?>";?></legend>
<legend><?php echo "<?php __('" . Inflector::humanize($action) . " {$singularHumanName}');?>";?></legend>
<?php
echo "\t<?php\n";
foreach ($fields as $field) {
@ -58,12 +59,12 @@
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?php echo \$html->link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
$done[] = $details['controller'];
}
}
}
?>
</ul>
</div>
</div>

View file

@ -1,5 +1,5 @@
<?php
$output = "<h2>Sweet, \"".Inflector::humanize($app)."\" got Baked by CakePHP!</h2>\n";
$output = "<h2>Sweet, \"" . Inflector::humanize($app) . "\" got Baked by CakePHP!</h2>\n";
$output .="
<?php
if (Configure::read() > 0):
@ -79,4 +79,4 @@ $output .= "\t\tYou can also add some CSS styles for your pages at: %s', true),\
$output .= "\t\tAPP . 'views' . DS . 'pages' . DS . 'home.ctp.<br />', APP . 'views' . DS . 'layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');\n";
$output .= "?>\n";
$output .= "</p>\n";
?>
?>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5
@ -88,12 +89,12 @@ echo "<?php endforeach; ?>\n";
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?php echo \$html->link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
$done[] = $details['controller'];
}
}
}
?>
</ul>
</div>
</div>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5
@ -32,14 +33,14 @@ foreach ($fields as $field) {
foreach ($associations['belongsTo'] as $alias => $details) {
if ($field === $details['foreignKey']) {
$isKey = true;
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('".Inflector::humanize(Inflector::underscore($alias))."'); ?></dt>\n";
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('" . Inflector::humanize(Inflector::underscore($alias)) . "'); ?></dt>\n";
echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t\t\t<?php echo \$html->link(\${$singularVar}['{$alias}']['{$details['displayField']}'], array('controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?>\n\t\t\t&nbsp;\n\t\t</dd>\n";
break;
}
}
}
if ($isKey !== true) {
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('".Inflector::humanize($field)."'); ?></dt>\n";
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('" . Inflector::humanize($field) . "'); ?></dt>\n";
echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t\t\t<?php echo \${$singularVar}['{$modelClass}']['{$field}']; ?>\n\t\t\t&nbsp;\n\t\t</dd>\n";
}
}
@ -58,8 +59,8 @@ foreach ($fields as $field) {
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?php echo \$html->link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
$done[] = $details['controller'];
}
}
@ -71,12 +72,12 @@ foreach ($fields as $field) {
if (!empty($associations['hasOne'])) :
foreach ($associations['hasOne'] as $alias => $details): ?>
<div class="related">
<h3><?php echo "<?php __('Related ".Inflector::humanize($details['controller'])."');?>";?></h3>
<h3><?php echo "<?php __('Related " . Inflector::humanize($details['controller']) . "');?>";?></h3>
<?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?>
<dl><?php echo "\t<?php \$i = 0; \$class = ' class=\"altrow\"';?>\n";?>
<?php
foreach ($details['fields'] as $field) {
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('".Inflector::humanize($field)."');?></dt>\n";
echo "\t\t<dt<?php if (\$i % 2 == 0) echo \$class;?>><?php __('" . Inflector::humanize($field) . "');?></dt>\n";
echo "\t\t<dd<?php if (\$i++ % 2 == 0) echo \$class;?>>\n\t<?php echo \${$singularVar}['{$alias}']['{$field}'];?>\n&nbsp;</dd>\n";
}
?>
@ -84,7 +85,7 @@ if (!empty($associations['hasOne'])) :
<?php echo "<?php endif; ?>\n";?>
<div class="actions">
<ul>
<li><?php echo "<?php echo \$html->link(__('Edit ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'edit', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?></li>\n";?>
<li><?php echo "<?php echo \$html->link(__('Edit " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'edit', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?></li>\n";?>
</ul>
</div>
</div>
@ -110,7 +111,7 @@ foreach ($relations as $alias => $details):
<tr>
<?php
foreach ($details['fields'] as $field) {
echo "\t\t<th><?php __('".Inflector::humanize($field)."'); ?></th>\n";
echo "\t\t<th><?php __('" . Inflector::humanize($field) . "'); ?></th>\n";
}
?>
<th class="actions"><?php echo "<?php __('Actions');?>";?></th>
@ -143,7 +144,7 @@ echo "\t<?php endforeach; ?>\n";
<?php echo "<?php endif; ?>\n\n";?>
<div class="actions">
<ul>
<li><?php echo "<?php echo \$html->link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add'));?>";?> </li>
<li><?php echo "<?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add'));?>";?> </li>
</ul>
</div>
</div>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -25,6 +26,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Short description for class.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -25,7 +26,8 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'Helper');
App::import('Helper', 'Helper', false);
/**
* This is a placeholder class.
* Create the same file in app/app_helper.php

View file

@ -71,4 +71,4 @@ allow = aco3, aco4
[groupname-goes-here]
deny = aco5, aco6
allow = aco7, aco8
allow = aco7, aco8

View file

@ -1,44 +1,51 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php
*
* Long description for file
* 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.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config
* @since CakePHP(tm) v 0.10.8.2117
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
*
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php is loaded
* 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.
*
*/
/**
* 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)
*
* $modelPaths = array('full path to models', 'second full path to models', 'etc...');
* $viewPaths = array('this path to views', 'second full path to views', 'etc...');
* $controllerPaths = array('this path to controllers', 'second full path to controllers', 'etc...');
* App::build(array(
* 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
* 'models' => array('/full/path/to/models/', '/next/full/path/to/models/'),
* 'views' => array('/full/path/to/views/', '/next/full/path/to/views/'),
* 'controllers' => array(/full/path/to/controllers/', '/next/full/path/to/controllers/'),
* 'datasources' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
* 'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
* 'components' => array('/full/path/to/components/', '/next/full/path/to/components/'),
* 'helpers' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'),
* 'vendors' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'),
* 'shells' => array('/full/path/to/shells/', '/next/full/path/to/shells/'),
* 'locales' => array('/full/path/to/locale/', '/next/full/path/to/locale/')
* ));
*
*/
/**
* As of 1.3, additional rules for the inflector are added below
*
* Inflector::rule('singular', array('rules' => array(), irregular' => array(), 'uninflected' => array()));
* Inflector::rule('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
*
*/
//EOF
?>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* This is core configuration file.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* CakePHP Debug Level:
*
@ -39,10 +41,12 @@
* In development mode, you need to click the flash message to continue.
*/
Configure::write('debug', 2);
/**
* Application wide charset encoding
*/
Configure::write('App.encoding', 'UTF-8');
/**
* To configure CakePHP *not* to use mod_rewrite and to
* use CakePHP pretty URLs, remove these .htaccess
@ -55,6 +59,7 @@
* And uncomment the App.baseUrl below:
*/
//Configure::write('App.baseUrl', env('SCRIPT_NAME'));
/**
* Uncomment the define below to use CakePHP admin routes.
*
@ -71,6 +76,7 @@
*
*/
//Configure::write('Cache.disable', true);
/**
* Enable cache checking.
*
@ -81,11 +87,13 @@
*
*/
//Configure::write('Cache.check', true);
/**
* Defines the default error type when using the log() function. Used for
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.
*/
define('LOG_ERROR', 2);
/**
* The preferred session handling method. Valid values:
*
@ -100,6 +108,7 @@
*
*/
Configure::write('Session.save', 'php');
/**
* The name of the table used to store CakePHP database sessions.
*
@ -108,30 +117,36 @@
* The table name set here should *not* include any table prefix defined elsewhere.
*/
//Configure::write('Session.table', 'cake_sessions');
/**
* The DATABASE_CONFIG::$var to use for database session handling.
*
* 'Session.save' must be set to 'database' in order to utilize this constant.
*/
//Configure::write('Session.database', 'default');
/**
* The name of CakePHP's session cookie.
*/
Configure::write('Session.cookie', 'CAKEPHP');
/**
* Session time out time (in seconds).
* Actual value depends on 'Security.level' setting.
*/
Configure::write('Session.timeout', '120');
/**
* If set to false, sessions are not automatically started.
*/
Configure::write('Session.start', true);
/**
* When set to false, HTTP_USER_AGENT will not be checked
* in the session
*/
Configure::write('Session.checkAgent', true);
/**
* The level of CakePHP security. The session timeout time defined
* in 'Session.timeout' is multiplied according to the settings here.
@ -145,10 +160,12 @@
* 'Security.level' is set to 'high'.
*/
Configure::write('Security.level', 'high');
/**
* A random string used in security hashing methods.
*/
Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
/**
* Compress CSS output by removing comments, whitespace, repeating tags, etc.
* This requires a/var/cache directory to be writable by the web server for caching.
@ -157,6 +174,7 @@
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css().
*/
//Configure::write('Asset.filter.css', 'css.php');
/**
* Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the
* output, and setting the config below to the name of the script.
@ -164,12 +182,14 @@
* To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JavaScriptHelper::link().
*/
//Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php');
/**
* The classname and database used in CakePHP's
* access control lists.
*/
Configure::write('Acl.classname', 'DbAcl');
Configure::write('Acl.database', 'default');
/**
* If you are on PHP 5.3 uncomment this line and correct your server timezone
* to fix the date & time related errors.

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Custom Inflected Words.
*
@ -25,6 +26,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* This is a key => value array of regex used to match words.
* If key matches then the value is returned.
@ -32,6 +34,7 @@
* $pluralRules = array('/(s)tatus$/i' => '\1\2tatuses', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice');
*/
$pluralRules = array();
/**
* This is a key only array of plural words that should not be inflected.
* Notice the last comma
@ -39,6 +42,7 @@
* $uninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox');
*/
$uninflectedPlural = array();
/**
* This is a key => value array of plural irregular words.
* If key matches then the value is returned.
@ -46,6 +50,7 @@
* $irregularPlural = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers')
*/
$irregularPlural = array();
/**
* This is a key => value array of regex used to match words.
* If key matches then the value is returned.
@ -53,12 +58,14 @@
* $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i')
*/
$singularRules = array();
/**
* This is a key only array of singular words that should not be inflected.
* You should not have to change this value below if you do change it use same format
* as the $uninflectedPlural above.
*/
$uninflectedSingular = $uninflectedPlural;
/**
* This is a key => value array of singular irregular words.
* Most of the time this will be a reverse of the above $irregularPlural array

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -26,12 +27,14 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Here, we are connecting '/' (base path) to controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/views/pages/home.ctp)...
*/
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
* ...and connect the rest of 'Pages' controller's urls.
*/

View file

@ -1,6 +1,8 @@
<?php
/* SVN FILE: $Id$ */
/*DbAcl schema generated on: 2007-11-24 15:11:13 : 1195945453*/
/**
* This is Acl Schema file
*
@ -25,6 +27,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility

View file

@ -1,6 +1,8 @@
<?php
/* SVN FILE: $Id$ */
/*i18n schema generated on: 2007-11-25 07:11:25 : 1196004805*/
/**
* This is i18n Schema file
*
@ -25,6 +27,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility

View file

@ -1,6 +1,8 @@
<?php
/* SVN FILE: $Id$ */
/*Sessions schema generated on: 2007-11-25 07:11:54 : 1196004714*/
/**
* This is Sessions Schema file
*
@ -25,6 +27,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/*
*
* Using the Schema command line utility

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Static content controller.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Static content controller
*
@ -33,6 +35,7 @@
* @subpackage cake.cake.libs.controller
*/
class PagesController extends AppController {
/**
* Controller name
*
@ -40,6 +43,7 @@ class PagesController extends AppController {
* @access public
*/
var $name = 'Pages';
/**
* Default helper
*
@ -47,6 +51,7 @@ class PagesController extends AppController {
* @access public
*/
var $helpers = array('Html');
/**
* This controller does not use a model
*
@ -54,6 +59,7 @@ class PagesController extends AppController {
* @access public
*/
var $uses = array();
/**
* Displays a view
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* PHP versions 4 and 5
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5
@ -34,4 +35,4 @@
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
</body>
</html>
</html>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5
@ -26,4 +27,3 @@
<?php echo $content_for_layout;?>
This email was sent using the CakePHP Framework, http://cakephp.org.

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -28,12 +29,14 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
header('HTTP/1.1 404 Not Found');
exit('File Not Found');
}
/**
* Enter description here...
*/
if (!class_exists('File')) {
uses('file');
}
/**
* Enter description here...
*
@ -50,6 +53,7 @@ if (!class_exists('File')) {
$output = " /* file: $name, ratio: $ratio% */ " . $output;
return $output;
}
/**
* Enter description here...
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,12 +25,14 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Use the DS to separate the directories in other defines
*/
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
/**
* These defines should only be edited if you have cake installed in
* a directory layout other than the way it is distributed.
@ -43,6 +46,7 @@
if (!defined('ROOT')) {
define('ROOT', dirname(dirname(dirname(__FILE__))));
}
/**
* The actual directory name for the "app".
*
@ -50,6 +54,7 @@
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -25,6 +26,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Enter description here...
*/

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -35,12 +36,14 @@ error_reporting(E_ALL & ~E_DEPRECATED);
set_time_limit(0);
ini_set('memory_limit','128M');
ini_set('display_errors', 1);
/**
* Use the DS to separate the directories in other defines
*/
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
/**
* These defines should only be edited if you have cake installed in
* a directory layout other than the way it is distributed.
@ -54,6 +57,7 @@ ini_set('display_errors', 1);
if (!defined('ROOT')) {
define('ROOT', dirname(dirname(dirname(__FILE__))));
}
/**
* The actual directory name for the "app".
*
@ -61,6 +65,7 @@ ini_set('display_errors', 1);
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
@ -93,7 +98,7 @@ 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 = Configure::corePaths('cake');
$corePath = App::core('cake');
if (isset($corePath[0])) {
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
} else {
@ -112,6 +117,7 @@ if (!isset($_SERVER['SERVER_NAME'])) {
if (empty( $_GET['output'])) {
$_GET['output'] = 'html';
}
/**
*
* Used to determine output to display

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test Suite Shell
*
@ -25,6 +26,7 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
class TestSuiteShell extends Shell {
/**
* The test category, "app", "core" or the name of a plugin
*
@ -32,6 +34,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
var $category = '';
/**
* "group", "case" or "all"
*
@ -39,6 +42,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
var $type = '';
/**
* Path to the test case/group file
*
@ -46,6 +50,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
var $file = '';
/**
* Storage for plugins that have tests
*
@ -53,6 +58,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
var $plugins = array();
/**
* Convenience variable to avoid duplicated code
*
@ -60,6 +66,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
var $isPluginTest = false;
/**
* Stores if the user wishes to get a code coverage analysis report
*
@ -67,6 +74,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
var $doCoverage = false;
/**
* The headline for the test output
*
@ -74,6 +82,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
var $headline = 'CakePHP Test Shell';
/**
* Initialization method installs Simpletest and loads all plugins
*
@ -81,7 +90,7 @@ class TestSuiteShell extends Shell {
* @access public
*/
function initialize() {
$corePath = Configure::corePaths('cake');
$corePath = App::core('cake');
if (isset($corePath[0])) {
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
} else {
@ -98,6 +107,7 @@ class TestSuiteShell extends Shell {
$this->plugins[] = Inflector::underscore($p);
}
}
/**
* Main entry point to this shell
*
@ -147,6 +157,7 @@ class TestSuiteShell extends Shell {
exit(1);
}
}
/**
* Help screen
*
@ -184,6 +195,7 @@ class TestSuiteShell extends Shell {
$this->out('Code Coverage Analysis: ');
$this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis");
}
/**
* Checks if the arguments supplied point to a valid test file and thus the shell can be run.
*
@ -237,6 +249,7 @@ class TestSuiteShell extends Shell {
$this->err($this->category.' '.$this->type.' '.$this->file.' is an invalid test identifier');
return false;
}
/**
* Executes the tests depending on our settings
*
@ -298,6 +311,7 @@ class TestSuiteShell extends Shell {
return $result;
}
/**
* Finds the correct folder to look for tests for based on the input category
*
@ -326,6 +340,7 @@ class TestSuiteShell extends Shell {
}
return $folder;
}
/**
* Sets some get vars needed for TestManager
*
@ -344,6 +359,7 @@ class TestSuiteShell extends Shell {
$_GET['group'] = true;
}
}
/**
* tries to install simpletest and exits gracefully if it is not there
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Dispatcher takes the URL information, parses it for paramters and
* tells the involved controllers what to do.
@ -25,10 +26,13 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* List of helpers to include
*/
App::import('Core', array('Router', 'Controller'));
App::import('Core', 'Router');
App::import('Controller', 'Controller', false);
/**
* Dispatcher translates URLs to controller-action-paramter triads.
*
@ -38,6 +42,7 @@ App::import('Core', array('Router', 'Controller'));
* @subpackage cake.cake
*/
class Dispatcher extends Object {
/**
* Base URL
*
@ -45,6 +50,7 @@ class Dispatcher extends Object {
* @access public
*/
var $base = false;
/**
* webroot path
*
@ -52,6 +58,7 @@ class Dispatcher extends Object {
* @access public
*/
var $webroot = '/';
/**
* Current URL
*
@ -59,6 +66,7 @@ class Dispatcher extends Object {
* @access public
*/
var $here = false;
/**
* Admin route (if on it)
*
@ -66,6 +74,7 @@ class Dispatcher extends Object {
* @access public
*/
var $admin = false;
/**
* Plugin being served (if any)
*
@ -73,6 +82,7 @@ class Dispatcher extends Object {
* @access public
*/
var $plugin = null;
/**
* the params for this request
*
@ -80,6 +90,7 @@ class Dispatcher extends Object {
* @access public
*/
var $params = null;
/**
* Constructor.
*/
@ -91,6 +102,7 @@ class Dispatcher extends Object {
return $this->dispatch($url);
}
}
/**
* Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set).
*
@ -193,6 +205,7 @@ class Dispatcher extends Object {
}
return $this->_invoke($controller, $this->params);
}
/**
* Invokes given controller's render action if autoRender option is set. Otherwise the
* contents of the operation are returned as a string.
@ -213,7 +226,7 @@ class Dispatcher extends Object {
if (!isset($methods[strtolower($params['action'])])) {
if ($controller->scaffold !== false) {
App::import('Core', 'Scaffold');
App::import('Controller', 'Scaffold', false);
return new Scaffold($controller, $params);
}
return $this->cakeError('missingAction', array(array(
@ -239,6 +252,7 @@ class Dispatcher extends Object {
}
echo($controller->output);
}
/**
* Sets the params when $url is passed as an array to Object::requestAction();
*
@ -252,6 +266,7 @@ class Dispatcher extends Object {
$this->params = array_merge($defaults, $url, $additionalParams);
return Router::url($url);
}
/**
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
*
@ -325,6 +340,7 @@ class Dispatcher extends Object {
}
return $params;
}
/**
* Returns a base URL and sets the proper webroot
*
@ -382,6 +398,7 @@ class Dispatcher extends Object {
}
return false;
}
/**
* Restructure params in case we're serving a plugin.
*
@ -412,6 +429,7 @@ class Dispatcher extends Object {
}
return $params;
}
/**
* Get controller to use, either plugin controller or application controller
*
@ -454,6 +472,7 @@ class Dispatcher extends Object {
}
return $controller;
}
/**
* Load controller and return controller class
*
@ -481,6 +500,7 @@ class Dispatcher extends Object {
}
return false;
}
/**
* Returns the REQUEST_URI from the server environment, or, failing that,
* constructs a new one, using the PHP_SELF constant and other variables.
@ -515,10 +535,10 @@ class Dispatcher extends Object {
parse_str($uri[1], $_GET);
}
$uri = $uri[0];
} elseif (empty($uri) && is_string(env('QUERY_STRING'))) {
} else {
$uri = env('QUERY_STRING');
}
if (strpos($uri, 'index.php') !== false) {
if (is_string($uri) && strpos($uri, 'index.php') !== false) {
list(, $uri) = explode('index.php', $uri, 2);
}
if (empty($uri) || $uri == '/' || $uri == '//') {
@ -526,6 +546,7 @@ class Dispatcher extends Object {
}
return str_replace('//', '/', '/' . $uri);
}
/**
* Returns and sets the $_GET[url] derived from the REQUEST_URI
*
@ -576,6 +597,7 @@ class Dispatcher extends Object {
}
return $url;
}
/**
* Outputs cached dispatch for js, css, img, view cache
*
@ -671,7 +693,7 @@ class Dispatcher extends Object {
if (file_exists($filename)) {
if (!class_exists('View')) {
App::import('Core', 'View');
App::import('View', 'View', false);
}
$controller = null;
$view =& new View($controller, false);

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Caching for CakePHP.
*
@ -23,6 +24,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Caching for CakePHP.
*
@ -30,6 +32,7 @@
* @subpackage cake.cake.libs
*/
class Cache extends Object {
/**
* Cache engine to use
*
@ -37,6 +40,7 @@ class Cache extends Object {
* @access protected
*/
var $_Engine = null;
/**
* Cache configuration stack
*
@ -44,6 +48,7 @@ class Cache extends Object {
* @access private
*/
var $__config = array();
/**
* Holds name of the current configuration being used
*
@ -51,6 +56,7 @@ class Cache extends Object {
* @access private
*/
var $__name = 'default';
/**
* whether to reset the settings with the next call to self::set();
*
@ -58,6 +64,7 @@ class Cache extends Object {
* @access private
*/
var $__reset = false;
/**
* Returns a singleton instance
*
@ -72,6 +79,7 @@ class Cache extends Object {
}
return $instance[0];
}
/**
* Tries to find and include a file for a cache engine and returns object instance
*
@ -85,6 +93,7 @@ class Cache extends Object {
}
return true;
}
/**
* Set the cache configuration to use
*
@ -132,6 +141,7 @@ class Cache extends Object {
}
return compact('engine', 'settings');
}
/**
* Set the cache engine to use or modify settings for one instance
*
@ -160,6 +170,7 @@ class Cache extends Object {
$_this->_Engine[$name] = null;
return false;
}
/**
* Temporarily change settings to current config options. if no params are passed, resets settings if needed
* Cache::write() will reset the configuration changes made
@ -192,11 +203,12 @@ class Cache extends Object {
}
$settings = array_merge($_this->__config[$_this->__name], $settings);
}
$_this->_Engine[$engine]->init($settings);
$_this->engine($engine, $settings);
}
return $_this->settings($engine);
}
/**
* Garbage collection
*
@ -211,6 +223,7 @@ class Cache extends Object {
$config = $_this->config();
$_this->_Engine[$config['engine']]->gc();
}
/**
* Write data for key into cache
*
@ -261,6 +274,7 @@ class Cache extends Object {
$settings = $_this->set();
return $success;
}
/**
* Read a key from the cache
*
@ -297,6 +311,7 @@ class Cache extends Object {
}
return $success;
}
/**
* Delete a key from the cache
*
@ -331,6 +346,7 @@ class Cache extends Object {
$settings = $_this->set();
return $success;
}
/**
* Delete all keys from the cache
*
@ -360,6 +376,7 @@ class Cache extends Object {
$settings = $_this->set();
return $success;
}
/**
* Check if Cache has initialized a working storage engine
*
@ -400,6 +417,7 @@ class Cache extends Object {
return array();
}
}
/**
* Storage engine for CakePHP caching
*
@ -407,6 +425,7 @@ class Cache extends Object {
* @subpackage cake.cake.libs
*/
class CacheEngine extends Object {
/**
* settings of current engine instance
*
@ -414,6 +433,7 @@ class CacheEngine extends Object {
* @access public
*/
var $settings = array();
/**
* Iitialize the cache engine
*
@ -430,6 +450,7 @@ class CacheEngine extends Object {
}
return true;
}
/**
* Garbage collection
*
@ -439,6 +460,7 @@ class CacheEngine extends Object {
*/
function gc() {
}
/**
* Write value for a key into cache
*
@ -451,6 +473,7 @@ class CacheEngine extends Object {
function write($key, &$value, $duration) {
trigger_error(sprintf(__('Method write() not implemented in %s', true), get_class($this)), E_USER_ERROR);
}
/**
* Read a key from the cache
*
@ -461,6 +484,7 @@ class CacheEngine extends Object {
function read($key) {
trigger_error(sprintf(__('Method read() not implemented in %s', true), get_class($this)), E_USER_ERROR);
}
/**
* Delete a key from the cache
*
@ -470,6 +494,7 @@ class CacheEngine extends Object {
*/
function delete($key) {
}
/**
* Delete all keys from the cache
*
@ -479,6 +504,7 @@ class CacheEngine extends Object {
*/
function clear($check) {
}
/**
* Cache Engine settings
*
@ -488,6 +514,7 @@ class CacheEngine extends Object {
function settings() {
return $this->settings;
}
/**
* generates a safe key
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* APC storage engine for cache.
*
@ -23,6 +24,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* APC storage engine for cache
*
@ -30,6 +32,7 @@
* @subpackage cake.cake.libs.cache
*/
class ApcEngine extends CacheEngine {
/**
* Initialize the Cache Engine
*
@ -45,6 +48,7 @@ class ApcEngine extends CacheEngine {
parent::init(array_merge(array('engine' => 'Apc', 'prefix' => Inflector::slug(APP_DIR) . '_'), $settings));
return function_exists('apc_cache_info');
}
/**
* Write data for key into cache
*
@ -59,6 +63,7 @@ class ApcEngine extends CacheEngine {
apc_store($key.'_expires', $expires, $duration);
return apc_store($key, $value, $duration);
}
/**
* Read a key from the cache
*
@ -74,6 +79,7 @@ class ApcEngine extends CacheEngine {
}
return apc_fetch($key);
}
/**
* Delete a key from the cache
*
@ -84,6 +90,7 @@ class ApcEngine extends CacheEngine {
function delete($key) {
return apc_delete($key);
}
/**
* Delete all keys from the cache
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* File Storage engine for cache
*
@ -23,6 +24,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* File Storage engine for cache
*
@ -31,6 +33,7 @@
* @subpackage cake.cake.libs.cache
*/
class FileEngine extends CacheEngine {
/**
* Instance of File class
*
@ -38,6 +41,7 @@ class FileEngine extends CacheEngine {
* @access private
*/
var $__File = null;
/**
* settings
* path = absolute path to cache directory, default => CACHE
@ -50,6 +54,7 @@ class FileEngine extends CacheEngine {
* @access public
*/
var $settings = array();
/**
* Set to true if FileEngine::init(); and FileEngine::__active(); do not fail.
*
@ -57,6 +62,7 @@ class FileEngine extends CacheEngine {
* @access private
*/
var $__active = false;
/**
* True unless FileEngine::__active(); fails
*
@ -64,6 +70,7 @@ class FileEngine extends CacheEngine {
* @access private
*/
var $__init = true;
/**
* Initialize the Cache Engine
*
@ -99,6 +106,7 @@ class FileEngine extends CacheEngine {
}
return $this->__active();
}
/**
* Garbage collection. Permanently remove all expired and deleted data
*
@ -108,6 +116,7 @@ class FileEngine extends CacheEngine {
function gc() {
return $this->clear(true);
}
/**
* Write data for key into cache
*
@ -149,6 +158,7 @@ class FileEngine extends CacheEngine {
$this->__File->close();
return $success;
}
/**
* Read a key from the cache
*
@ -181,6 +191,7 @@ class FileEngine extends CacheEngine {
$this->__File->close();
return $data;
}
/**
* Delete a key from the cache
*
@ -194,6 +205,7 @@ class FileEngine extends CacheEngine {
}
return $this->__File->delete();
}
/**
* Delete all values from the cache
*
@ -233,6 +245,7 @@ class FileEngine extends CacheEngine {
$dir->close();
return true;
}
/**
* Get absolute file for a given key
*
@ -250,6 +263,7 @@ class FileEngine extends CacheEngine {
return false;
}
}
/**
* Determine is cache directory is writable
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Memcache storage engine for cache
*
@ -23,6 +24,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Memcache storage engine for cache
*
@ -30,6 +32,7 @@
* @subpackage cake.cake.libs.cache
*/
class MemcacheEngine extends CacheEngine {
/**
* Memcache wrapper.
*
@ -37,6 +40,7 @@ class MemcacheEngine extends CacheEngine {
* @access private
*/
var $__Memcache = null;
/**
* settings
* servers = string or array of memcache servers, default => 127.0.0.1
@ -46,6 +50,7 @@ class MemcacheEngine extends CacheEngine {
* @access public
*/
var $settings = array();
/**
* Initialize the Cache Engine
*
@ -89,6 +94,7 @@ class MemcacheEngine extends CacheEngine {
}
return true;
}
/**
* Write data for key into cache
*
@ -103,6 +109,7 @@ class MemcacheEngine extends CacheEngine {
$this->__Memcache->set($key.'_expires', $expires, $this->settings['compress'], $expires);
return $this->__Memcache->set($key, $value, $this->settings['compress'], $expires);
}
/**
* Read a key from the cache
*
@ -118,6 +125,7 @@ class MemcacheEngine extends CacheEngine {
}
return $this->__Memcache->get($key);
}
/**
* Delete a key from the cache
*
@ -128,6 +136,7 @@ class MemcacheEngine extends CacheEngine {
function delete($key) {
return $this->__Memcache->delete($key);
}
/**
* Delete all keys from the cache
*
@ -137,6 +146,7 @@ class MemcacheEngine extends CacheEngine {
function clear() {
return $this->__Memcache->flush();
}
/**
* Connects to a server in connection pool
*
@ -155,4 +165,4 @@ class MemcacheEngine extends CacheEngine {
return true;
}
}
?>
?>

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Xcache storage engine for cache.
*
@ -23,6 +24,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Xcache storage engine for cache
*
@ -31,6 +33,7 @@
* @subpackage cake.cake.libs.cache
*/
class XcacheEngine extends CacheEngine {
/**
* settings
* PHP_AUTH_USER = xcache.admin.user, default cake
@ -40,6 +43,7 @@ class XcacheEngine extends CacheEngine {
* @access public
*/
var $settings = array();
/**
* Initialize the Cache Engine
*
@ -57,6 +61,7 @@ class XcacheEngine extends CacheEngine {
);
return function_exists('xcache_info');
}
/**
* Write data for key into cache
*
@ -71,6 +76,7 @@ class XcacheEngine extends CacheEngine {
xcache_set($key.'_expires', $expires, $duration);
return xcache_set($key, $value, $duration);
}
/**
* Read a key from the cache
*
@ -89,6 +95,7 @@ class XcacheEngine extends CacheEngine {
}
return false;
}
/**
* Delete a key from the cache
*
@ -99,6 +106,7 @@ class XcacheEngine extends CacheEngine {
function delete($key) {
return xcache_unset($key);
}
/**
* Delete all keys from the cache
*
@ -114,6 +122,7 @@ class XcacheEngine extends CacheEngine {
$this->__auth(true);
return true;
}
/**
* Populates and reverses $_SERVER authentication values
* Makes necessary changes (and reverting them back) in $_SERVER

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Logging.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Included libraries.
*
@ -31,6 +33,7 @@
if (!class_exists('File')) {
require LIBS . 'file.php';
}
/**
* Set up error level constants to be used within the framework if they are not defined within the
* system.
@ -48,6 +51,7 @@
if (!defined('LOG_INFO')) {
define('LOG_INFO', 6);
}
/**
* Logs messages to text files
*
@ -55,6 +59,7 @@
* @subpackage cake.cake.libs
*/
class CakeLog {
/**
* Writes given message to a log file in the logs directory.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Session class for Cake.
*
@ -38,6 +39,7 @@
* @subpackage cake.cake.libs
*/
class CakeSession extends Object {
/**
* True if the Session is still valid
*
@ -45,6 +47,7 @@ class CakeSession extends Object {
* @access public
*/
var $valid = false;
/**
* Error messages for this session
*
@ -52,6 +55,7 @@ class CakeSession extends Object {
* @access public
*/
var $error = false;
/**
* User agent string
*
@ -59,6 +63,7 @@ class CakeSession extends Object {
* @access protected
*/
var $_userAgent = '';
/**
* Path to where the session is active.
*
@ -66,6 +71,7 @@ class CakeSession extends Object {
* @access public
*/
var $path = '/';
/**
* Error number of last occurred error
*
@ -73,6 +79,7 @@ class CakeSession extends Object {
* @access public
*/
var $lastError = null;
/**
* 'Security.level' setting, "high", "medium", or "low".
*
@ -80,6 +87,7 @@ class CakeSession extends Object {
* @access public
*/
var $security = null;
/**
* Start time for this session.
*
@ -87,6 +95,7 @@ class CakeSession extends Object {
* @access public
*/
var $time = false;
/**
* Time when this session becomes invalid.
*
@ -94,6 +103,7 @@ class CakeSession extends Object {
* @access public
*/
var $sessionTime = false;
/**
* Keeps track of keys to watch for writes on
*
@ -101,6 +111,7 @@ class CakeSession extends Object {
* @access public
*/
var $watchKeys = array();
/**
* Current Session id
*
@ -108,6 +119,7 @@ class CakeSession extends Object {
* @access public
*/
var $id = null;
/**
* Constructor.
*
@ -116,7 +128,7 @@ class CakeSession extends Object {
* @access public
*/
function __construct($base = null, $start = true) {
App::import('Core', 'Security');
App::import('Core', 'Set', 'Security');
$this->time = time();
if (Configure::read('Session.checkAgent') === true || Configure::read('Session.checkAgent') === null) {
@ -167,6 +179,7 @@ class CakeSession extends Object {
}
parent::__construct();
}
/**
* Starts the Session.
*
@ -181,6 +194,7 @@ class CakeSession extends Object {
$this->__initSession();
return $this->__startSession();
}
/**
* Determine if Session has been started.
*
@ -193,6 +207,7 @@ class CakeSession extends Object {
}
return false;
}
/**
* Returns true if given variable is set in session.
*
@ -208,6 +223,7 @@ class CakeSession extends Object {
$result = Set::extract($_SESSION, $var);
return isset($result);
}
/**
* Returns the Session id
*
@ -226,6 +242,7 @@ class CakeSession extends Object {
return $this->id;
}
}
/**
* Removes a variable from session.
*
@ -246,6 +263,7 @@ class CakeSession extends Object {
$this->__setError(2, "$name doesn't exist");
return false;
}
/**
* Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself
*
@ -265,6 +283,7 @@ class CakeSession extends Object {
$old[$key] = $var;
}
}
/**
* Return error description for given error number.
*
@ -279,6 +298,7 @@ class CakeSession extends Object {
return $this->error[$errorNumber];
}
}
/**
* Returns last occurred error as a string, if any.
*
@ -292,6 +312,7 @@ class CakeSession extends Object {
return false;
}
}
/**
* Returns true if session is valid.
*
@ -311,6 +332,7 @@ class CakeSession extends Object {
}
return $this->valid;
}
/**
* Returns given session variable, or all of them, if no parameters given.
*
@ -333,6 +355,7 @@ class CakeSession extends Object {
$this->__setError(2, "$name doesn't exist");
return null;
}
/**
* Returns all session variables.
*
@ -346,6 +369,7 @@ class CakeSession extends Object {
$this->__setError(2, "No Session vars set");
return false;
}
/**
* Tells Session to write a notification when a certain session path or subpath is written to
*
@ -362,6 +386,7 @@ class CakeSession extends Object {
$this->watchKeys[] = $var;
}
}
/**
* Tells Session to stop watching a given key path
*
@ -382,6 +407,7 @@ class CakeSession extends Object {
}
}
}
/**
* Writes value to given session variable name.
*
@ -402,6 +428,7 @@ class CakeSession extends Object {
$this->__overwrite($_SESSION, Set::insert($_SESSION, $var, $value));
return (Set::extract($_SESSION, $var) === $value);
}
/**
* Helper method to destroy invalid sessions.
*
@ -415,6 +442,7 @@ class CakeSession extends Object {
$this->renew();
$this->_checkValid();
}
/**
* Helper method to initialize a session, based on Cake core settings.
*
@ -502,7 +530,7 @@ class CakeSession extends Object {
case 'cache':
if (empty($_SESSION)) {
if (!class_exists('Cache')) {
uses('Cache');
require LIBS . 'cache.php';
}
if ($iniSet) {
ini_set('session.use_trans_sid', 0);
@ -532,6 +560,7 @@ class CakeSession extends Object {
break;
}
}
/**
* Helper method to start a session
*
@ -553,6 +582,7 @@ class CakeSession extends Object {
return true;
}
}
/**
* Helper method to create a new session.
*
@ -589,6 +619,7 @@ class CakeSession extends Object {
$this->__setError(1, 'Session is valid');
}
}
/**
* Helper method to restart a session.
*
@ -624,6 +655,7 @@ class CakeSession extends Object {
}
}
}
/**
* Restarts this session.
*
@ -632,6 +664,7 @@ class CakeSession extends Object {
function renew() {
$this->__regenerateId();
}
/**
* Validate that the $name is in correct dot notation
* example: $name = 'ControllerName.key';
@ -647,6 +680,7 @@ class CakeSession extends Object {
$this->__setError(3, "$name is not a string");
return false;
}
/**
* Helper method to set an internal error message.
*
@ -662,6 +696,7 @@ class CakeSession extends Object {
$this->error[$errorNumber] = $errorMessage;
$this->lastError = $errorNumber;
}
/**
* Method called on open of a database session.
*
@ -671,6 +706,7 @@ class CakeSession extends Object {
function __open() {
return true;
}
/**
* Method called on close of a database session.
*
@ -691,6 +727,7 @@ class CakeSession extends Object {
}
return true;
}
/**
* Method used to read from a database session.
*
@ -711,6 +748,7 @@ class CakeSession extends Object {
return $row[$model->alias]['data'];
}
/**
* Helper function called on write for database sessions.
*
@ -740,6 +778,7 @@ class CakeSession extends Object {
return $return;
}
/**
* Method called on the destruction of a database session.
*
@ -753,6 +792,7 @@ class CakeSession extends Object {
return $return;
}
/**
* Helper function called on gc for database sessions.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Cake Socket connection class.
*
@ -23,6 +24,7 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'Validation');
/**
* Cake network socket connection class.
*
@ -32,6 +34,7 @@ App::import('Core', 'Validation');
* @subpackage cake.cake.libs
*/
class CakeSocket extends Object {
/**
* Object description
*
@ -39,6 +42,7 @@ class CakeSocket extends Object {
* @access public
*/
var $description = 'Remote DataSource Network Socket Interface';
/**
* Base configuration settings for the socket connection
*
@ -52,6 +56,7 @@ class CakeSocket extends Object {
'port' => 80,
'timeout' => 30
);
/**
* Configuration settings for the socket connection
*
@ -59,6 +64,7 @@ class CakeSocket extends Object {
* @access public
*/
var $config = array();
/**
* Reference to socket connection resource
*
@ -66,6 +72,7 @@ class CakeSocket extends Object {
* @access public
*/
var $connection = null;
/**
* This boolean contains the current state of the CakeSocket class
*
@ -73,6 +80,7 @@ class CakeSocket extends Object {
* @access public
*/
var $connected = false;
/**
* This variable contains an array with the last error number (num) and string (str)
*
@ -80,6 +88,7 @@ class CakeSocket extends Object {
* @access public
*/
var $lastError = array();
/**
* Constructor.
*
@ -93,6 +102,7 @@ class CakeSocket extends Object {
$this->config['protocol'] = getprotobyname($this->config['protocol']);
}
}
/**
* Connect the socket to the given host and port.
*
@ -120,7 +130,11 @@ class CakeSocket extends Object {
$this->setLastError($errStr, $errNum);
}
return $this->connected = is_resource($this->connection);
$this->connected = is_resource($this->connection);
if ($this->connected) {
stream_set_timeout($this->connection, $this->config['timeout']);
}
return $this->connected;
}
/**
@ -136,6 +150,7 @@ class CakeSocket extends Object {
return gethostbyaddr($this->address());
}
}
/**
* Get the IP address of the current connection.
*
@ -149,6 +164,7 @@ class CakeSocket extends Object {
return gethostbyname($this->config['host']);
}
}
/**
* Get all IP addresses associated with the current connection.
*
@ -162,6 +178,7 @@ class CakeSocket extends Object {
return gethostbynamel($this->config['host']);
}
}
/**
* Get the last error as a string.
*
@ -175,6 +192,7 @@ class CakeSocket extends Object {
return null;
}
}
/**
* Set the last error.
*
@ -185,6 +203,7 @@ class CakeSocket extends Object {
function setLastError($errNum, $errStr) {
$this->lastError = array('num' => $errNum, 'str' => $errStr);
}
/**
* Write data to the socket.
*
@ -218,11 +237,18 @@ class CakeSocket extends Object {
}
if (!feof($this->connection)) {
return fread($this->connection, $length);
$buffer = fread($this->connection, $length);
$info = stream_get_meta_data($this->connection);
if ($info['timed_out']) {
$this->setLastError(E_WARNING, __('Connection timed out', true));
return false;
}
return $buffer;
} else {
return false;
}
}
/**
* Abort socket operation.
*
@ -231,6 +257,7 @@ class CakeSocket extends Object {
*/
function abort() {
}
/**
* Disconnect the socket from the current connection.
*
@ -249,6 +276,7 @@ class CakeSocket extends Object {
}
return !$this->connected;
}
/**
* Destructor, used to disconnect from current connection.
*
@ -257,6 +285,7 @@ class CakeSocket extends Object {
function __destruct() {
$this->disconnect();
}
/**
* Resets the state of this Socket instance to it's initial state (before Object::__construct got executed)
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Class collections.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Class Collections.
*
@ -35,6 +37,7 @@
* @subpackage cake.cake.libs
*/
class ClassRegistry {
/**
* Names of classes with their objects.
*
@ -42,6 +45,7 @@ class ClassRegistry {
* @access private
*/
var $__objects = array();
/**
* Names of class names mapped to the object in the registry.
*
@ -49,6 +53,7 @@ class ClassRegistry {
* @access private
*/
var $__map = array();
/**
* Default constructor parameter settings, indexed by type
*
@ -56,6 +61,7 @@ class ClassRegistry {
* @access private
*/
var $__config = array();
/**
* Return a singleton instance of the ClassRegistry.
*
@ -69,16 +75,17 @@ class ClassRegistry {
}
return $instance[0];
}
/**
* Loads a class, registers the object in the registry and returns instance of the object.
*
* Examples
* Simple Use: Get a Post model instance ```ClassRegistry::init('Post');```
*
*
* Exapanded: ```array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass');```
*
*
* Model Classes can accept optional ```array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias);```
*
*
* When $class is a numeric keyed array, multiple class instances will be stored in the registry,
* no instance of the object will be returned
* {{{
@ -169,6 +176,7 @@ class ClassRegistry {
}
return ${$class};
}
/**
* Add $object to the registry, associating it with the name $key.
*
@ -187,6 +195,7 @@ class ClassRegistry {
}
return false;
}
/**
* Remove object which corresponds to given key.
*
@ -202,6 +211,7 @@ class ClassRegistry {
unset($_this->__objects[$key]);
}
}
/**
* Returns true if given key is present in the ClassRegistry.
*
@ -220,6 +230,7 @@ class ClassRegistry {
}
return false;
}
/**
* Get all keys from the registry.
*
@ -231,6 +242,7 @@ class ClassRegistry {
$_this =& ClassRegistry::getInstance();
return array_keys($_this->__objects);
}
/**
* Return object which corresponds to given key.
*
@ -253,6 +265,7 @@ class ClassRegistry {
}
return $return;
}
/**
* Sets the default constructor parameter for an object type
*
@ -277,6 +290,7 @@ class ClassRegistry {
}
$_this->__config[$type] = $param;
}
/**
* Checks to see if $alias is a duplicate $class Object
*
@ -297,6 +311,7 @@ class ClassRegistry {
}
return $duplicate;
}
/**
* Add a key name pair to the registry to map name to class in the registry.
*
@ -313,6 +328,7 @@ class ClassRegistry {
$_this->__map[$key] = $name;
}
}
/**
* Get all keys from the map in the registry.
*
@ -324,6 +340,7 @@ class ClassRegistry {
$_this =& ClassRegistry::getInstance();
return array_keys($_this->__map);
}
/**
* Return the name of a class in the registry.
*
@ -337,6 +354,7 @@ class ClassRegistry {
return $this->__map[$key];
}
}
/**
* Flushes all objects from the ClassRegistry.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Configuration class (singleton). Used for managing runtime configuration information.
*
@ -32,6 +34,7 @@
* @link http://book.cakephp.org/view/42/The-Configuration-Class
*/
class Configure extends Object {
/**
* Current debug level.
*
@ -40,13 +43,7 @@ class Configure extends Object {
* @access public
*/
var $debug = null;
/**
* Determines if $__objects cache should be written.
*
* @var boolean
* @access private
*/
var $__cache = false;
/**
* Returns a singleton instance of the Configure class.
*
@ -56,11 +53,15 @@ class Configure extends Object {
function &getInstance($boot = true) {
static $instance = array();
if (!$instance) {
if (!class_exists('Set')) {
require LIBS . 'set.php';
}
$instance[0] =& new Configure();
$instance[0]->__loadBootstrap($boot);
}
return $instance[0];
}
/**
* Used to store a dynamic variable in the Configure instance.
*
@ -92,19 +93,15 @@ class Configure extends Object {
$config = array($config => $value);
}
foreach ($config as $names => $value) {
$name = $_this->__configVarNames($names);
switch (count($name)) {
case 3:
$_this->{$name[0]}[$name[1]][$name[2]] = $value;
break;
case 2:
$_this->{$name[0]}[$name[1]] = $value;
break;
case 1:
$_this->{$name[0]} = $value;
break;
foreach ($config as $name => $value) {
if (strpos($name, '.') === false) {
$_this->{$name} = $value;
} else {
$names = explode('.', $name, 2);
if (!isset($_this->{$names[0]})) {
$_this->{$names[0]} = array();
}
$_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value);
}
}
@ -129,6 +126,7 @@ class Configure extends Object {
}
}
}
/**
* Used to read information stored in the Configure instance.
*
@ -154,27 +152,22 @@ class Configure extends Object {
}
return $_this->debug;
}
$name = $_this->__configVarNames($var);
switch (count($name)) {
case 3:
if (isset($_this->{$name[0]}[$name[1]][$name[2]])) {
return $_this->{$name[0]}[$name[1]][$name[2]];
}
break;
case 2:
if (isset($_this->{$name[0]}[$name[1]])) {
return $_this->{$name[0]}[$name[1]];
}
break;
case 1:
if (isset($_this->{$name[0]})) {
return $_this->{$name[0]};
}
break;
if (strpos($var, '.') !== false) {
$names = explode('.', $var, 2);
$var = $names[0];
}
return null;
if (!isset($_this->{$var})) {
return null;
}
if (!empty($names[1])) {
return Set::extract($_this->{$var}, $names[1]);
}
return $_this->{$var};
}
/**
* Used to delete a variable from the Configure instance.
*
@ -189,14 +182,16 @@ class Configure extends Object {
*/
function delete($var = null) {
$_this =& Configure::getInstance();
$name = $_this->__configVarNames($var);
if (count($name) > 1) {
unset($_this->{$name[0]}[$name[1]]);
} else {
unset($_this->{$name[0]});
if (strpos($var, '.') === false) {
unset($_this->{$var});
return;
}
$names = explode('.', $var, 2);
$_this->{$names[0]} = Set::remove($_this->{$names[0]}, $names[1]);
}
/**
* Loads a file from app/config/configure_file.php.
* Config file variables should be formated like:
@ -241,6 +236,7 @@ class Configure extends Object {
}
return Configure::write($config);
}
/**
* Used to determine the current version of CakePHP.
*
@ -259,6 +255,7 @@ class Configure extends Object {
}
return $_this->Cake['version'];
}
/**
* Used to write a config file to disk.
*
@ -297,6 +294,7 @@ class Configure extends Object {
}
Configure::__writeConfig($content, $name, $write);
}
/**
* Creates a cached version of a configuration file.
* Appends values passed from Configure::store() to the cached file
@ -332,22 +330,7 @@ class Configure extends Object {
}
}
}
/**
* Checks $name for dot notation to create dynamic Configure::$var as an array when needed.
*
* @param mixed $name Name to split
* @return array Name separated in items through dot notation
* @access private
*/
function __configVarNames($name) {
if (is_string($name)) {
if (strpos($name, ".")) {
return explode(".", $name);
}
return array($name);
}
return $name;
}
/**
* @deprecated
* @see App::objects()
@ -355,6 +338,7 @@ class Configure extends Object {
function listObjects($type, $path = null, $cache = true) {
return App::objects($type, $path, $cache);
}
/**
* @deprecated
* @see App::core()
@ -362,6 +346,7 @@ class Configure extends Object {
function corePaths($type = null) {
return App::core($type);
}
/**
* @deprecated
* @see App::build()
@ -369,6 +354,7 @@ class Configure extends Object {
function buildPaths($paths) {
return App::build($paths);
}
/**
* Loads app/config/bootstrap.php.
* If the alternative paths are set in this file
@ -414,37 +400,32 @@ class Configure extends Object {
}
if (Cache::config('_cake_core_') === false) {
Cache::config('_cake_core_', array_merge($cache['settings'], array(
Cache::config('_cake_core_', array_merge((array)$cache['settings'], array(
'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
'serialize' => true, 'duration' => $duration
)));
}
if (Cache::config('_cake_model_') === false) {
Cache::config('_cake_model_', array_merge($cache['settings'], array(
Cache::config('_cake_model_', array_merge((array)$cache['settings'], array(
'prefix' => $prefix . 'cake_model_', 'path' => $path . DS . 'models' . DS,
'serialize' => true, 'duration' => $duration
)));
}
Cache::config('default');
}
App::build(compact(
'models', 'views', 'controllers', 'helpers', 'components',
'behaviors', 'plugins', 'vendors', 'locales', 'shells'
));
}
}
/**
* Caches the object map when the instance of the Configure class is destroyed
*
* @access public
*/
function __destruct() {
if ($this->__cache) {
Cache::write('object_map', array_filter($this->__objects), '_cake_core_');
if (App::path('controllers') == array()) {
App::build(array(
'models' => $modelPaths, 'views' => $viewPaths, 'controllers' => $controllerPaths,
'helpers' => $helperPaths, 'components' => $componentPaths, 'behaviors' => $behaviorPaths,
'plugins' => $pluginPaths, 'vendors' => $vendorPaths, 'locales' => $localePaths,
'shells' => $shellPaths
));
}
}
}
}
/**
* Class and file loader.
*
@ -454,6 +435,7 @@ class Configure extends Object {
* @subpackage cake.cake.libs
*/
class App extends Object {
/**
* List of object types and their properties
*
@ -481,6 +463,7 @@ class App extends Object {
* @access public
*/
var $models = array();
/**
* List of additional path(s) where behavior files reside.
*
@ -488,6 +471,7 @@ class App extends Object {
* @access public
*/
var $behaviors = array();
/**
* List of additional path(s) where controller files reside.
*
@ -495,6 +479,7 @@ class App extends Object {
* @access public
*/
var $controllers = array();
/**
* List of additional path(s) where component files reside.
*
@ -502,6 +487,7 @@ class App extends Object {
* @access public
*/
var $components = array();
/**
* List of additional path(s) where view files reside.
*
@ -509,6 +495,7 @@ class App extends Object {
* @access public
*/
var $views = array();
/**
* List of additional path(s) where helper files reside.
*
@ -516,6 +503,7 @@ class App extends Object {
* @access public
*/
var $helpers = array();
/**
* List of additional path(s) where plugins reside.
*
@ -523,6 +511,7 @@ class App extends Object {
* @access public
*/
var $plugins = array();
/**
* List of additional path(s) where vendor packages reside.
*
@ -530,6 +519,7 @@ class App extends Object {
* @access public
*/
var $vendors = array();
/**
* List of additional path(s) where locale files reside.
*
@ -537,6 +527,7 @@ class App extends Object {
* @access public
*/
var $locales = array();
/**
* List of additional path(s) where console shell files reside.
*
@ -544,6 +535,7 @@ class App extends Object {
* @access public
*/
var $shells = array();
/**
* Paths to search for files.
*
@ -551,6 +543,7 @@ class App extends Object {
* @access public
*/
var $search = array();
/**
* Whether or not to return the file that is loaded.
*
@ -558,6 +551,7 @@ class App extends Object {
* @access public
*/
var $return = false;
/**
* Determines if $__maps and $__paths cache should be written.
*
@ -565,6 +559,7 @@ class App extends Object {
* @access private
*/
var $__cache = false;
/**
* Holds key/value pairs of $type => file path.
*
@ -572,6 +567,7 @@ class App extends Object {
* @access private
*/
var $__map = array();
/**
* Holds paths for deep searching of files.
*
@ -579,6 +575,7 @@ class App extends Object {
* @access private
*/
var $__paths = array();
/**
* Holds loaded files.
*
@ -586,6 +583,7 @@ class App extends Object {
* @access private
*/
var $__loaded = array();
/**
* Holds and key => value array of object types.
*
@ -593,6 +591,7 @@ class App extends Object {
* @access private
*/
var $__objects = array();
/**
* Used to read information stored path
*
@ -610,6 +609,7 @@ class App extends Object {
}
return $_this->{$type};
}
/**
* Build path references. Merges the supplied $paths
* with the base paths and the default core paths.
@ -668,6 +668,7 @@ class App extends Object {
}
}
}
/**
* 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.
@ -702,6 +703,7 @@ class App extends Object {
$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;
@ -719,6 +721,7 @@ class App extends Object {
}
return $paths;
}
/**
* Returns an index of objects of the given type, with the physical path to each object.
*
@ -744,7 +747,7 @@ class App extends Object {
$_this->__objects = Cache::read('object_map', '_cake_core_');
}
if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) {
if (!isset($_this->__objects[$name]) || $cache !== true) {
$types = $_this->types;
if (!isset($types[$type])) {
@ -772,15 +775,16 @@ class App extends Object {
$objects[$key] = Inflector::camelize($value);
}
}
if ($cache === true && !empty($objects)) {
$_this->__objects[$name] = $objects;
if ($cache === true) {
$_this->__cache = true;
} else {
return $objects;
}
$_this->__objects[$name] = $objects;
}
return $_this->__objects[$name];
}
/**
* Finds classes based on $name or specific file(s) to search.
*
@ -840,7 +844,7 @@ class App extends Object {
}
}
if (!App::import($tempType, $plugin . $class)) {
if (!App::import($tempType, $plugin . $class, $parent)) {
return false;
}
}
@ -862,7 +866,7 @@ class App extends Object {
if ($name != null && !class_exists($name . $ext['class'])) {
if ($load = $_this->__mapped($name . $ext['class'], $type, $plugin)) {
if ($_this->__load($load)) {
$_this->__overload($type, $name . $ext['class']);
$_this->__overload($type, $name . $ext['class'], $parent);
if ($_this->return) {
$value = include $load;
@ -904,7 +908,7 @@ class App extends Object {
if ($directory !== null) {
$_this->__cache = true;
$_this->__map($directory . $file, $name . $ext['class'], $type, $plugin);
$_this->__overload($type, $name . $ext['class']);
$_this->__overload($type, $name . $ext['class'], $parent);
if ($_this->return) {
$value = include $directory . $file;
@ -916,6 +920,7 @@ class App extends Object {
}
return true;
}
/**
* Returns a single instance of App.
*
@ -930,6 +935,7 @@ class App extends Object {
}
return $instance[0];
}
/**
* Locates the $file in $__paths, searches recursively.
*
@ -961,12 +967,14 @@ class App extends Object {
}
continue;
}
if (!isset($this->__paths[$path])) {
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
$Folder =& new Folder();
$directories = $Folder->tree($path, false, 'dir');
$directories = $Folder->tree($path, array('.svn', 'tests', 'templates'), 'dir');
sort($directories);
$this->__paths[$path] = $directories;
}
@ -978,6 +986,7 @@ class App extends Object {
}
return null;
}
/**
* Attempts to load $file.
*
@ -1001,6 +1010,7 @@ class App extends Object {
}
return false;
}
/**
* Maps the $name to the $file.
*
@ -1017,6 +1027,7 @@ class App extends Object {
$this->__map[$type][$name] = $file;
}
}
/**
* Returns a file's complete path.
*
@ -1039,6 +1050,7 @@ class App extends Object {
}
return false;
}
/**
* Used to overload objects as needed.
*
@ -1046,11 +1058,12 @@ class App extends Object {
* @param string $name Class name to overload
* @access private
*/
function __overload($type, $name) {
if (($type === 'Model' || $type === 'Helper') && strtolower($name) != 'schema') {
function __overload($type, $name, $parent) {
if (($type === 'Model' || $type === 'Helper') && $parent !== false) {
Overloadable::overload($name);
}
}
/**
* Loads parent classes based on $type.
* Returns a prefix or suffix needed for loading files.
@ -1075,10 +1088,10 @@ class App extends Object {
switch ($load) {
case 'model':
if (!class_exists('Model')) {
App::import('Core', 'Model', false, App::core('models'));
require LIBS . 'model' . DS . 'model.php';
}
if (!class_exists('AppModel')) {
App::import($type, 'AppModel', false, App::path('models'));
App::import($type, 'AppModel', false);
}
if ($plugin) {
if (!class_exists($plugin . 'AppModel')) {
@ -1135,6 +1148,7 @@ class App extends Object {
}
return array('class' => null, 'suffix' => null, 'path' => null);
}
/**
* Returns default search paths.
*
@ -1144,36 +1158,17 @@ class App extends Object {
*/
function __paths($type) {
$type = strtolower($type);
$paths = array();
if ($type === 'core') {
$path = App::core();
$paths = array();
foreach ($path as $key => $value) {
$count = count($key);
for ($i = 0; $i < $count; $i++) {
$paths[] = $path[$key][$i];
}
}
return $paths;
return App::core('libs');
}
if ($paths = App::path($type .'s')) {
return $paths;
}
switch ($type) {
case 'plugin':
return array(APP . 'plugins' . DS);
case 'vendor':
return array(APP . 'vendors' . DS, VENDORS, APP . 'plugins' . DS);
case 'controller':
return array(APP . 'controllers' . DS, APP);
case 'model':
return array(APP . 'models' . DS, APP);
case 'view':
return array(APP . 'views' . DS);
}
return $paths;
}
/**
* Removes file location from map if the file has been deleted.
*
@ -1190,6 +1185,7 @@ class App extends Object {
unset($this->__map[$type][$name]);
}
}
/**
* Returns an array of filenames of PHP files in the given directory.
*
@ -1222,6 +1218,7 @@ class App extends Object {
}
return $items;
}
/**
* Object destructor.
*
@ -1236,6 +1233,7 @@ class App extends Object {
unset($this->__paths[rtrim($core[0], DS)]);
Cache::write('dir_map', array_filter($this->__paths), '_cake_core_');
Cache::write('file_map', array_filter($this->__map), '_cake_core_');
Cache::write('object_map', $this->__objects, '_cake_core_');
}
}
}

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -25,6 +26,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* This is a placeholder class.
* Create the same file in app/app_controller.php

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
*
* PHP versions 4 and 5
@ -21,6 +22,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Handler for Controller::$components
*
@ -29,6 +31,7 @@
* @link http://book.cakephp.org/view/62/Components
*/
class Component extends Object {
/**
* Contains various controller variable information (plugin, name, base).
*
@ -36,6 +39,7 @@ class Component extends Object {
* @access private
*/
var $__controllerVars = array('plugin' => null, 'name' => null, 'base' => null);
/**
* List of loaded components.
*
@ -43,6 +47,7 @@ class Component extends Object {
* @access protected
*/
var $_loaded = array();
/**
* List of components attached directly to the controller, which callbacks
* should be executed on.
@ -51,6 +56,7 @@ class Component extends Object {
* @access protected
*/
var $_primary = array();
/**
* Settings for loaded components.
*
@ -58,6 +64,7 @@ class Component extends Object {
* @access private
**/
var $__settings = array();
/**
* Used to initialize the components for current controller.
*
@ -76,6 +83,7 @@ class Component extends Object {
$this->_loadComponents($controller);
}
/**
* Called before the Controller::beforeFilter().
*
@ -97,6 +105,7 @@ class Component extends Object {
}
}
}
/**
* Called after the Controller::beforeFilter() and before the controller action
*
@ -113,6 +122,7 @@ class Component extends Object {
}
}
}
/**
* Called after the Controller::beforeRender(), after the view class is loaded, and before the
* Controller::render()
@ -129,6 +139,7 @@ class Component extends Object {
}
}
}
/**
* Called before Controller::redirect().
*
@ -152,6 +163,7 @@ class Component extends Object {
}
return $response;
}
/**
* Called after Controller::render() and before the output is printed to the browser.
*
@ -167,6 +179,7 @@ class Component extends Object {
}
}
}
/**
* Loads components used by this component.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Access Control List factory class.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Access Control List factory class.
*
@ -33,6 +35,7 @@
* @subpackage cake.cake.libs.controller.components
*/
class AclComponent extends Object {
/**
* Instance of an ACL class
*
@ -40,6 +43,7 @@ class AclComponent extends Object {
* @access protected
*/
var $_Instance = null;
/**
* Constructor. Will return an instance of the correct ACL class.
*
@ -59,6 +63,7 @@ class AclComponent extends Object {
$this->_Instance =& new $name();
$this->_Instance->initialize($this);
}
/**
* Startup is not used
*
@ -69,6 +74,7 @@ class AclComponent extends Object {
function startup(&$controller) {
return true;
}
/**
* Empty class defintion, to be overridden in subclasses.
*
@ -76,6 +82,7 @@ class AclComponent extends Object {
*/
function _initACL() {
}
/**
* Pass-thru function for ACL check instance.
*
@ -88,6 +95,7 @@ class AclComponent extends Object {
function check($aro, $aco, $action = "*") {
return $this->_Instance->check($aro, $aco, $action);
}
/**
* Pass-thru function for ACL allow instance.
*
@ -100,6 +108,7 @@ class AclComponent extends Object {
function allow($aro, $aco, $action = "*") {
return $this->_Instance->allow($aro, $aco, $action);
}
/**
* Pass-thru function for ACL deny instance.
*
@ -112,6 +121,7 @@ class AclComponent extends Object {
function deny($aro, $aco, $action = "*") {
return $this->_Instance->deny($aro, $aco, $action);
}
/**
* Pass-thru function for ACL inherit instance.
*
@ -124,6 +134,7 @@ class AclComponent extends Object {
function inherit($aro, $aco, $action = "*") {
return $this->_Instance->inherit($aro, $aco, $action);
}
/**
* Pass-thru function for ACL grant instance.
*
@ -136,6 +147,7 @@ class AclComponent extends Object {
function grant($aro, $aco, $action = "*") {
return $this->_Instance->grant($aro, $aco, $action);
}
/**
* Pass-thru function for ACL grant instance.
*
@ -149,6 +161,7 @@ class AclComponent extends Object {
return $this->_Instance->revoke($aro, $aco, $action);
}
}
/**
* Access Control List abstract class. Not to be instantiated.
* Subclasses of this class are used by AclComponent to perform ACL checks in Cake.
@ -158,6 +171,7 @@ class AclComponent extends Object {
* @abstract
*/
class AclBase extends Object {
/**
* This class should never be instantiated, just subclassed.
*
@ -168,6 +182,7 @@ class AclBase extends Object {
return NULL;
}
}
/**
* Empty method to be overridden in subclasses
*
@ -178,6 +193,7 @@ class AclBase extends Object {
*/
function check($aro, $aco, $action = "*") {
}
/**
* Empty method to be overridden in subclasses
*
@ -187,6 +203,7 @@ class AclBase extends Object {
function initialize(&$component) {
}
}
/**
* In this file you can extend the AclBase.
*
@ -194,6 +211,7 @@ class AclBase extends Object {
* @subpackage cake.cake.libs.model
*/
class DbAcl extends AclBase {
/**
* Constructor
*
@ -206,6 +224,7 @@ class DbAcl extends AclBase {
$this->Aro =& ClassRegistry::init(array('class' => 'Aro', 'alias' => 'Aro'));
$this->Aco =& ClassRegistry::init(array('class' => 'Aco', 'alias' => 'Aco'));
}
/**
* Enter description here...
*
@ -217,6 +236,7 @@ class DbAcl extends AclBase {
$component->Aro = $this->Aro;
$component->Aco = $this->Aco;
}
/**
* Checks if the given $aro has access to action $action in $aco
*
@ -306,6 +326,7 @@ class DbAcl extends AclBase {
}
return false;
}
/**
* Allow $aro to have access to action $actions in $aco
*
@ -357,6 +378,7 @@ class DbAcl extends AclBase {
}
return ($this->Aro->Permission->save($save) !== false);
}
/**
* Deny access for $aro to action $action in $aco
*
@ -369,6 +391,7 @@ class DbAcl extends AclBase {
function deny($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, -1);
}
/**
* Let access for $aro to action $action in $aco be inherited
*
@ -381,6 +404,7 @@ class DbAcl extends AclBase {
function inherit($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action, 0);
}
/**
* Allow $aro to have access to action $actions in $aco
*
@ -394,6 +418,7 @@ class DbAcl extends AclBase {
function grant($aro, $aco, $action = "*") {
return $this->allow($aro, $aco, $action);
}
/**
* Deny access for $aro to action $action in $aco
*
@ -407,6 +432,7 @@ class DbAcl extends AclBase {
function revoke($aro, $aco, $action = "*") {
return $this->deny($aro, $aco, $action);
}
/**
* Get an array of access-control links between the given Aro and Aco
*
@ -433,6 +459,7 @@ class DbAcl extends AclBase {
)))
);
}
/**
* Get the keys used in an ACO
*
@ -451,6 +478,7 @@ class DbAcl extends AclBase {
return $newKeys;
}
}
/**
* In this file you can extend the AclBase.
*
@ -458,6 +486,7 @@ class DbAcl extends AclBase {
* @subpackage cake.cake.libs.model.iniacl
*/
class IniAcl extends AclBase {
/**
* Array with configuration, parsed from ini file
*
@ -465,12 +494,14 @@ class IniAcl extends AclBase {
* @access public
*/
var $config = null;
/**
* The constructor must be overridden, as AclBase is abstract.
*
*/
function __construct() {
}
/**
* Main ACL check function. Checks to see if the ARO (access request object) has access to the ACO (access control object).
* Looks at the acl.ini.php file for permissions (see instructions in /config/acl.ini.php).
@ -528,6 +559,7 @@ class IniAcl extends AclBase {
}
return false;
}
/**
* Parses an INI file and returns an array that reflects the INI file's section structure. Double-quote friendly.
*
@ -570,6 +602,7 @@ class IniAcl extends AclBase {
return $iniSetting;
}
/**
* Removes trailing spaces on all array elements (to prepare for searching)
*

View file

@ -37,6 +37,7 @@ App::import(array('Router', 'Security'));
* @subpackage cake.cake.libs.controller.components
*/
class AuthComponent extends Object {
/**
* Maintains current user login state.
*
@ -44,6 +45,7 @@ class AuthComponent extends Object {
* @access private
*/
var $_loggedIn = false;
/**
* Other components utilized by AuthComponent
*
@ -51,6 +53,7 @@ class AuthComponent extends Object {
* @access public
*/
var $components = array('Session', 'RequestHandler');
/**
* A reference to the object used for authentication
*
@ -58,6 +61,7 @@ class AuthComponent extends Object {
* @access public
*/
var $authenticate = null;
/**
* The name of the component to use for Authorization or set this to
* 'controller' will validate against Controller::isAuthorized()
@ -70,6 +74,7 @@ class AuthComponent extends Object {
* @access public
*/
var $authorize = false;
/**
* The name of an optional view element to render when an Ajax request is made
* with an invalid or expired session
@ -78,6 +83,7 @@ class AuthComponent extends Object {
* @access public
*/
var $ajaxLogin = null;
/**
* The name of the model that represents users which will be authenticated. Defaults to 'User'.
*
@ -85,6 +91,7 @@ class AuthComponent extends Object {
* @access public
*/
var $userModel = 'User';
/**
* Additional query conditions to use when looking up and authenticating users,
* i.e. array('User.is_active' => 1).
@ -93,6 +100,7 @@ class AuthComponent extends Object {
* @access public
*/
var $userScope = array();
/**
* Allows you to specify non-default login name and password fields used in
* $userModel, i.e. array('username' => 'login_name', 'password' => 'passwd').
@ -101,6 +109,7 @@ class AuthComponent extends Object {
* @access public
*/
var $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}".
@ -109,6 +118,7 @@ class AuthComponent extends Object {
* @access public
*/
var $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
@ -119,6 +129,7 @@ class AuthComponent extends Object {
* @access public
*/
var $actionPath = null;
/**
* A URL (defined as a string or array) to the controller action that handles
* logins.
@ -127,6 +138,7 @@ class AuthComponent extends Object {
* @access public
*/
var $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
@ -137,6 +149,7 @@ class AuthComponent extends Object {
* @access public
*/
var $loginRedirect = null;
/**
* The 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().
@ -148,6 +161,7 @@ class AuthComponent extends Object {
* @see AuthComponent::logout()
*/
var $logoutRedirect = null;
/**
* The name of model or model object, or any other object has an isAuthorized method.
*
@ -155,6 +169,7 @@ class AuthComponent extends Object {
* @access public
*/
var $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.
@ -163,6 +178,7 @@ class AuthComponent extends Object {
* @access public
*/
var $loginError = null;
/**
* Error to display when user attempts to access an object or action to which they do not have
* acccess.
@ -171,6 +187,7 @@ class AuthComponent extends Object {
* @access public
*/
var $authError = null;
/**
* Determines whether AuthComponent will automatically redirect and exit if login is successful.
*
@ -178,6 +195,7 @@ class AuthComponent extends Object {
* @access public
*/
var $autoRedirect = true;
/**
* Controller actions for which user validation is not required.
*
@ -186,6 +204,7 @@ class AuthComponent extends Object {
* @see AuthComponent::allow()
*/
var $allowedActions = array();
/**
* Maps actions to CRUD operations. Used for controller-based validation ($validate = 'controller').
*
@ -200,6 +219,7 @@ class AuthComponent extends Object {
'view' => 'read',
'remove' => 'delete'
);
/**
* Form data from Controller::$data
*
@ -207,6 +227,7 @@ class AuthComponent extends Object {
* @access public
*/
var $data = array();
/**
* Parameter data from Controller::$params
*
@ -214,6 +235,7 @@ class AuthComponent extends Object {
* @access public
*/
var $params = array();
/**
* Method list for bound controller
*
@ -221,6 +243,7 @@ class AuthComponent extends Object {
* @access protected
*/
var $_methods = array();
/**
* Initializes AuthComponent for use in the controller
*
@ -253,6 +276,7 @@ class AuthComponent extends Object {
Debugger::checkSessionKey();
}
}
/**
* Main execution method. Handles redirecting of invalid users, and processing
* of login form data.
@ -407,6 +431,7 @@ class AuthComponent extends Object {
$controller->redirect($controller->referer(), null, true);
return false;
}
/**
* Attempts to introspect the correct values for object properties including
* $userModel and $sessionKey.
@ -437,6 +462,7 @@ class AuthComponent extends Object {
}
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
@ -529,6 +555,7 @@ class AuthComponent extends Object {
}
return $valid;
}
/**
* Get authorization type
*
@ -550,6 +577,7 @@ class AuthComponent extends Object {
}
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.
@ -571,6 +599,7 @@ class AuthComponent extends Object {
$this->allowedActions = array_merge($this->allowedActions, $args);
}
}
/**
* Removes items from the list of allowed actions.
*
@ -591,6 +620,7 @@ class AuthComponent extends Object {
}
$this->allowedActions = array_values($this->allowedActions);
}
/**
* Maps action names to CRUD operations. Used for controller-based authentication.
*
@ -610,6 +640,7 @@ class AuthComponent extends Object {
}
}
}
/**
* 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
@ -636,6 +667,7 @@ class AuthComponent extends Object {
}
return $this->_loggedIn;
}
/**
* Logs a user out, and returns the login action to redirect to.
*
@ -651,6 +683,7 @@ class AuthComponent extends Object {
$this->_loggedIn = false;
return Router::normalize($this->logoutRedirect);
}
/**
* Get the current user from the session.
*
@ -674,6 +707,7 @@ class AuthComponent extends Object {
return null;
}
}
/**
* If no parameter is passed, gets the authentication redirect URL.
*
@ -697,6 +731,7 @@ class AuthComponent extends Object {
}
return Router::normalize($redir);
}
/**
* Validates a user against an abstract object.
*
@ -719,6 +754,7 @@ class AuthComponent extends Object {
}
return $this->Acl->check($user, $object, $action);
}
/**
* Returns the path to the ACO node bound to a controller/action.
*
@ -735,6 +771,7 @@ class AuthComponent extends Object {
$this->actionPath . $action
);
}
/**
* Returns a reference to the model object specified, and attempts
* to load it if it is not found.
@ -762,6 +799,7 @@ class AuthComponent extends Object {
return $model;
}
/**
* Identifies a user based on specific criteria.
*
@ -837,6 +875,7 @@ class AuthComponent extends Object {
}
return null;
}
/**
* Hash any passwords found in $data using $userModel and $fields['password']
*
@ -856,6 +895,7 @@ class AuthComponent extends Object {
}
return $data;
}
/**
* Hash a password with the application's salt value (as defined with Configure::write('Security.salt');
*
@ -866,6 +906,7 @@ class AuthComponent extends Object {
function password($password) {
return Security::hash($password, null, true);
}
/**
* Component shutdown. If user is logged in, wipe out redirect.
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,10 +25,12 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Load Security class
*/
App::import('Core', 'Security');
/**
* Cookie Component.
*
@ -38,6 +41,7 @@ App::import('Core', 'Security');
*
*/
class CookieComponent extends Object {
/**
* The name of the cookie.
*
@ -48,6 +52,7 @@ class CookieComponent extends Object {
* @access public
*/
var $name = 'CakeCookie';
/**
* The time a cookie will remain valid.
*
@ -60,6 +65,7 @@ class CookieComponent extends Object {
* @access public
*/
var $time = null;
/**
* Cookie path.
*
@ -75,6 +81,7 @@ class CookieComponent extends Object {
* @access public
*/
var $path = '/';
/**
* Domain path.
*
@ -90,6 +97,7 @@ class CookieComponent extends Object {
* @access public
*/
var $domain = '';
/**
* Secure HTTPS only cookie.
*
@ -103,6 +111,7 @@ class CookieComponent extends Object {
* @access public
*/
var $secure = false;
/**
* Encryption key.
*
@ -113,6 +122,7 @@ class CookieComponent extends Object {
* @access protected
*/
var $key = null;
/**
* Values stored in the cookie.
*
@ -123,6 +133,7 @@ class CookieComponent extends Object {
* @access private
*/
var $__values = array();
/**
* Type of encryption to use.
*
@ -134,6 +145,7 @@ class CookieComponent extends Object {
* @todo add additional encryption methods
*/
var $__type = 'cipher';
/**
* Used to reset cookie time if $expire is passed to CookieComponent::write()
*
@ -141,6 +153,7 @@ class CookieComponent extends Object {
* @access private
*/
var $__reset = null;
/**
* Expire time of the cookie
*
@ -150,6 +163,7 @@ class CookieComponent extends Object {
* @access private
*/
var $__expires = 0;
/**
* Main execution method.
*
@ -160,6 +174,7 @@ class CookieComponent extends Object {
$this->key = Configure::read('Security.salt');
$this->_set($settings);
}
/**
* Start CookieComponent for use in the controller
*
@ -172,6 +187,7 @@ class CookieComponent extends Object {
$this->__values = $this->__decrypt($_COOKIE[$this->name]);
}
}
/**
* Write a value to the $_COOKIE[$key];
*
@ -203,10 +219,10 @@ class CookieComponent extends Object {
if (count($name) > 1) {
$this->__values[$name[0]][$name[1]] = $value;
$this->__write("[".$name[0]."][".$name[1]."]", $value);
$this->__write("[" . $name[0] . "][" . $name[1] . "]", $value);
} else {
$this->__values[$name[0]] = $value;
$this->__write("[".$name[0]."]", $value);
$this->__write("[" . $name[0] . "]", $value);
}
} else {
foreach ($key as $names => $value) {
@ -214,15 +230,16 @@ class CookieComponent extends Object {
if (count($name) > 1) {
$this->__values[$name[0]][$name[1]] = $value;
$this->__write("[".$name[0]."][".$name[1]."]", $value);
$this->__write("[" . $name[0] . "][" . $name[1] . "]", $value);
} else {
$this->__values[$name[0]] = $value;
$this->__write("[".$name[0]."]", $value);
$this->__write("[" . $name[0] . "]", $value);
}
}
}
$this->__encrypted = true;
}
/**
* Read the value of the $_COOKIE[$key];
*
@ -258,6 +275,7 @@ class CookieComponent extends Object {
return null;
}
}
/**
* Delete a cookie value
*
@ -278,21 +296,22 @@ class CookieComponent extends Object {
$name = $this->__cookieVarNames($key);
if (count($name) > 1) {
if (isset($this->__values[$name[0]])) {
$this->__delete("[".$name[0]."][".$name[1]."]");
$this->__delete("[" . $name[0] . "][" . $name[1] . "]");
unset($this->__values[$name[0]][$name[1]]);
}
} else {
if (isset($this->__values[$name[0]])) {
if (is_array($this->__values[$name[0]])) {
foreach ($this->__values[$name[0]] as $key => $value) {
$this->__delete("[".$name[0]."][".$key."]");
$this->__delete("[" . $name[0] . "][" . $key . "]");
}
}
$this->__delete("[".$name[0]."]");
$this->__delete("[" . $name[0] . "]");
unset($this->__values[$name[0]]);
}
}
}
/**
* Destroy current cookie
*
@ -318,6 +337,7 @@ class CookieComponent extends Object {
$this->__delete("[$name]");
}
}
/**
* Will allow overriding default encryption method.
*
@ -328,6 +348,7 @@ class CookieComponent extends Object {
function type($type = 'cipher') {
$this->__type = 'cipher';
}
/**
* Set the expire time for a session variable.
*
@ -353,6 +374,7 @@ class CookieComponent extends Object {
}
return $this->__expires = strtotime($expires, $now);
}
/**
* Set cookie
*
@ -368,6 +390,7 @@ class CookieComponent extends Object {
$this->__reset = null;
}
}
/**
* Sets a cookie expire time to remove cookie value
*
@ -377,6 +400,7 @@ class CookieComponent extends Object {
function __delete($name) {
setcookie($this->name . $name, '', time() - 42000, $this->path, $this->domain, $this->secure);
}
/**
* Encrypts $value using var $type method in Security class
*
@ -395,6 +419,7 @@ class CookieComponent extends Object {
}
return($value);
}
/**
* Decrypts $value using var $type method in Security class
*
@ -449,6 +474,7 @@ class CookieComponent extends Object {
}
return $name;
}
/**
* Implode method to keep keys are multidimensional arrays
*
@ -463,6 +489,7 @@ class CookieComponent extends Object {
}
return substr($string, 1);
}
/**
* Explode method to return array from string set in CookieComponent::__implode()
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,6 +25,8 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'Multibyte');
/**
* EmailComponent
*
@ -34,8 +37,8 @@
* @subpackage cake.cake.libs.controller.components
*
*/
App::import('Core', 'Multibyte');
class EmailComponent extends Object{
/**
* Recipient of the email
*
@ -43,6 +46,7 @@ class EmailComponent extends Object{
* @access public
*/
var $to = null;
/**
* The mail which the email is sent from
*
@ -50,6 +54,7 @@ class EmailComponent extends Object{
* @access public
*/
var $from = null;
/**
* The email the recipient will reply to
*
@ -57,6 +62,7 @@ class EmailComponent extends Object{
* @access public
*/
var $replyTo = null;
/**
* The read receipt email
*
@ -64,6 +70,7 @@ class EmailComponent extends Object{
* @access public
*/
var $readReceipt = null;
/**
* The mail that will be used in case of any errors like
* - Remote mailserver down
@ -74,6 +81,7 @@ class EmailComponent extends Object{
* @access public
*/
var $return = null;
/**
* Carbon Copy
*
@ -84,6 +92,7 @@ class EmailComponent extends Object{
* @access public
*/
var $cc = array();
/**
* Blind Carbon Copy
*
@ -94,6 +103,7 @@ class EmailComponent extends Object{
* @access public
*/
var $bcc = array();
/**
* The subject of the email
*
@ -101,6 +111,7 @@ class EmailComponent extends Object{
* @access public
*/
var $subject = null;
/**
* Associative array of a user defined headers
* Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
@ -109,6 +120,7 @@ class EmailComponent extends Object{
* @access public
*/
var $headers = array();
/**
* List of additional headers
*
@ -118,6 +130,7 @@ class EmailComponent extends Object{
* @access public
*/
var $additionalParams = null;
/**
* Layout for the View
*
@ -125,6 +138,7 @@ class EmailComponent extends Object{
* @access public
*/
var $layout = 'default';
/**
* Template for the view
*
@ -132,6 +146,7 @@ class EmailComponent extends Object{
* @access public
*/
var $template = null;
/**
* as per RFC2822 Section 2.1.1
*
@ -139,10 +154,12 @@ class EmailComponent extends Object{
* @access public
*/
var $lineLength = 70;
/**
* @deprecated see lineLength
*/
var $_lineLength = null;
/**
* What format should the email be sent in
*
@ -155,6 +172,7 @@ class EmailComponent extends Object{
* @access public
*/
var $sendAs = 'text';
/**
* What method should the email be sent by
*
@ -167,6 +185,7 @@ class EmailComponent extends Object{
* @access public
*/
var $delivery = 'mail';
/**
* charset the email is sent in
*
@ -174,6 +193,7 @@ class EmailComponent extends Object{
* @access public
*/
var $charset = 'utf-8';
/**
* List of files that should be attached to the email.
*
@ -183,6 +203,7 @@ class EmailComponent extends Object{
* @access public
*/
var $attachments = array();
/**
* What mailer should EmailComponent identify itself as
*
@ -190,6 +211,7 @@ class EmailComponent extends Object{
* @access public
*/
var $xMailer = 'CakePHP Email Component';
/**
* The list of paths to search if an attachment isnt absolute
*
@ -197,6 +219,7 @@ class EmailComponent extends Object{
* @access public
*/
var $filePaths = array();
/**
* List of options to use for smtp mail method
*
@ -213,6 +236,7 @@ class EmailComponent extends Object{
var $smtpOptions = array(
'port'=> 25, 'host' => 'localhost', 'timeout' => 30
);
/**
* Placeholder for any errors that might happen with the
* smtp mail methods
@ -221,6 +245,7 @@ class EmailComponent extends Object{
* @access public
*/
var $smtpError = null;
/**
* If set to true, the mail method will be auto-set to 'debug'
*
@ -228,6 +253,7 @@ class EmailComponent extends Object{
* @access protected
*/
var $_debug = false;
/**
* Temporary store of message header lines
*
@ -235,6 +261,7 @@ class EmailComponent extends Object{
* @access private
*/
var $__header = array();
/**
* If set, boundary to use for multipart mime messages
*
@ -242,6 +269,7 @@ class EmailComponent extends Object{
* @access private
*/
var $__boundary = null;
/**
* Temporary store of message lines
*
@ -249,6 +277,7 @@ class EmailComponent extends Object{
* @access private
*/
var $__message = array();
/**
* Variable that holds SMTP connection
*
@ -256,6 +285,7 @@ class EmailComponent extends Object{
* @access private
*/
var $__smtpConnection = null;
/**
* Initialize component
*
@ -269,6 +299,7 @@ class EmailComponent extends Object{
}
$this->_set($settings);
}
/**
* Startup component
*
@ -276,6 +307,7 @@ class EmailComponent extends Object{
* @access public
*/
function startup(&$controller) {}
/**
* Send an email using the specified content, template and layout
*
@ -330,6 +362,7 @@ class EmailComponent extends Object{
return $sent;
}
/**
* Reset all EmailComponent internal variables to be able to send out a new email.
*
@ -346,10 +379,12 @@ class EmailComponent extends Object{
$this->subject = null;
$this->additionalParams = null;
$this->smtpError = null;
$this->attachments = array();
$this->__header = array();
$this->__boundary = null;
$this->__message = array();
}
/**
* Render the contents using the current layout and template.
*
@ -429,6 +464,7 @@ class EmailComponent extends Object{
return $msg;
}
/**
* Create unique boundary identifier
*
@ -437,6 +473,7 @@ class EmailComponent extends Object{
function __createBoundary() {
$this->__boundary = md5(uniqid(time()));
}
/**
* Create emails headers including (but not limited to) from email address, reply to,
* bcc and cc.
@ -490,11 +527,11 @@ class EmailComponent extends Object{
$this->__header[] = 'Content-Type: text/html; charset=' . $this->charset;
} elseif ($this->sendAs === 'both') {
$this->__header[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
$this->__header[] = '';
}
$this->__header[] = 'Content-Transfer-Encoding: 7bit';
}
/**
* Format the message by seeing if it has attachments.
*
@ -503,16 +540,21 @@ class EmailComponent extends Object{
*/
function __formatMessage($message) {
if (!empty($this->attachments)) {
$prefix = array(
'--' . $this->__boundary,
'Content-Type: text/plain; charset=' . $this->charset,
'Content-Transfer-Encoding: 7bit',
''
);
$prefix = array('--' . $this->__boundary);
if ($this->sendAs === 'text') {
$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
} elseif ($this->sendAs === 'html') {
$prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
} elseif ($this->sendAs === 'both') {
$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
}
$prefix[] = 'Content-Transfer-Encoding: 7bit';
$prefix[] = '';
$message = array_merge($prefix, $message);
}
return $message;
}
/**
* Attach files by adding file contents inside boundaries.
*
@ -543,6 +585,7 @@ class EmailComponent extends Object{
$this->__message[] = '';
}
}
/**
* Find the specified attachment in the list of file paths
*
@ -562,6 +605,7 @@ class EmailComponent extends Object{
}
return null;
}
/**
* Wrap the message using EmailComponent::$lineLength
*
@ -589,6 +633,7 @@ class EmailComponent extends Object{
$formatted[] = '';
return $formatted;
}
/**
* Encode the specified string using the current charset
*
@ -605,6 +650,7 @@ class EmailComponent extends Object{
}
return mb_encode_mimeheader($subject, $this->charset, 'B', $nl);
}
/**
* Format a string as an email address
*
@ -623,6 +669,7 @@ class EmailComponent extends Object{
}
return $this->__strip($string);
}
/**
* Remove certain elements (such as bcc:, to:, %0a) from given value
*
@ -644,6 +691,7 @@ class EmailComponent extends Object{
}
return $value;
}
/**
* Wrapper for PHP mail function used for sending out emails
*
@ -658,6 +706,7 @@ class EmailComponent extends Object{
}
return @mail($this->to, $this->__encode($this->subject), $message, $header, $this->additionalParams);
}
/**
* Sends out email via SMTP
*
@ -733,6 +782,7 @@ class EmailComponent extends Object{
$this->__smtpConnection->disconnect();
return true;
}
/**
* Private method for sending data to SMTP connection
*
@ -756,6 +806,7 @@ class EmailComponent extends Object{
}
return true;
}
/**
* Set as controller flash message a debug message showing current settings in component
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Request object for handling alternative HTTP requests
*
@ -37,6 +38,7 @@ if (!defined('REQUEST_MOBILE_UA')) {
*
*/
class RequestHandlerComponent extends Object {
/**
* The layout that will be switched to for Ajax requests
*
@ -45,6 +47,7 @@ class RequestHandlerComponent extends Object {
* @see RequestHandler::setAjax()
*/
var $ajaxLayout = 'ajax';
/**
* Determines whether or not callbacks will be fired on this component
*
@ -52,6 +55,7 @@ class RequestHandlerComponent extends Object {
* @access public
*/
var $enabled = true;
/**
* Holds the content-type of the response that is set when using
* RequestHandler::respondAs()
@ -60,6 +64,7 @@ class RequestHandlerComponent extends Object {
* @access private
*/
var $__responseTypeSet = null;
/**
* Holds the copy of Controller::$params
*
@ -67,6 +72,7 @@ class RequestHandlerComponent extends Object {
* @access public
*/
var $params = array();
/**
* Friendly content-type mappings used to set response types and determine
* request types. Can be modified with RequestHandler::setContent()
@ -104,6 +110,7 @@ class RequestHandlerComponent extends Object {
'zip' => 'application/x-zip',
'tar' => 'application/x-tar'
);
/**
* Content-types accepted by the client. If extension parsing is enabled in the
* Router, and an extension is detected, the corresponding content-type will be
@ -114,6 +121,7 @@ class RequestHandlerComponent extends Object {
* @see Router::parseExtensions()
*/
var $__acceptTypes = array();
/**
* The template to use when rendering the given content type.
*
@ -121,6 +129,7 @@ class RequestHandlerComponent extends Object {
* @access private
*/
var $__renderType = null;
/**
* Contains the file extension parsed out by the Router
*
@ -129,6 +138,7 @@ class RequestHandlerComponent extends Object {
* @see Router::parseExtensions()
*/
var $ext = null;
/**
* Flag set when MIME types have been initialized
*
@ -137,6 +147,7 @@ class RequestHandlerComponent extends Object {
* @see RequestHandler::__initializeTypes()
*/
var $__typesInitialized = false;
/**
* Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
*
@ -152,6 +163,7 @@ class RequestHandlerComponent extends Object {
}
parent::__construct();
}
/**
* Initializes the component, gets a reference to Controller::$parameters, and
* checks to see if a file extension has been parsed by the Router. If yes, the
@ -168,6 +180,7 @@ class RequestHandlerComponent extends Object {
$this->ext = $controller->params['url']['ext'];
}
}
/**
* The startup method of the RequestHandler enables several automatic behaviors
* related to the detection of certain properties of the HTTP request, including:
@ -217,6 +230,7 @@ class RequestHandlerComponent extends Object {
}
}
}
/**
* Handles (fakes) redirects for Ajax requests using requestAction()
*
@ -234,6 +248,7 @@ class RequestHandlerComponent extends Object {
echo $this->requestAction($url, array('return'));
$this->_stop();
}
/**
* Returns true if the current HTTP request is Ajax, false otherwise
*
@ -243,6 +258,7 @@ class RequestHandlerComponent extends Object {
function isAjax() {
return env('HTTP_X_REQUESTED_WITH') === "XMLHttpRequest";
}
/**
* Returns true if the current HTTP request is coming from a Flash-based client
*
@ -252,6 +268,7 @@ class RequestHandlerComponent extends Object {
function isFlash() {
return (preg_match('/^(Shockwave|Adobe) Flash/', env('HTTP_USER_AGENT')) == 1);
}
/**
* Returns true if the current request is over HTTPS, false otherwise.
*
@ -261,6 +278,7 @@ class RequestHandlerComponent extends Object {
function isSSL() {
return env('HTTPS');
}
/**
* Returns true if the current call accepts an XML response, false otherwise
*
@ -270,6 +288,7 @@ class RequestHandlerComponent extends Object {
function isXml() {
return $this->prefers('xml');
}
/**
* Returns true if the current call accepts an RSS response, false otherwise
*
@ -279,6 +298,7 @@ class RequestHandlerComponent extends Object {
function isRss() {
return $this->prefers('rss');
}
/**
* Returns true if the current call accepts an Atom response, false otherwise
*
@ -288,6 +308,7 @@ class RequestHandlerComponent extends Object {
function isAtom() {
return $this->prefers('atom');
}
/**
* Returns true if user agent string matches a mobile web browser, or if the
* client accepts WAP content.
@ -302,6 +323,7 @@ class RequestHandlerComponent extends Object {
}
return false;
}
/**
* Returns true if the client accepts WAP content
*
@ -311,6 +333,7 @@ class RequestHandlerComponent extends Object {
function isWap() {
return $this->prefers('wap');
}
/**
* Returns true if the current call a POST request
*
@ -320,6 +343,7 @@ class RequestHandlerComponent extends Object {
function isPost() {
return (strtolower(env('REQUEST_METHOD')) == 'post');
}
/**
* Returns true if the current call a PUT request
*
@ -329,6 +353,7 @@ class RequestHandlerComponent extends Object {
function isPut() {
return (strtolower(env('REQUEST_METHOD')) == 'put');
}
/**
* Returns true if the current call a GET request
*
@ -338,6 +363,7 @@ class RequestHandlerComponent extends Object {
function isGet() {
return (strtolower(env('REQUEST_METHOD')) == 'get');
}
/**
* Returns true if the current call a DELETE request
*
@ -347,6 +373,7 @@ class RequestHandlerComponent extends Object {
function isDelete() {
return (strtolower(env('REQUEST_METHOD')) == 'delete');
}
/**
* Gets Prototype version if call is Ajax, otherwise empty string.
* The Prototype library sets a special "Prototype version" HTTP header.
@ -360,6 +387,7 @@ class RequestHandlerComponent extends Object {
}
return false;
}
/**
* Adds/sets the Content-type(s) for the given name. This method allows
* content-types to be mapped to friendly aliases (or extensions), which allows
@ -379,6 +407,7 @@ class RequestHandlerComponent extends Object {
}
$this->__requestContent[$name] = $type;
}
/**
* Gets the server name from which this request was referred
*
@ -395,6 +424,7 @@ class RequestHandlerComponent extends Object {
}
return trim(preg_replace('/(?:\:.*)/', '', $sessHost));
}
/**
* Gets remote client IP
*
@ -421,6 +451,7 @@ class RequestHandlerComponent extends Object {
}
return trim($ipaddr);
}
/**
* Determines which content types the client accepts. Acceptance is based on
* the file extension parsed by the Router (if present), and by the HTTP_ACCEPT
@ -469,6 +500,7 @@ class RequestHandlerComponent extends Object {
}
}
}
/**
* Determines the content type of the data the client has sent (i.e. in a POST request)
*
@ -495,6 +527,7 @@ class RequestHandlerComponent extends Object {
return ($type == $this->mapType($contentType));
}
}
/**
* Determines which content-types the client prefers. If no parameters are given,
* the content-type that the client most likely prefers is returned. If $type is
@ -558,6 +591,7 @@ class RequestHandlerComponent extends Object {
$accepts = array_intersect($acceptedTypes, $accepts);
return $accepts[0];
}
/**
* Sets the layout and template paths for the content type defined by $type.
*
@ -585,7 +619,7 @@ class RequestHandlerComponent extends Object {
if (empty($this->__renderType)) {
$controller->viewPath .= '/' . $type;
} else {
$remove = preg_replace("/(?:\/{$type})$/", '/' . $type, $controller->viewPath);
$remove = preg_replace("/(?:\/{$this->__renderType})$/", '/' . $type, $controller->viewPath);
$controller->viewPath = $remove;
}
$this->__renderType = $type;
@ -607,6 +641,7 @@ class RequestHandlerComponent extends Object {
}
}
}
/**
* Sets the response header based on type map index name. If DEBUG is greater than 2, the header
* is not set.
@ -615,7 +650,7 @@ class RequestHandlerComponent extends Object {
* like 'application/x-shockwave'.
* @param array $options If $type is a friendly type name that is associated with
* more than one type of content, $index is used to select which content-type to use.
*
*
* @return boolean Returns false if the friendly type name given in $type does
* not exist in the type map, or if the Content-type header has
* already been set by this method.
@ -673,6 +708,7 @@ class RequestHandlerComponent extends Object {
}
return false;
}
/**
* Returns the current response type (Content-type header), or null if none has been set
*
@ -686,6 +722,7 @@ class RequestHandlerComponent extends Object {
}
return $this->mapType($this->__responseTypeSet);
}
/**
* Maps a content-type back to an alias
*
@ -717,6 +754,7 @@ class RequestHandlerComponent extends Object {
return $ctype;
}
}
/**
* Initializes MIME types
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Short description for file.
*
@ -33,6 +35,7 @@
* @subpackage cake.cake.libs.controller.components
*/
class SecurityComponent extends Object {
/**
* The controller method that will be called if this request is black-hole'd
*
@ -40,6 +43,7 @@ class SecurityComponent extends Object {
* @access public
*/
var $blackHoleCallback = null;
/**
* List of controller actions for which a POST request is required
*
@ -48,6 +52,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requirePost()
*/
var $requirePost = array();
/**
* List of controller actions for which a GET request is required
*
@ -56,6 +61,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireGet()
*/
var $requireGet = array();
/**
* List of controller actions for which a PUT request is required
*
@ -64,6 +70,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requirePut()
*/
var $requirePut = array();
/**
* List of controller actions for which a DELETE request is required
*
@ -72,6 +79,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireDelete()
*/
var $requireDelete = array();
/**
* List of actions that require an SSL-secured connection
*
@ -80,6 +88,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireSecure()
*/
var $requireSecure = array();
/**
* List of actions that require a valid authentication key
*
@ -88,6 +97,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireAuth()
*/
var $requireAuth = array();
/**
* List of actions that require an HTTP-authenticated login (basic or digest)
*
@ -96,6 +106,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireLogin()
*/
var $requireLogin = array();
/**
* Login options for SecurityComponent::requireLogin()
*
@ -104,6 +115,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireLogin()
*/
var $loginOptions = array('type' => '', 'prompt' => null);
/**
* An associative array of usernames/passwords used for HTTP-authenticated logins.
* If using digest authentication, passwords should be MD5-hashed.
@ -113,6 +125,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireLogin()
*/
var $loginUsers = array();
/**
* Controllers from which actions of the current controller are allowed to receive
* requests.
@ -122,6 +135,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireAuth()
*/
var $allowedControllers = array();
/**
* Actions from which actions of the current controller are allowed to receive
* requests.
@ -131,6 +145,7 @@ class SecurityComponent extends Object {
* @see SecurityComponent::requireAuth()
*/
var $allowedActions = array();
/**
* Form fields to disable
*
@ -138,6 +153,7 @@ class SecurityComponent extends Object {
* @access public
*/
var $disabledFields = array();
/**
* Whether to validate POST data. Set to false to disable for data coming from 3rd party
* services, etc.
@ -146,6 +162,7 @@ class SecurityComponent extends Object {
* @access public
*/
var $validatePost = true;
/**
* Other components used by the Security component
*
@ -153,12 +170,14 @@ class SecurityComponent extends Object {
* @access public
*/
var $components = array('RequestHandler', 'Session');
/**
* Holds the current action of the controller
*
* @var string
*/
var $_action = null;
/**
* Component startup. All security checking happens here.
*
@ -187,6 +206,7 @@ class SecurityComponent extends Object {
}
$this->_generateToken($controller);
}
/**
* Sets the actions that require a POST request, or empty for all actions
*
@ -197,6 +217,7 @@ class SecurityComponent extends Object {
$args = func_get_args();
$this->_requireMethod('Post', $args);
}
/**
* Sets the actions that require a GET request, or empty for all actions
*
@ -207,6 +228,7 @@ class SecurityComponent extends Object {
$args = func_get_args();
$this->_requireMethod('Get', $args);
}
/**
* Sets the actions that require a PUT request, or empty for all actions
*
@ -217,6 +239,7 @@ class SecurityComponent extends Object {
$args = func_get_args();
$this->_requireMethod('Put', $args);
}
/**
* Sets the actions that require a DELETE request, or empty for all actions
*
@ -227,6 +250,7 @@ class SecurityComponent extends Object {
$args = func_get_args();
$this->_requireMethod('Delete', $args);
}
/**
* Sets the actions that require a request that is SSL-secured, or empty for all actions
*
@ -237,6 +261,7 @@ class SecurityComponent extends Object {
$args = func_get_args();
$this->_requireMethod('Secure', $args);
}
/**
* Sets the actions that require an authenticated request, or empty for all actions
*
@ -247,6 +272,7 @@ class SecurityComponent extends Object {
$args = func_get_args();
$this->_requireMethod('Auth', $args);
}
/**
* Sets the actions that require an HTTP-authenticated request, or empty for all actions
*
@ -270,6 +296,7 @@ class SecurityComponent extends Object {
$this->loginUsers =& $this->loginOptions['users'];
}
}
/**
* Attempts to validate the login credentials for an HTTP-authenticated request
*
@ -308,6 +335,7 @@ class SecurityComponent extends Object {
}
return null;
}
/**
* Generates the text of an HTTP-authentication request header from an array of options.
*
@ -329,6 +357,7 @@ class SecurityComponent extends Object {
return $auth . ' ' . join(',', $out);
}
/**
* Parses an HTTP digest authentication response, and returns an array of the data, or null on failure.
*
@ -355,6 +384,7 @@ class SecurityComponent extends Object {
}
return null;
}
/**
* Generates a hash to be compared with an HTTP digest-authenticated response
*
@ -370,6 +400,7 @@ class SecurityComponent extends Object {
md5(env('REQUEST_METHOD') . ':' . $data['uri'])
);
}
/**
* Black-hole an invalid request with a 404 error or custom callback. If SecurityComponent::$blackHoleCallback
* is specified, it will use this callback by executing the method indicated in $error
@ -394,6 +425,7 @@ class SecurityComponent extends Object {
return $this->_callback($controller, $this->blackHoleCallback, array($error));
}
}
/**
* Sets the actions that require a $method HTTP request, or empty for all actions
*
@ -405,6 +437,7 @@ class SecurityComponent extends Object {
function _requireMethod($method, $actions = array()) {
$this->{'require' . $method} = (empty($actions)) ? array('*'): $actions;
}
/**
* Check if HTTP methods are required
*
@ -429,6 +462,7 @@ class SecurityComponent extends Object {
}
return true;
}
/**
* Check if access requires secure connection
*
@ -450,6 +484,7 @@ class SecurityComponent extends Object {
}
return true;
}
/**
* Check if authentication is required
*
@ -485,6 +520,7 @@ class SecurityComponent extends Object {
}
return true;
}
/**
* Check if login is required
*
@ -532,6 +568,7 @@ class SecurityComponent extends Object {
}
return true;
}
/**
* Validate submitted form
*
@ -612,6 +649,7 @@ class SecurityComponent extends Object {
$check = Security::hash(serialize($fieldList) . Configure::read('Security.salt'));
return ($token === $check);
}
/**
* Add authentication key for new form posts
*
@ -654,6 +692,7 @@ class SecurityComponent extends Object {
return true;
}
/**
* Sets the default login options for an HTTP-authenticated request
*
@ -670,6 +709,7 @@ class SecurityComponent extends Object {
), array_filter($options));
$options = array_merge(array('opaque' => md5($options['realm'])), $options);
}
/**
* Calls a controller callback method
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
@ -27,6 +28,7 @@
if (!class_exists('cakesession')) {
require LIBS . 'cake_session.php';
}
/**
* Session Component.
*
@ -37,6 +39,7 @@ if (!class_exists('cakesession')) {
*
*/
class SessionComponent extends CakeSession {
/**
* Used to determine if methods implementation is used, or bypassed
*
@ -44,6 +47,7 @@ class SessionComponent extends CakeSession {
* @access private
*/
var $__active = true;
/**
* Used to determine if Session has been started
*
@ -51,6 +55,7 @@ class SessionComponent extends CakeSession {
* @access private
*/
var $__started = false;
/**
* Used to determine if request are from an Ajax request
*
@ -58,6 +63,7 @@ class SessionComponent extends CakeSession {
* @access private
*/
var $__bare = 0;
/**
* Class constructor
*
@ -70,6 +76,7 @@ class SessionComponent extends CakeSession {
$this->__active = false;
}
}
/**
* Initializes the component, gets a reference to Controller::$param['bare'].
*
@ -82,6 +89,7 @@ class SessionComponent extends CakeSession {
$this->__bare = $controller->params['bare'];
}
}
/**
* Startup method.
*
@ -94,6 +102,7 @@ class SessionComponent extends CakeSession {
$this->__start();
}
}
/**
* Starts Session on if 'Session.start' is set to false in core.php
*
@ -108,6 +117,7 @@ class SessionComponent extends CakeSession {
parent::__construct($base);
$this->__active = true;
}
/**
* Used to write a value to a session key.
*
@ -137,6 +147,7 @@ class SessionComponent extends CakeSession {
}
return false;
}
/**
* Used to read a session values for a key or return values for all keys.
*
@ -154,6 +165,7 @@ class SessionComponent extends CakeSession {
}
return false;
}
/**
* Used to delete a session variable.
*
@ -170,6 +182,7 @@ class SessionComponent extends CakeSession {
}
return false;
}
/**
* Wrapper for SessionComponent::del();
*
@ -186,6 +199,7 @@ class SessionComponent extends CakeSession {
}
return false;
}
/**
* Used to check if a session variable is set
*
@ -202,6 +216,7 @@ class SessionComponent extends CakeSession {
}
return false;
}
/**
* Used to determine the last error in a session.
*
@ -217,6 +232,7 @@ class SessionComponent extends CakeSession {
}
return false;
}
/**
* Used to set a session variable that can be used to output messages in the view.
*
@ -236,6 +252,7 @@ class SessionComponent extends CakeSession {
$this->write('Message.' . $key, compact('message', 'layout', 'params'));
}
}
/**
* Used to renew a session id
*
@ -250,6 +267,7 @@ class SessionComponent extends CakeSession {
parent::renew();
}
}
/**
* Used to check for a valid session.
*
@ -265,6 +283,7 @@ class SessionComponent extends CakeSession {
}
return false;
}
/**
* Used to destroy sessions
*
@ -279,6 +298,7 @@ class SessionComponent extends CakeSession {
parent::destroy();
}
}
/**
* Returns Session id
*
@ -292,6 +312,7 @@ class SessionComponent extends CakeSession {
function id($id = null) {
return parent::id($id);
}
/**
* Starts Session if SessionComponent is used in Controller::beforeFilter(),
* or is called from

View file

@ -17,10 +17,12 @@
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Include files
*/
App::import('Core', array('Component', 'View'));
App::import('Controller', 'Component', false);
App::import('View', 'View', false);
/**
* Controller
*
@ -34,6 +36,7 @@ App::import('Core', array('Component', 'View'));
*
*/
class Controller extends Object {
/**
* The name of this controller. Controller names are plural, named after the model they manipulate.
*
@ -42,6 +45,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/52/name
*/
var $name = null;
/**
* Stores the current URL, relative to the webroot of the application.
*
@ -49,6 +53,7 @@ class Controller extends Object {
* @access public
*/
var $here = null;
/**
* The webroot of the application.
*
@ -56,6 +61,7 @@ class Controller extends Object {
* @access public
*/
var $webroot = null;
/**
* The name of the currently requested controller action.
*
@ -63,6 +69,7 @@ class Controller extends Object {
* @access public
*/
var $action = null;
/**
* An array containing the class names of models this controller uses.
*
@ -73,6 +80,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/53/components-helpers-and-uses
*/
var $uses = false;
/**
* An array containing the names of helpers this controller uses. The array elements should
* not contain the "Helper" part of the classname.
@ -84,6 +92,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/53/components-helpers-and-uses
*/
var $helpers = array('Html', 'Form');
/**
* Parameters received in the current request: GET and POST data, information
* about the request, etc.
@ -93,6 +102,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/55/The-Parameters-Attribute-params
*/
var $params = array();
/**
* Data POSTed to the controller using the HtmlHelper. Data here is accessible
* using the $this->data['ModelName']['fieldName'] pattern.
@ -101,6 +111,7 @@ class Controller extends Object {
* @access public
*/
var $data = array();
/**
* Holds pagination defaults for controller actions. The keys that can be included
* in this array are: 'conditions', 'fields', 'order', 'limit', 'page', and 'recursive',
@ -119,6 +130,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/164/Pagination
*/
var $paginate = array('limit' => 20, 'page' => 1);
/**
* The name of the views subfolder containing views for this controller.
*
@ -126,6 +138,7 @@ class Controller extends Object {
* @access public
*/
var $viewPath = null;
/**
* The name of the layouts subfolder containing layouts for this controller.
*
@ -133,6 +146,7 @@ class Controller extends Object {
* @access public
*/
var $layoutPath = null;
/**
* Contains variables to be handed to the view.
*
@ -140,6 +154,7 @@ class Controller extends Object {
* @access public
*/
var $viewVars = array();
/**
* Text to be used for the $title_for_layout layout variable (usually
* placed inside <title> tags.)
@ -149,6 +164,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/54/Page-related-Attributes-layout-and-pageTitle
*/
var $pageTitle = false;
/**
* An array containing the class names of the models this controller uses.
*
@ -156,6 +172,7 @@ class Controller extends Object {
* @access public
*/
var $modelNames = array();
/**
* Base URL path.
*
@ -163,6 +180,7 @@ class Controller extends Object {
* @access public
*/
var $base = null;
/**
* The name of the layout file to render the view inside of. The name specified
* is the filename of the layout in /app/views/layouts without the .ctp
@ -173,6 +191,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/54/Page-related-Attributes-layout-and-pageTitle
*/
var $layout = 'default';
/**
* Set to true to automatically render the view
* after action logic.
@ -181,6 +200,7 @@ class Controller extends Object {
* @access public
*/
var $autoRender = true;
/**
* Set to true to automatically render the layout around views.
*
@ -188,6 +208,7 @@ class Controller extends Object {
* @access public
*/
var $autoLayout = true;
/**
* Instance of Component used to handle callbacks.
*
@ -195,6 +216,7 @@ class Controller extends Object {
* @access public
*/
var $Component = null;
/**
* Array containing the names of components this controller uses. Component names
* should not contain the "Component" portion of the classname.
@ -206,6 +228,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/53/components-helpers-and-uses
*/
var $components = array();
/**
* The name of the View class this controller sends output to.
*
@ -213,6 +236,7 @@ class Controller extends Object {
* @access public
*/
var $view = 'View';
/**
* File extension for view templates. Defaults to Cake's conventional ".ctp".
*
@ -220,6 +244,7 @@ class Controller extends Object {
* @access public
*/
var $ext = '.ctp';
/**
* The output of the requested action. Contains either a variable
* returned from the action, or the data of the rendered view;
@ -229,6 +254,7 @@ class Controller extends Object {
* @access public
*/
var $output = null;
/**
* Automatically set to the name of a plugin.
*
@ -236,6 +262,7 @@ class Controller extends Object {
* @access public
*/
var $plugin = null;
/**
* Used to define methods a controller that will be cached. To cache a
* single action, the value is set to an array containing keys that match
@ -254,6 +281,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/346/Caching-in-the-Controller
*/
var $cacheAction = false;
/**
* Used to create cached instances of models a controller uses.
* When set to true, all models related to the controller will be cached.
@ -263,6 +291,7 @@ class Controller extends Object {
* @access public
*/
var $persistModel = false;
/**
* Holds all params passed and named.
*
@ -270,6 +299,7 @@ class Controller extends Object {
* @access public
*/
var $passedArgs = array();
/**
* Triggers Scaffolding
*
@ -278,6 +308,7 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/105/Scaffolding
*/
var $scaffold = false;
/**
* Holds current methods of the controller
*
@ -286,6 +317,7 @@ class Controller extends Object {
* @link
*/
var $methods = array();
/**
* This controller's primary model class name, the Inflector::classify()'ed version of
* the controller's $name property.
@ -296,6 +328,7 @@ class Controller extends Object {
* @access public
*/
var $modelClass = null;
/**
* This controller's model key name, an underscored version of the controller's $modelClass property.
*
@ -305,6 +338,7 @@ class Controller extends Object {
* @access public
*/
var $modelKey = null;
/**
* Holds any validation errors produced by the last call of the validateErrors() method/
*
@ -312,6 +346,7 @@ class Controller extends Object {
* @access public
*/
var $validationErrors = null;
/**
* Constructor.
*
@ -346,6 +381,7 @@ class Controller extends Object {
$this->methods = array_diff($childMethods, $parentMethods);
parent::__construct();
}
/**
* Merge components, helpers, and uses vars from AppController and PluginAppController.
*
@ -427,6 +463,7 @@ class Controller extends Object {
}
}
}
/**
* Loads Model classes based on the the uses property
* see Controller::loadModel(); for more info.
@ -464,6 +501,7 @@ class Controller extends Object {
}
return true;
}
/**
* Loads and instantiates models required by this controller.
* If Controller::persistModel; is true, controller will cache model instances on first request,
@ -528,6 +566,7 @@ class Controller extends Object {
$this->modelNames[] = $modelClass;
}
}
/**
* Redirects to given $url, after turning off $this->autoRender.
* Script execution is halted after the redirect.
@ -640,6 +679,7 @@ class Controller extends Object {
$this->_stop();
}
}
/**
* Convenience method for header()
*
@ -650,6 +690,7 @@ class Controller extends Object {
function header($status) {
header($status);
}
/**
* Saves a variable for use inside a view template.
*
@ -681,6 +722,7 @@ class Controller extends Object {
}
}
}
/**
* Internally redirects one action to another. Examples:
*
@ -699,6 +741,7 @@ class Controller extends Object {
unset($args[0]);
return call_user_func_array(array(&$this, $action), $args);
}
/**
* Controller callback to tie into Auth component.
* Only called when AuthComponent::authorize is set to 'controller'.
@ -713,6 +756,7 @@ class Controller extends Object {
), E_USER_WARNING);
return false;
}
/**
* Returns number of errors in a submitted FORM.
*
@ -728,6 +772,7 @@ class Controller extends Object {
}
return count($errors);
}
/**
* Validates models passed by parameters. Example:
*
@ -752,6 +797,7 @@ class Controller extends Object {
return $this->validationErrors = (count($errors) ? $errors : false);
}
/**
* Instantiates the correct view class, hands it its data, and uses it to render the view output.
*
@ -816,6 +862,7 @@ class Controller extends Object {
return $this->output;
}
/**
* Returns the referring URL for this request.
*
@ -846,6 +893,7 @@ class Controller extends Object {
}
return '/';
}
/**
* Forces the user's browser not to cache the results of the current request.
*
@ -860,6 +908,7 @@ class Controller extends Object {
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
/**
* Shows a message to the user for $pause seconds, then redirects to $url.
* Uses flash.ctp as the default layout for the message.
@ -880,6 +929,7 @@ class Controller extends Object {
$this->set('page_title', $message);
$this->render(false, 'flash');
}
/**
* Converts POST'ed form data to a model conditions array, suitable for use in a Model::find() call.
*
@ -936,6 +986,7 @@ class Controller extends Object {
}
return $cond;
}
/**
* Handles automatic pagination of model records.
*
@ -1130,6 +1181,7 @@ class Controller extends Object {
}
return $results;
}
/**
* Called before the controller action.
*
@ -1138,6 +1190,7 @@ class Controller extends Object {
*/
function beforeFilter() {
}
/**
* Called after the controller action is run, but before the view is rendered.
*
@ -1146,6 +1199,7 @@ class Controller extends Object {
*/
function beforeRender() {
}
/**
* Called after the controller action is run and rendered.
*
@ -1154,6 +1208,7 @@ class Controller extends Object {
*/
function afterFilter() {
}
/**
* This method should be overridden in child classes.
*
@ -1165,6 +1220,7 @@ class Controller extends Object {
function _beforeScaffold($method) {
return true;
}
/**
* This method should be overridden in child classes.
*
@ -1176,6 +1232,7 @@ class Controller extends Object {
function _afterScaffoldSave($method) {
return true;
}
/**
* This method should be overridden in child classes.
*
@ -1187,6 +1244,7 @@ class Controller extends Object {
function _afterScaffoldSaveError($method) {
return true;
}
/**
* This method should be overridden in child classes.
* If not it will render a scaffold error.

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Static content controller.
*
@ -24,6 +25,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Static content controller
*
@ -33,6 +35,7 @@
* @subpackage cake.cake.libs.controller
*/
class PagesController extends AppController {
/**
* Controller name
*
@ -40,6 +43,7 @@ class PagesController extends AppController {
* @access public
*/
var $name = 'Pages';
/**
* Default helper
*
@ -47,6 +51,7 @@ class PagesController extends AppController {
* @access public
*/
var $helpers = array('Html');
/**
* This controller does not use a model
*
@ -54,6 +59,7 @@ class PagesController extends AppController {
* @access public
*/
var $uses = array();
/**
* Displays a view
*

View file

@ -19,6 +19,7 @@
* @since Cake v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Scaffolding is a set of automatic actions for starting web development work faster.
*
@ -31,6 +32,7 @@
* @subpackage cake.cake.libs.controller
*/
class Scaffold extends Object {
/**
* Controller object
*
@ -38,6 +40,7 @@ class Scaffold extends Object {
* @access public
*/
var $controller = null;
/**
* Name of the controller to scaffold
*
@ -45,6 +48,7 @@ class Scaffold extends Object {
* @access public
*/
var $name = null;
/**
* Action to be performed.
*
@ -52,6 +56,7 @@ class Scaffold extends Object {
* @access public
*/
var $action = null;
/**
* Name of current model this view context is attached to
*
@ -59,6 +64,7 @@ class Scaffold extends Object {
* @access public
*/
var $model = null;
/**
* Path to View.
*
@ -66,6 +72,7 @@ class Scaffold extends Object {
* @access public
*/
var $viewPath;
/**
* Path parts for creating links in views.
*
@ -73,6 +80,7 @@ class Scaffold extends Object {
* @access public
*/
var $base = null;
/**
* Name of layout to use with this View.
*
@ -80,6 +88,7 @@ class Scaffold extends Object {
* @access public
*/
var $layout = 'default';
/**
* Array of parameter data
*
@ -87,6 +96,7 @@ class Scaffold extends Object {
* @access public
*/
var $params;
/**
* File extension. Defaults to Cake's template ".ctp".
*
@ -94,6 +104,7 @@ class Scaffold extends Object {
* @access public
*/
var $ext = '.ctp';
/**
* Sub-directory for this view file.
*
@ -101,6 +112,7 @@ class Scaffold extends Object {
* @access public
*/
var $subDir = null;
/**
* Plugin name.
*
@ -108,6 +120,7 @@ class Scaffold extends Object {
* @access public
*/
var $plugin = null;
/**
* valid session.
*
@ -115,6 +128,7 @@ class Scaffold extends Object {
* @access public
*/
var $_validSession = null;
/**
* List of variables to collect from the associated controller
*
@ -125,6 +139,7 @@ class Scaffold extends Object {
'action', 'base', 'webroot', 'layout', 'name',
'viewPath', 'ext', 'params', 'data', 'plugin', 'cacheAction'
);
/**
* Title HTML element for current scaffolded view
*
@ -132,6 +147,7 @@ class Scaffold extends Object {
* @access public
*/
var $scaffoldTitle = null;
/**
* Construct and set up given controller with given parameters.
*
@ -186,6 +202,7 @@ class Scaffold extends Object {
isset($this->controller->Session) && $this->controller->Session->valid() != false
);
}
/**
* Outputs the content of a scaffold method passing it through the Controller::afterFilter()
*
@ -196,6 +213,7 @@ class Scaffold extends Object {
$this->controller->afterFilter();
echo($this->controller->output);
}
/**
* Renders a view action of scaffolded model.
*
@ -231,6 +249,7 @@ class Scaffold extends Object {
return $this->__scaffoldError();
}
}
/**
* Renders index action of scaffolded model.
*
@ -250,6 +269,7 @@ class Scaffold extends Object {
return $this->__scaffoldError();
}
}
/**
* Renders an add or edit action for scaffolded model.
*
@ -261,6 +281,7 @@ class Scaffold extends Object {
$this->controller->render($action, $this->layout);
$this->_output();
}
/**
* Saves or updates the scaffolded model.
*
@ -354,6 +375,7 @@ class Scaffold extends Object {
return $this->__scaffoldError();
}
}
/**
* Performs a delete on given scaffolded Model.
*
@ -407,6 +429,7 @@ class Scaffold extends Object {
return $this->__scaffoldError();
}
}
/**
* Show a scaffold error
*
@ -417,6 +440,7 @@ class Scaffold extends Object {
return $this->controller->render('error', $this->layout);
$this->_output();
}
/**
* When methods are now present in a controller
* scaffoldView is used to call default Scaffold methods if:
@ -489,6 +513,7 @@ class Scaffold extends Object {
)));
}
}
/**
* Returns associations for controllers models.
*
@ -529,6 +554,7 @@ if (!class_exists('ThemeView')) {
}
class ScaffoldView extends ThemeView {
/**
* Override _getViewFileName
*

View file

@ -130,13 +130,15 @@ class Debugger extends Object {
define('E_DEPRECATED', 8192);
}
$e = '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-trace\')';
$e = '<pre class="cake-debug">';
$e .= '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-trace\')';
$e .= '.style.display = (document.getElementById(\'{:id}-trace\').style.display == ';
$e .= '\'none\' ? \'\' : \'none\');"><b>{:error}</b> ({:code})</a>: {:description} ';
$e .= '[<b>{:path}</b>, line <b>{:line}</b>]';
$e .= '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
$e .= '{:links}{:info}</div>';
$e .= '</pre>';
$this->_templates['js']['error'] = $e;
$t = '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
@ -164,7 +166,7 @@ class Debugger extends Object {
$this->_templates['js']['code'] .= 'style="display: none;"><pre>{:code}</pre></div>';
$e = '<pre class="cake-debug"><b>{:error}</b> ({:code}) : {:description} ';
$e = '<pre class="cake-debug"><b>{:error}</b> ({:code}) : {:description} ';
$e .= '[<b>{:path}</b>, line <b>{:line}]</b></pre>';
$this->_templates['html']['error'] = $e;

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Error handler
*
@ -25,6 +26,7 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Controller', 'App');
/**
* Error Handling Controller
*
@ -35,12 +37,14 @@ App::import('Controller', 'App');
*/
class CakeErrorController extends AppController {
var $name = 'CakeError';
/**
* Uses Property
*
* @var array
*/
var $uses = array();
/**
* __construct
*
@ -56,6 +60,7 @@ class CakeErrorController extends AppController {
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
}
}
/**
* Error Handler.
*
@ -67,6 +72,7 @@ class CakeErrorController extends AppController {
* @subpackage cake.cake.libs
*/
class ErrorHandler extends Object {
/**
* Controller instance.
*
@ -74,6 +80,7 @@ class ErrorHandler extends Object {
* @access public
*/
var $controller = null;
/**
* Class constructor.
*
@ -118,6 +125,7 @@ class ErrorHandler extends Object {
$this->dispatchMethod($method, $messages);
$this->_stop();
}
/**
* Displays an error page (e.g. 404 Not found).
*
@ -134,6 +142,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('error404');
}
/**
* Convenience method to display a 404 page.
*
@ -156,6 +165,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('error404');
}
/**
* Renders the Missing Controller web page.
*
@ -173,6 +183,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingController');
}
/**
* Renders the Missing Action web page.
*
@ -191,6 +202,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingAction');
}
/**
* Renders the Private Action web page.
*
@ -207,6 +219,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('privateAction');
}
/**
* Renders the Missing Table web page.
*
@ -223,6 +236,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingTable');
}
/**
* Renders the Missing Database web page.
*
@ -235,6 +249,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingScaffolddb');
}
/**
* Renders the Missing View web page.
*
@ -252,6 +267,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingView');
}
/**
* Renders the Missing Layout web page.
*
@ -268,6 +284,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingLayout');
}
/**
* Renders the Database Connection web page.
*
@ -283,6 +300,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingConnection');
}
/**
* Renders the Missing Helper file web page.
*
@ -299,6 +317,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingHelperFile');
}
/**
* Renders the Missing Helper class web page.
*
@ -315,6 +334,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingHelperClass');
}
/**
* Renders the Missing Component file web page.
*
@ -332,6 +352,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingComponentFile');
}
/**
* Renders the Missing Component class web page.
*
@ -349,6 +370,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingComponentClass');
}
/**
* Renders the Missing Model class web page.
*
@ -364,6 +386,7 @@ class ErrorHandler extends Object {
));
$this->_outputMessage('missingModel');
}
/**
* Output message
*

View file

@ -1,5 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Convenience class for reading, writing and appending to files.
*
@ -22,6 +23,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Included libraries.
*
@ -32,6 +34,7 @@ if (!class_exists('Object')) {
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
/**
* Convenience class for reading, writing and appending to files.
*
@ -39,6 +42,7 @@ if (!class_exists('Folder')) {
* @subpackage cake.cake.libs
*/
class File extends Object {
/**
* Folder object of the File
*
@ -46,6 +50,7 @@ class File extends Object {
* @access public
*/
var $Folder = null;
/**
* Filename
*
@ -53,6 +58,7 @@ class File extends Object {
* @access public
*/
var $name = null;
/**
* file info
*
@ -60,6 +66,7 @@ class File extends Object {
* @access public
*/
var $info = array();
/**
* Holds the file handler resource if the file is opened
*
@ -67,6 +74,7 @@ class File extends Object {
* @access public
*/
var $handle = null;
/**
* enable locking for file reading and writing
*
@ -74,6 +82,7 @@ class File extends Object {
* @access public
*/
var $lock = null;
/**
* path property
*
@ -83,6 +92,7 @@ class File extends Object {
* @access public
*/
var $path = null;
/**
* Constructor
*
@ -109,6 +119,7 @@ class File extends Object {
}
}
}
/**
* Closes the current file if it is opened
*
@ -117,6 +128,7 @@ class File extends Object {
function __destruct() {
$this->close();
}
/**
* Creates the File.
*
@ -134,6 +146,7 @@ class File extends Object {
}
return false;
}
/**
* Opens the current file with a given $mode
*
@ -159,6 +172,7 @@ class File extends Object {
}
return false;
}
/**
* Return the contents of this File as a string.
*
@ -196,6 +210,7 @@ class File extends Object {
}
return $data;
}
/**
* Sets or gets the offset for the currently opened file.
*
@ -214,6 +229,7 @@ class File extends Object {
}
return false;
}
/**
* Prepares a ascii string for writing
* fixes line endings
@ -257,6 +273,7 @@ class File extends Object {
}
return $success;
}
/**
* Append given data string to this File.
*
@ -268,6 +285,7 @@ class File extends Object {
function append($data, $force = false) {
return $this->write($data, 'a', $force);
}
/**
* Closes the current file if it is opened.
*
@ -280,6 +298,7 @@ class File extends Object {
}
return fclose($this->handle);
}
/**
* Deletes the File.
*
@ -293,6 +312,7 @@ class File extends Object {
}
return false;
}
/**
* Returns the File extension.
*
@ -308,6 +328,7 @@ class File extends Object {
}
return $this->info;
}
/**
* Returns the File extension.
*
@ -323,6 +344,7 @@ class File extends Object {
}
return false;
}
/**
* Returns the File name without extension.
*
@ -340,6 +362,7 @@ class File extends Object {
}
return false;
}
/**
* makes filename safe for saving
*
@ -356,6 +379,7 @@ class File extends Object {
}
return preg_replace( "/(?:[^\w\.-]+)/", "_", basename($name, $ext));
}
/**
* Get md5 Checksum of file with previous check of Filesize
*
@ -375,6 +399,7 @@ class File extends Object {
return false;
}
/**
* Returns the full path of the File.
*
@ -387,6 +412,7 @@ class File extends Object {
}
return $this->path;
}
/**
* Returns true if the File exists.
*
@ -396,6 +422,7 @@ class File extends Object {
function exists() {
return (file_exists($this->path) && is_file($this->path));
}
/**
* Returns the "chmod" (permissions) of the File.
*
@ -408,6 +435,7 @@ class File extends Object {
}
return false;
}
/**
* Returns the Filesize
*
@ -420,6 +448,7 @@ class File extends Object {
}
return false;
}
/**
* Returns true if the File is writable.
*
@ -429,6 +458,7 @@ class File extends Object {
function writable() {
return is_writable($this->path);
}
/**
* Returns true if the File is executable.
*
@ -438,6 +468,7 @@ class File extends Object {
function executable() {
return is_executable($this->path);
}
/**
* Returns true if the File is readable.
*
@ -447,6 +478,7 @@ class File extends Object {
function readable() {
return is_readable($this->path);
}
/**
* Returns the File's owner.
*
@ -459,6 +491,7 @@ class File extends Object {
}
return false;
}
/**
* Returns the File group.
*
@ -471,6 +504,7 @@ class File extends Object {
}
return false;
}
/**
* Returns last access time.
*
@ -483,6 +517,7 @@ class File extends Object {
}
return false;
}
/**
* Returns last modified time.
*
@ -495,6 +530,7 @@ class File extends Object {
}
return false;
}
/**
* Returns the current folder.
*

Some files were not shown because too many files have changed in this diff Show more