2007-03-09 23:15:03 +00:00
< ? php
2007-03-27 05:10:42 +00:00
/* SVN FILE: $Id$ */
/**
2007-05-13 20:17:27 +00:00
* Base class for Shells
2007-03-27 05:10:42 +00:00
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) : Rapid Development Framework < http :// www . cakephp . org />
* Copyright 2005 - 2007 , Cake Software Foundation , Inc .
* 1785 E . Sahara Avenue , Suite 490 - 204
* Las Vegas , Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
* @ copyright Copyright 2005 - 2007 , Cake Software Foundation , Inc .
* @ link http :// www . cakefoundation . org / projects / info / cakephp CakePHP ( tm ) Project
* @ package cake
2007-05-14 01:14:41 +00:00
* @ subpackage cake . cake . console . libs
* @ since CakePHP ( tm ) v 1.2 . 0.5012
2007-03-27 05:10:42 +00:00
* @ version $Revision $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / mit - license . php The MIT License
*/
2007-05-14 12:23:25 +00:00
require_once CAKE . 'console' . DS . 'error.php' ;
2007-03-09 23:15:03 +00:00
/**
* Base class for command - line utilities for automating programmer chores .
*
* @ package cake
2007-05-13 20:17:27 +00:00
* @ subpackage cake . cake . console . libs
2007-03-09 23:15:03 +00:00
*/
2007-05-12 21:18:07 +00:00
class Shell extends Object {
2007-03-09 23:15:03 +00:00
/**
2007-10-22 05:52:20 +00:00
* An instance of the ShellDispatcher object that loaded this script
2007-03-09 23:15:03 +00:00
*
2007-10-22 05:52:20 +00:00
* @ var object
* @ access public
2007-03-09 23:15:03 +00:00
*/
2007-05-04 19:32:05 +00:00
var $Dispatch = null ;
2007-03-09 23:15:03 +00:00
/**
* If true , the script will ask for permission to perform actions .
*
* @ var boolean
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
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 .
*
* @ var object
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
2007-10-22 05:52:20 +00:00
var $DbConfig = null ;
2007-03-09 23:15:03 +00:00
/**
* Contains command switches parsed from the command line .
*
* @ var array
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
var $params = array ();
/**
* Contains arguments parsed from the command line .
*
* @ var array
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
var $args = array ();
2007-05-13 20:17:27 +00:00
/**
* The file name of the shell that was invoked .
*
* @ var string
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 20:17:27 +00:00
*/
var $shell = null ;
/**
* The class name of the shell that was invoked .
*
* @ var string
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 20:17:27 +00:00
*/
var $className = null ;
/**
* The command called if public methods are available .
*
* @ var string
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 20:17:27 +00:00
*/
var $command = null ;
/**
* The name of the shell in camelized .
*
* @ var string
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 20:17:27 +00:00
*/
var $name = null ;
/**
* Contains tasks to load and instantiate
*
* @ var array
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 20:17:27 +00:00
*/
var $tasks = array ();
2007-05-13 22:03:03 +00:00
/**
2007-05-14 01:14:41 +00:00
* Contains the loaded tasks
2007-05-13 22:03:03 +00:00
*
* @ var array
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 22:03:03 +00:00
*/
2007-05-14 01:14:41 +00:00
var $taskNames = array ();
2007-05-13 20:17:27 +00:00
/**
* Contains models to load and instantiate
*
* @ var array
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 20:17:27 +00:00
*/
var $uses = array ();
2007-03-09 23:15:03 +00:00
/**
2007-05-12 21:18:07 +00:00
* Constructs this Shell instance .
2007-03-09 23:15:03 +00:00
*
*/
function __construct ( & $dispatch ) {
2007-05-13 20:17:27 +00:00
$vars = array ( 'params' , 'args' , 'shell' , 'shellName' => 'name' , 'shellClass' => 'className' , 'shellCommand' => 'command' );
2007-06-20 06:15:35 +00:00
foreach ( $vars as $key => $var ) {
2007-06-20 07:51:52 +00:00
if ( is_string ( $key )) {
2007-06-03 23:56:04 +00:00
$this -> { $var } =& $dispatch -> { $key };
2007-05-13 20:17:27 +00:00
} else {
2007-06-03 23:56:04 +00:00
$this -> { $var } =& $dispatch -> { $var };
2007-05-13 20:17:27 +00:00
}
2007-05-12 23:40:37 +00:00
}
2007-06-03 23:56:04 +00:00
$shellKey = Inflector :: underscore ( $this -> name );
ClassRegistry :: addObject ( $shellKey , $this );
ClassRegistry :: map ( $shellKey , $shellKey );
2007-06-20 06:15:35 +00:00
if ( ! PHP5 && isset ( $this -> args [ 0 ]) && strpos ( low ( get_class ( $this )), low ( Inflector :: camelize ( $this -> args [ 0 ]))) !== false ) {
2007-06-03 23:56:04 +00:00
$dispatch -> shiftArgs ();
2007-06-21 14:38:46 +00:00
}
2007-06-20 06:15:35 +00:00
if ( ! PHP5 && isset ( $this -> args [ 0 ]) && low ( $this -> command ) == low ( Inflector :: variable ( $this -> args [ 0 ])) && method_exists ( $this , $this -> command )) {
2007-06-03 23:56:04 +00:00
$dispatch -> shiftArgs ();
2007-06-04 19:07:50 +00:00
}
2007-06-03 23:56:04 +00:00
$this -> Dispatch =& $dispatch ;
2007-05-04 00:25:04 +00:00
}
/**
2007-05-12 21:18:07 +00:00
* Initializes the Shell
2007-06-04 07:21:17 +00:00
* acts as constructor for subclasses
* allows configuration of tasks prior to shell execution
2007-05-04 00:25:04 +00:00
*
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-04 03:49:53 +00:00
*/
2007-05-04 00:25:04 +00:00
function initialize () {
2007-05-13 20:17:27 +00:00
$this -> _loadModels ();
2007-06-04 07:21:17 +00:00
}
/**
* Starts up the the Shell
* allows for checking and configuring prior to command or main execution
* can be overriden in subclasses
*
2007-10-22 05:52:20 +00:00
* @ access public
2007-06-04 07:21:17 +00:00
*/
function startup () {
2007-05-13 20:49:37 +00:00
$this -> _welcome ();
}
/**
* Displays a header for the shell
*
2007-10-22 05:52:20 +00:00
* @ access protected
2007-05-13 20:49:37 +00:00
*/
function _welcome () {
2007-05-13 20:17:27 +00:00
$this -> out ( 'App : ' . APP_DIR );
2007-05-12 19:47:14 +00:00
$this -> out ( 'Path: ' . ROOT . DS . APP_DIR );
$this -> hr ();
2007-03-09 23:15:03 +00:00
}
2007-05-04 00:25:04 +00:00
/**
* Loads database file and constructs DATABASE_CONFIG class
2007-10-22 05:52:20 +00:00
* makes $this -> DbConfig available to subclasses
2007-05-04 00:25:04 +00:00
*
* @ return bool
2007-10-22 05:52:20 +00:00
* @ access protected
2007-05-04 00:25:04 +00:00
*/
2007-05-03 21:14:46 +00:00
function _loadDbConfig () {
2007-10-22 05:52:20 +00:00
if ( config ( 'database' ) && class_exists ( 'DATABASE_CONFIG' )) {
$this -> DbConfig =& new DATABASE_CONFIG ();
return true ;
2007-05-03 21:14:46 +00:00
}
2007-05-04 00:25:04 +00:00
$this -> err ( 'Database config could not be loaded' );
2007-05-13 01:36:56 +00:00
$this -> out ( 'Run \'bake\' to create the database configuration' );
2007-05-03 21:14:46 +00:00
return false ;
}
2007-05-04 00:25:04 +00:00
/**
2007-05-13 20:17:27 +00:00
* if var $uses = true
2007-05-04 00:25:04 +00:00
* Loads AppModel file and constructs AppModel class
* makes $this -> AppModel available to subclasses
2007-06-03 23:56:04 +00:00
* if var $uses is an array of models will load those models
2007-05-04 00:25:04 +00:00
*
* @ return bool
2007-10-22 05:52:20 +00:00
* @ access protected
2007-05-04 00:25:04 +00:00
*/
2007-05-13 20:17:27 +00:00
function _loadModels () {
2007-06-20 06:15:35 +00:00
if ( $this -> uses === null || $this -> uses === false ) {
2007-05-13 20:17:27 +00:00
return ;
}
2007-05-03 21:14:46 +00:00
uses ( 'model' . DS . 'connection_manager' ,
'model' . DS . 'datasources' . DS . 'dbo_source' , 'model' . DS . 'model'
);
2007-06-20 06:15:35 +00:00
if ( $this -> uses === true && loadModel ()) {
2007-05-13 01:36:56 +00:00
$this -> AppModel = & new AppModel ( false , false , false );
2007-05-03 21:14:46 +00:00
return true ;
}
2007-05-13 20:17:27 +00:00
if ( $this -> uses !== true && ! empty ( $this -> uses )) {
$uses = is_array ( $this -> uses ) ? $this -> uses : array ( $this -> uses );
$this -> modelClass = $uses [ 0 ];
2007-06-20 06:15:35 +00:00
foreach ( $uses as $modelClass ) {
2007-05-13 20:17:27 +00:00
$modelKey = Inflector :: underscore ( $modelClass );
2007-06-20 07:51:52 +00:00
if ( ! class_exists ( $modelClass )) {
2007-05-13 20:17:27 +00:00
loadModel ( $modelClass );
}
2007-06-20 06:15:35 +00:00
if ( class_exists ( $modelClass )) {
2007-05-13 20:17:27 +00:00
$model =& new $modelClass ();
$this -> modelNames [] = $modelClass ;
$this -> { $modelClass } =& $model ;
ClassRegistry :: addObject ( $modelKey , $model );
} else {
return $this -> cakeError ( 'missingModel' , array ( array ( 'className' => $modelClass )));
}
}
return true ;
}
2007-05-03 21:14:46 +00:00
return false ;
}
2007-05-13 20:17:27 +00:00
/**
* Loads tasks defined in var $tasks
*
* @ return bool
2007-10-22 05:52:20 +00:00
* @ access public
2007-05-13 20:17:27 +00:00
*/
2007-06-03 23:56:04 +00:00
function loadTasks () {
2007-06-20 06:15:35 +00:00
if ( $this -> tasks === null || $this -> tasks === false ) {
2007-05-13 20:17:27 +00:00
return ;
}
2007-05-03 21:14:46 +00:00
2007-05-13 20:17:27 +00:00
if ( $this -> tasks !== true && ! empty ( $this -> tasks )) {
$tasks = $this -> tasks ;
2007-06-20 06:15:35 +00:00
if ( ! is_array ( $tasks )) {
2007-05-13 20:17:27 +00:00
$tasks = array ( $tasks );
}
2007-06-20 06:15:35 +00:00
foreach ( $tasks as $taskName ) {
2007-05-13 20:17:27 +00:00
$loaded = false ;
2007-06-20 06:15:35 +00:00
foreach ( $this -> Dispatch -> shellPaths as $path ) {
2007-05-13 20:17:27 +00:00
$taskPath = $path . 'tasks' . DS . Inflector :: underscore ( $taskName ) . '.php' ;
if ( file_exists ( $taskPath )) {
$loaded = true ;
break ;
}
}
2007-05-15 01:16:10 +00:00
2007-05-13 20:17:27 +00:00
if ( $loaded ) {
2007-06-03 23:56:04 +00:00
$taskKey = Inflector :: underscore ( $taskName );
2007-05-13 20:17:27 +00:00
$taskClass = Inflector :: camelize ( $taskName . 'Task' );
2007-06-20 06:15:35 +00:00
if ( ! class_exists ( $taskClass )) {
2007-05-14 12:23:25 +00:00
require_once $taskPath ;
}
2007-06-03 23:56:04 +00:00
if ( ClassRegistry :: isKeySet ( $taskKey )) {
$this -> taskNames [] = $taskName ;
if ( ! PHP5 ) {
$this -> { $taskName } =& ClassRegistry :: getObject ( $taskKey );
ClassRegistry :: map ( $taskName , $taskKey );
} else {
$this -> { $taskName } = ClassRegistry :: getObject ( $taskKey );
ClassRegistry :: map ( $taskName , $taskKey );
}
} else {
2007-05-13 20:17:27 +00:00
$this -> taskNames [] = $taskName ;
2007-06-03 23:56:04 +00:00
if ( ! PHP5 ) {
$this -> { $taskName } =& new $taskClass ( $this -> Dispatch );
} else {
$this -> { $taskName } = new $taskClass ( $this -> Dispatch );
}
2007-05-15 01:16:10 +00:00
}
2007-06-20 06:15:35 +00:00
if ( ! isset ( $this -> { $taskName })) {
2007-05-13 20:17:27 +00:00
$this -> err ( " Task ' " . $taskName . " ' could not be loaded " );
exit ();
}
} else {
$this -> err ( " Task ' " . $taskName . " ' could not be found " );
exit ();
}
}
}
return false ;
}
2007-03-09 23:15:03 +00:00
/**
* Prompts the user for input , and returns it .
*
* @ param string $prompt Prompt text .
* @ param mixed $options Array or string of options .
* @ param string $default Default input value .
* @ return Either the default value , or the user - provided input .
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
function in ( $prompt , $options = null , $default = null ) {
2007-05-14 12:23:25 +00:00
$in = $this -> Dispatch -> getInput ( $prompt , $options , $default );
2007-06-20 06:15:35 +00:00
if ( $options && is_string ( $options )) {
if ( strpos ( $options , ',' )) {
2007-05-14 12:23:25 +00:00
$options = explode ( ',' , $options );
2007-06-20 06:15:35 +00:00
} elseif ( strpos ( $options , '/' )) {
2007-05-14 12:23:25 +00:00
$options = explode ( '/' , $options );
} else {
$options = array ( $options );
}
}
2007-06-20 06:15:35 +00:00
if ( is_array ( $options )) {
while ( $in == '' || ( $in && ( ! in_array ( low ( $in ), $options ) && ! in_array ( up ( $in ), $options )) && ! in_array ( $in , $options ))) {
2007-05-14 12:23:25 +00:00
$in = $this -> Dispatch -> getInput ( $prompt , $options , $default );
}
}
2007-06-20 06:15:35 +00:00
if ( $in ) {
2007-05-14 12:23:25 +00:00
return $in ;
}
2007-03-09 23:15:03 +00:00
}
/**
* Outputs to the stdout filehandle .
*
* @ param string $string String to output .
2007-10-22 16:54:36 +00:00
* @ param boolean $newline If true , the outputs gets an added newline .
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
function out ( $string , $newline = true ) {
2007-10-28 04:18:18 +00:00
if ( is_array ( $string )) {
2007-08-21 14:17:45 +00:00
$str = '' ;
foreach ( $string as $message ) {
$str .= $message . " \n " ;
}
$string = $str ;
}
2007-05-04 03:49:53 +00:00
return $this -> Dispatch -> stdout ( $string , $newline );
2007-03-09 23:15:03 +00:00
}
/**
* Outputs to the stderr filehandle .
*
* @ param string $string Error text to output .
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
function err ( $string ) {
2007-10-28 04:18:18 +00:00
if ( is_array ( $string )) {
2007-08-21 14:17:45 +00:00
$str = '' ;
foreach ( $string as $message ) {
$str .= $message . " \n " ;
}
$string = $str ;
}
2007-05-04 04:37:25 +00:00
return $this -> Dispatch -> stderr ( $string . " \n " );
2007-03-09 23:15:03 +00:00
}
/**
* Outputs a series of minus characters to the standard output , acts as a visual separator .
*
2007-10-22 16:54:36 +00:00
* @ param boolean $newline If true , the outputs gets an added newline .
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
2007-05-02 18:41:55 +00:00
function hr ( $newline = false ) {
if ( $newline ) {
$this -> out ( " \n " );
}
2007-03-09 23:15:03 +00:00
$this -> out ( '---------------------------------------------------------------' );
2007-05-02 18:41:55 +00:00
if ( $newline ) {
$this -> out ( " \n " );
}
2007-03-09 23:15:03 +00:00
}
2007-05-04 03:49:53 +00:00
/**
2007-10-22 05:52:20 +00:00
* Displays a formatted error message and exits the application
2007-05-04 03:49:53 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $title Title of the error message
* @ param string $msg Error message
* @ access public
2007-05-04 03:49:53 +00:00
*/
2007-05-14 12:23:25 +00:00
function error ( $title , $msg ) {
2007-05-23 17:27:30 +00:00
$out = " $title\n " ;
2007-05-04 03:49:53 +00:00
$out .= " $msg\n " ;
$out .= " \n " ;
2007-05-14 12:23:25 +00:00
$this -> err ( $out );
2007-05-04 03:49:53 +00:00
exit ();
}
/**
* Will check the number args matches otherwise throw an error
*
2007-10-22 16:11:12 +00:00
* @ param integer $expectedNum Expected number of paramters
2007-10-22 05:52:20 +00:00
* @ param string $command Command
* @ access protected
2007-05-04 03:49:53 +00:00
*/
2007-05-04 19:32:05 +00:00
function _checkArgs ( $expectedNum , $command = null ) {
2007-06-20 06:15:35 +00:00
if ( ! $command ) {
2007-05-04 03:49:53 +00:00
$command = $this -> command ;
}
if ( count ( $this -> args ) < $expectedNum ) {
2007-06-03 23:56:04 +00:00
$this -> error ( " Wrong number of parameters: " . count ( $this -> args ), " Expected: { $expectedNum } \n Please type 'cake { $this -> shell } help' for help on usage of the { $this -> name } { $command } " );
2007-05-04 03:49:53 +00:00
}
}
2007-03-09 23:15:03 +00:00
/**
2007-10-22 05:52:20 +00:00
* Creates a file at given path
2007-03-09 23:15:03 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $path Where to put the file .
2007-03-09 23:15:03 +00:00
* @ param string $contents Content to put in the file .
2007-10-22 16:09:35 +00:00
* @ return boolean Success
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
function createFile ( $path , $contents ) {
$path = str_replace ( DS . DS , DS , $path );
2007-09-18 04:16:04 +00:00
$this -> out ( " \n " . sprintf ( __ ( " Creating file %s " , true ), $path ));
2007-03-09 23:15:03 +00:00
if ( is_file ( $path ) && $this -> interactive === true ) {
2007-05-14 12:23:25 +00:00
$key = $this -> in ( __ ( " File exists, overwrite? " , true ) . " { $path } " , array ( 'y' , 'n' , 'q' ), 'n' );
if ( low ( $key ) == 'q' ) {
2007-05-03 21:14:46 +00:00
$this -> out ( __ ( " Quitting. " , true ) . " \n " );
2007-03-09 23:15:03 +00:00
exit ;
2007-06-20 06:15:35 +00:00
} elseif ( low ( $key ) == 'a' ) {
2007-03-09 23:15:03 +00:00
$this -> dont_ask = true ;
2007-06-20 06:15:35 +00:00
} elseif ( low ( $key ) != 'y' ) {
2007-05-03 21:14:46 +00:00
$this -> out ( __ ( " Skip " , true ) . " { $path } \n " );
2007-03-09 23:15:03 +00:00
return false ;
}
}
2007-06-20 06:15:35 +00:00
if ( ! class_exists ( 'File' )) {
2007-05-14 12:23:25 +00:00
uses ( 'file' );
}
2007-10-25 02:22:40 +00:00
2007-05-03 23:22:02 +00:00
if ( $File = new File ( $path , true )) {
2007-10-25 03:10:31 +00:00
$data = $File -> prepare ( $contents );
$File -> write ( $data );
2007-05-14 12:23:25 +00:00
$this -> out ( __ ( " Wrote " , true ) . " { $path } " );
2007-03-09 23:15:03 +00:00
return true ;
} else {
2007-05-03 21:14:46 +00:00
$this -> err ( __ ( " Error! Could not write to " , true ) . " { $path } . \n " );
2007-03-09 23:15:03 +00:00
return false ;
}
}
/**
2007-05-07 15:30:06 +00:00
* Outputs usage text on the standard output . Implement it in subclasses .
2007-03-09 23:15:03 +00:00
*
2007-10-22 05:52:20 +00:00
* @ access public
2007-03-09 23:15:03 +00:00
*/
function help () {
2007-06-20 06:15:35 +00:00
if ( $this -> command != null ) {
2007-05-13 20:17:27 +00:00
$this -> err ( " Unknown { $this -> name } command ' $this->command '. \n For usage, try 'cake { $this -> shell } help'. \n \n " );
2007-06-20 07:51:52 +00:00
} else {
2007-05-13 20:17:27 +00:00
$this -> Dispatch -> help ();
}
2007-03-09 23:15:03 +00:00
}
/**
2007-10-22 05:52:20 +00:00
* Action to create a Unit Test
2007-03-09 23:15:03 +00:00
*
2007-10-22 16:09:35 +00:00
* @ return boolean Success
2007-10-22 05:52:20 +00:00
* @ access protected
2007-03-09 23:15:03 +00:00
*/
2007-05-14 12:23:25 +00:00
function _checkUnitTest () {
if ( is_dir ( VENDORS . 'simpletest' ) || is_dir ( ROOT . DS . APP_DIR . DS . 'vendors' . DS . 'simpletest' )) {
2007-03-09 23:15:03 +00:00
return true ;
}
2007-05-14 12:23:25 +00:00
$unitTest = $this -> in ( 'Cake test suite not installed. Do you want to bake unit test files anyway?' , array ( 'y' , 'n' ), 'y' );
$result = low ( $unitTest ) == 'y' || low ( $unitTest ) == 'yes' ;
if ( $result ) {
$this -> out ( " \n You can download the Cake test suite from http://cakeforge.org/projects/testsuite/ " , true );
}
return $result ;
2007-03-09 23:15:03 +00:00
}
2007-06-03 23:56:04 +00:00
/**
2007-10-22 05:52:20 +00:00
* Makes absolute file path easier to read
2007-06-03 23:56:04 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $file Absolute file path
2007-06-03 23:56:04 +00:00
* @ return sting short path
2007-10-22 05:52:20 +00:00
* @ access public
2007-06-03 23:56:04 +00:00
*/
function shortPath ( $file ) {
$shortPath = str_replace ( ROOT , null , $file );
$shortPath = str_replace ( '..' . DS , '' , $shortPath );
2007-10-22 05:52:20 +00:00
return r ( DS . DS , DS , $shortPath );
2007-06-03 23:56:04 +00:00
}
2007-06-21 14:38:46 +00:00
/**
2007-10-22 05:52:20 +00:00
* Checks for Configure :: read ( 'Routing.admin' ) and forces user to input it if not enabled
2007-06-21 14:38:46 +00:00
*
2007-10-22 05:52:20 +00:00
* @ return string Admin route to use
* @ access public
2007-06-21 14:38:46 +00:00
*/
function getAdmin () {
2007-08-03 00:15:52 +00:00
$admin = '' ;
$cakeAdmin = null ;
2007-08-25 15:29:44 +00:00
$adminRoute = Configure :: read ( 'Routing.admin' );
if ( ! empty ( $adminRoute )) {
$cakeAdmin = $adminRoute . '_' ;
2007-06-21 14:38:46 +00:00
} else {
2007-08-25 15:29:44 +00:00
$this -> out ( 'You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.' );
2007-06-21 14:38:46 +00:00
$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.' );
2007-08-25 15:29:44 +00:00
$this -> out ( 'You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.' );
2007-06-21 14:38:46 +00:00
exit ();
} else {
2007-08-03 00:15:52 +00:00
$cakeAdmin = $admin . '_' ;
2007-06-21 14:38:46 +00:00
}
}
2007-08-03 00:15:52 +00:00
return $cakeAdmin ;
2007-06-21 14:38:46 +00:00
}
2007-03-09 23:15:03 +00:00
/**
2007-10-22 05:52:20 +00:00
* Creates the proper controller path for the specified controller class name
2007-03-09 23:15:03 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $name Controller class name
* @ return string Path to controller
* @ access protected
2007-03-09 23:15:03 +00:00
*/
2007-05-14 12:23:25 +00:00
function _controllerPath ( $name ) {
return low ( Inflector :: underscore ( $name ));
}
/**
2007-10-22 05:52:20 +00:00
* Creates the proper controller plural name for the specified controller class name
2007-05-14 12:23:25 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $name Controller class name
* @ return string Controller plural name
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _controllerName ( $name ) {
return Inflector :: pluralize ( Inflector :: camelize ( $name ));
}
/**
2007-10-22 05:52:20 +00:00
* Creates the proper controller camelized name ( singularized ) for the specified name
2007-05-14 12:23:25 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $name Name
* @ return string Camelized and singularized controller name
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _modelName ( $name ) {
return Inflector :: camelize ( Inflector :: singularize ( $name ));
}
/**
2007-10-22 05:52:20 +00:00
* Creates the proper singular model key for associations
2007-05-14 12:23:25 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $name Controller class name
* @ return string Singular model key
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _modelKey ( $name ) {
return Inflector :: underscore ( Inflector :: singularize ( $name )) . '_id' ;
2007-03-09 23:15:03 +00:00
}
2007-05-14 12:23:25 +00:00
/**
2007-10-22 05:52:20 +00:00
* Creates the proper model name from a foreign key
2007-05-14 12:23:25 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $key Foreign key
* @ return string Model name
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _modelNameFromKey ( $key ) {
$name = str_replace ( '_id' , '' , $key );
return $this -> _modelName ( $name );
}
/**
* creates the singular name for use in views .
*
* @ param string $name
* @ return string $name
2007-10-22 05:52:20 +00:00
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _singularName ( $name ) {
return Inflector :: variable ( Inflector :: singularize ( $name ));
}
/**
2007-10-22 05:52:20 +00:00
* Creates the plural name for views
2007-05-14 12:23:25 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $name Name to use
* @ return string Plural name for views
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _pluralName ( $name ) {
return Inflector :: variable ( Inflector :: pluralize ( $name ));
}
/**
2007-10-22 05:52:20 +00:00
* Creates the singular human name used in views
2007-05-14 12:23:25 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $name Controller name
* @ return string Singular human name
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _singularHumanName ( $name ) {
return Inflector :: humanize ( Inflector :: underscore ( Inflector :: singularize ( $name )));
}
/**
2007-10-22 05:52:20 +00:00
* Creates the plural human name used in views
2007-05-14 12:23:25 +00:00
*
2007-10-22 05:52:20 +00:00
* @ param string $name Controller name
* @ return string Plural human name
* @ access protected
2007-05-14 12:23:25 +00:00
*/
function _pluralHumanName ( $name ) {
return Inflector :: humanize ( Inflector :: underscore ( Inflector :: pluralize ( $name )));
2007-05-15 01:16:10 +00:00
}
2007-03-09 23:15:03 +00:00
}
2007-10-28 04:18:18 +00:00
?>