2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2008-05-30 11:40:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5012
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-25 21:05:00 +00:00
|
|
|
App::uses('AppShell', 'Console/Command');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2011-07-26 01:46:52 +00:00
|
|
|
* Provides a very basic 'interactive' console for CakePHP apps.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Console.Command
|
2013-08-02 21:34:32 +00:00
|
|
|
* @deprecated Deprecated since version 2.4, will be removed in 3.0
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-11-25 21:05:00 +00:00
|
|
|
class ConsoleShell extends AppShell {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Available binding types
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $associations = array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Chars that describe invalid commands
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $badCommandChars = array('$', ';');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Available models
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $models = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
/**
|
|
|
|
* _finished
|
|
|
|
*
|
|
|
|
* This shell is perpetual, setting this property to true exits the process
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
protected $_finished = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _methodPatterns
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $_methodPatterns = array(
|
|
|
|
'help' => '/^(help|\?)/',
|
|
|
|
'_exit' => '/^(quit|exit)/',
|
|
|
|
'_models' => '/^models/i',
|
|
|
|
'_bind' => '/^(\w+) bind (\w+) (\w+)/',
|
|
|
|
'_unbind' => '/^(\w+) unbind (\w+) (\w+)/',
|
|
|
|
'_find' => '/.+->find/',
|
|
|
|
'_save' => '/.+->save/',
|
|
|
|
'_columns' => '/^(\w+) columns/',
|
|
|
|
'_routesReload' => '/^routes\s+reload/i',
|
|
|
|
'_routesShow' => '/^routes\s+show/i',
|
|
|
|
'_routeToString' => '/^route\s+(\(.*\))$/i',
|
|
|
|
'_routeToArray' => '/^route\s+(.*)$/i',
|
|
|
|
);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2012-02-26 15:21:04 +00:00
|
|
|
* Override startup of the Shell
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-29 02:03:44 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-02-26 15:21:04 +00:00
|
|
|
public function startup() {
|
2010-12-08 01:12:50 +00:00
|
|
|
App::uses('Dispatcher', 'Routing');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Dispatcher = new Dispatcher();
|
2011-05-23 02:20:56 +00:00
|
|
|
$this->models = App::objects('Model');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
foreach ($this->models as $model) {
|
2011-05-23 02:20:56 +00:00
|
|
|
$class = $model;
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses($class, 'Model');
|
2010-11-13 04:05:44 +00:00
|
|
|
$this->{$class} = new $class();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-04-25 19:17:59 +00:00
|
|
|
$this->out(__d('cake_console', 'Model classes:'));
|
|
|
|
$this->hr();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
foreach ($this->models as $model) {
|
|
|
|
$this->out(" - {$model}");
|
|
|
|
}
|
2012-08-04 17:44:35 +00:00
|
|
|
|
|
|
|
if (!$this->_loadRoutes()) {
|
|
|
|
$message = __d(
|
|
|
|
'cake_console',
|
|
|
|
'There was an error loading the routes config. Please check that the file exists and contains no errors.'
|
|
|
|
);
|
|
|
|
$this->err($message);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
/**
|
2013-12-05 23:38:32 +00:00
|
|
|
* Gets the option parser instance and configures it.
|
2013-08-01 08:39:01 +00:00
|
|
|
*
|
2013-12-05 23:38:32 +00:00
|
|
|
* @return ConsoleOptionParser
|
2013-08-01 08:39:01 +00:00
|
|
|
*/
|
2012-08-04 17:57:14 +00:00
|
|
|
public function getOptionParser() {
|
2013-12-05 23:38:32 +00:00
|
|
|
$parser = parent::getOptionParser();
|
|
|
|
|
|
|
|
$parser->description(array(
|
2012-08-04 17:57:14 +00:00
|
|
|
'The interactive console is a tool for testing parts of your',
|
|
|
|
'app before you write code.',
|
|
|
|
'',
|
|
|
|
'See below for a list of supported commands.'
|
2013-12-05 23:38:32 +00:00
|
|
|
))->epilog(array(
|
2012-08-04 17:57:14 +00:00
|
|
|
'<info>Model testing</info>',
|
|
|
|
'',
|
|
|
|
'To test model results, use the name of your model without a leading $',
|
|
|
|
'e.g. Foo->find("all")',
|
|
|
|
"",
|
|
|
|
'To dynamically set associations, you can do the following:',
|
|
|
|
'',
|
|
|
|
"\tModelA bind <association> ModelB",
|
|
|
|
'',
|
|
|
|
"where the supported associations are hasOne, hasMany, belongsTo, hasAndBelongsToMany",
|
|
|
|
"",
|
|
|
|
'To dynamically remove associations, you can do the following:',
|
|
|
|
'',
|
|
|
|
"\t ModelA unbind <association> ModelB",
|
|
|
|
'',
|
|
|
|
"where the supported associations are the same as above",
|
|
|
|
"",
|
|
|
|
"To save a new field in a model, you can do the following:",
|
|
|
|
'',
|
|
|
|
"\tModelA->save(array('foo' => 'bar', 'baz' => 0))",
|
|
|
|
'',
|
|
|
|
"where you are passing a hash of data to be saved in the format",
|
|
|
|
"of field => value pairs",
|
|
|
|
"",
|
|
|
|
"To get column information for a model, use the following:",
|
|
|
|
'',
|
|
|
|
"\tModelA columns",
|
|
|
|
'',
|
|
|
|
"which returns a list of columns and their type",
|
|
|
|
"",
|
|
|
|
'<info>Route testing</info>',
|
|
|
|
"",
|
|
|
|
'To test URLs against your app\'s route configuration, type:',
|
|
|
|
"",
|
|
|
|
"\tRoute <url>",
|
|
|
|
"",
|
|
|
|
"where url is the path to your your action plus any query parameters,",
|
2012-12-22 22:48:15 +00:00
|
|
|
"minus the application's base path. For example:",
|
2012-08-04 17:57:14 +00:00
|
|
|
"",
|
|
|
|
"\tRoute /posts/view/1",
|
|
|
|
"",
|
|
|
|
"will return something like the following:",
|
|
|
|
"",
|
|
|
|
"\tarray(",
|
|
|
|
"\t [...]",
|
|
|
|
"\t 'controller' => 'posts',",
|
|
|
|
"\t 'action' => 'view',",
|
|
|
|
"\t [...]",
|
|
|
|
"\t)",
|
|
|
|
"",
|
|
|
|
'Alternatively, you can use simple array syntax to test reverse',
|
|
|
|
'To reload your routes config (Config/routes.php), do the following:',
|
|
|
|
"",
|
|
|
|
"\tRoutes reload",
|
|
|
|
"",
|
|
|
|
'To show all connected routes, do the following:',
|
|
|
|
'',
|
|
|
|
"\tRoutes show",
|
2013-12-05 23:38:32 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
return $parser;
|
2012-08-04 17:57:14 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Prints the help message
|
|
|
|
*
|
2011-07-29 02:03:44 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function help() {
|
2012-08-04 17:57:14 +00:00
|
|
|
$optionParser = $this->getOptionParser();
|
|
|
|
$this->out($optionParser->epilog());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Override main() to handle action
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param string $command The command to run.
|
2011-07-29 02:03:44 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function main($command = null) {
|
2013-08-01 08:39:01 +00:00
|
|
|
$this->_finished = false;
|
|
|
|
while (!$this->_finished) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (empty($command)) {
|
|
|
|
$command = trim($this->in(''));
|
|
|
|
}
|
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
$method = $this->_method($command);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
if ($method) {
|
|
|
|
$this->$method($command);
|
|
|
|
} else {
|
|
|
|
$this->out(__d('cake_console', "Invalid command"));
|
|
|
|
$this->out();
|
|
|
|
}
|
|
|
|
$command = '';
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
/**
|
|
|
|
* Determine the method to process the current command
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param string $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return string or false
|
|
|
|
*/
|
|
|
|
protected function _method($command) {
|
|
|
|
foreach ($this->_methodPatterns as $method => $pattern) {
|
|
|
|
if (preg_match($pattern, $command)) {
|
|
|
|
return $method;
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
/**
|
|
|
|
* Set the finiished property so that the loop in main method ends
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _exit() {
|
|
|
|
$this->_finished = true;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
/**
|
|
|
|
* List all models
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _models() {
|
|
|
|
$this->out(__d('cake_console', 'Model classes:'));
|
|
|
|
$this->hr();
|
|
|
|
foreach ($this->models as $model) {
|
|
|
|
$this->out(" - {$model}");
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
/**
|
|
|
|
* Bind an association
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param mixed $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _bind($command) {
|
|
|
|
preg_match($this->_methodPatterns[__FUNCTION__], $command, $tmp);
|
|
|
|
|
|
|
|
foreach ($tmp as $data) {
|
|
|
|
$data = strip_tags($data);
|
|
|
|
$data = str_replace($this->badCommandChars, "", $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$modelA = $tmp[1];
|
|
|
|
$association = $tmp[2];
|
|
|
|
$modelB = $tmp[3];
|
|
|
|
|
|
|
|
if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations)) {
|
|
|
|
$this->{$modelA}->bindModel(array($association => array($modelB => array('className' => $modelB))), false);
|
|
|
|
$this->out(__d('cake_console', "Created %s association between %s and %s",
|
|
|
|
$association, $modelA, $modelB));
|
|
|
|
} else {
|
|
|
|
$this->out(__d('cake_console', "Please verify you are using valid models and association types"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind an association
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param mixed $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _unbind($command) {
|
|
|
|
preg_match($this->_methodPatterns[__FUNCTION__], $command, $tmp);
|
|
|
|
|
|
|
|
foreach ($tmp as $data) {
|
|
|
|
$data = strip_tags($data);
|
|
|
|
$data = str_replace($this->badCommandChars, "", $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$modelA = $tmp[1];
|
|
|
|
$association = $tmp[2];
|
|
|
|
$modelB = $tmp[3];
|
|
|
|
|
|
|
|
// Verify that there is actually an association to unbind
|
|
|
|
$currentAssociations = $this->{$modelA}->getAssociated();
|
|
|
|
$validCurrentAssociation = false;
|
|
|
|
|
|
|
|
foreach ($currentAssociations as $model => $currentAssociation) {
|
2014-04-29 12:19:33 +00:00
|
|
|
if ($model === $modelB && $association === $currentAssociation) {
|
2013-08-01 08:39:01 +00:00
|
|
|
$validCurrentAssociation = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations) && $validCurrentAssociation) {
|
|
|
|
$this->{$modelA}->unbindModel(array($association => array($modelB)));
|
|
|
|
$this->out(__d('cake_console', "Removed %s association between %s and %s",
|
|
|
|
$association, $modelA, $modelB));
|
|
|
|
} else {
|
|
|
|
$this->out(__d('cake_console', "Please verify you are using valid models, valid current association, and valid association types"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform a find
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param mixed $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _find($command) {
|
|
|
|
$command = strip_tags($command);
|
|
|
|
$command = str_replace($this->badCommandChars, "", $command);
|
|
|
|
|
|
|
|
// Do we have a valid model?
|
2014-02-11 21:38:24 +00:00
|
|
|
list($modelToCheck) = explode('->', $command);
|
2013-08-01 08:39:01 +00:00
|
|
|
|
|
|
|
if ($this->_isValidModel($modelToCheck)) {
|
|
|
|
$findCommand = "\$data = \$this->$command;";
|
|
|
|
//@codingStandardsIgnoreStart
|
|
|
|
@eval($findCommand);
|
|
|
|
//@codingStandardsIgnoreEnd
|
|
|
|
|
|
|
|
if (is_array($data)) {
|
|
|
|
foreach ($data as $idx => $results) {
|
|
|
|
if (is_numeric($idx)) { // findAll() output
|
|
|
|
foreach ($results as $modelName => $result) {
|
|
|
|
$this->out("$modelName");
|
|
|
|
|
|
|
|
foreach ($result as $field => $value) {
|
|
|
|
if (is_array($value)) {
|
|
|
|
foreach ($value as $field2 => $value2) {
|
|
|
|
$this->out("\t$field2: $value2");
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2013-08-01 08:39:01 +00:00
|
|
|
|
|
|
|
$this->out();
|
|
|
|
} else {
|
|
|
|
$this->out("\t$field: $value");
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 08:39:01 +00:00
|
|
|
} else { // find() output
|
|
|
|
$this->out($idx);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
foreach ($results as $field => $value) {
|
|
|
|
if (is_array($value)) {
|
|
|
|
foreach ($value as $field2 => $value2) {
|
|
|
|
$this->out("\t$field2: $value2");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->out();
|
|
|
|
} else {
|
|
|
|
$this->out("\t$field: $value");
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 08:39:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->out();
|
|
|
|
$this->out(__d('cake_console', "No result set found"));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2013-08-01 08:39:01 +00:00
|
|
|
} else {
|
|
|
|
$this->out(__d('cake_console', "%s is not a valid model", $modelToCheck));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a record
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param mixed $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _save($command) {
|
|
|
|
// Validate the model we're trying to save here
|
|
|
|
$command = strip_tags($command);
|
|
|
|
$command = str_replace($this->badCommandChars, "", $command);
|
2014-02-11 21:38:24 +00:00
|
|
|
list($modelToSave) = explode("->", $command);
|
2013-08-01 08:39:01 +00:00
|
|
|
|
|
|
|
if ($this->_isValidModel($modelToSave)) {
|
|
|
|
// Extract the array of data we are trying to build
|
|
|
|
list(, $data) = explode("->save", $command);
|
|
|
|
$data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data);
|
|
|
|
$saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));";
|
|
|
|
//@codingStandardsIgnoreStart
|
|
|
|
@eval($saveCommand);
|
|
|
|
//@codingStandardsIgnoreEnd
|
|
|
|
$this->out(__d('cake_console', 'Saved record for %s', $modelToSave));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-08-01 08:39:01 +00:00
|
|
|
/**
|
|
|
|
* Show the columns for a model
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param mixed $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _columns($command) {
|
|
|
|
preg_match($this->_methodPatterns[__FUNCTION__], $command, $tmp);
|
|
|
|
|
|
|
|
$modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));
|
|
|
|
|
|
|
|
if ($this->_isValidModel($modelToCheck)) {
|
|
|
|
// Get the column info for this model
|
|
|
|
$fieldsCommand = "\$data = \$this->{$modelToCheck}->getColumnTypes();";
|
|
|
|
//@codingStandardsIgnoreStart
|
|
|
|
@eval($fieldsCommand);
|
|
|
|
//@codingStandardsIgnoreEnd
|
|
|
|
|
|
|
|
if (is_array($data)) {
|
|
|
|
foreach ($data as $field => $type) {
|
|
|
|
$this->out("\t{$field}: {$type}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->out(__d('cake_console', "Please verify that you selected a valid model"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reload route definitions
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _routesReload() {
|
|
|
|
if (!$this->_loadRoutes()) {
|
2013-08-20 22:03:39 +00:00
|
|
|
return $this->err(__d('cake_console', "There was an error loading the routes config. Please check that the file exists and is free of parse errors."));
|
2013-08-01 08:39:01 +00:00
|
|
|
}
|
|
|
|
$this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count(Router::$routes)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show all routes
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _routesShow() {
|
|
|
|
$this->out(print_r(Hash::combine(Router::$routes, '{n}.template', '{n}.defaults'), true));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-10-08 03:17:58 +00:00
|
|
|
* Parse an array URL and show the equivalent URL as a string
|
2013-08-01 08:39:01 +00:00
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param mixed $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _routeToString($command) {
|
|
|
|
preg_match($this->_methodPatterns[__FUNCTION__], $command, $tmp);
|
|
|
|
|
|
|
|
//@codingStandardsIgnoreStart
|
|
|
|
if ($url = eval('return array' . $tmp[1] . ';')) {
|
|
|
|
//@codingStandardsIgnoreEnd
|
|
|
|
$this->out(Router::url($url));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-10-08 03:17:58 +00:00
|
|
|
* Parse a string URL and show as an array
|
2013-08-01 08:39:01 +00:00
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param mixed $command The command to run.
|
2013-08-01 08:39:01 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _routeToArray($command) {
|
|
|
|
preg_match($this->_methodPatterns[__FUNCTION__], $command, $tmp);
|
|
|
|
|
|
|
|
$this->out(var_export(Router::parse($tmp[1]), true));
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Tells if the specified model is included in the list of available models
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param string $modelToCheck The model to check.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return boolean true if is an available model, false otherwise
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _isValidModel($modelToCheck) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return in_array($modelToCheck, $this->models);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-19 21:33:59 +00:00
|
|
|
/**
|
2011-06-25 14:08:41 +00:00
|
|
|
* Reloads the routes configuration from app/Config/routes.php, and compiles
|
2008-09-19 21:33:59 +00:00
|
|
|
* all routes found
|
|
|
|
*
|
|
|
|
* @return boolean True if config reload was a success, otherwise false
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _loadRoutes() {
|
2010-12-08 01:12:50 +00:00
|
|
|
Router::reload();
|
|
|
|
extract(Router::getNamedExpressions());
|
2008-09-19 21:33:59 +00:00
|
|
|
|
2012-11-14 09:00:15 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-03-03 23:55:07 +00:00
|
|
|
if (!@include APP . 'Config' . DS . 'routes.php') {
|
2012-11-14 09:00:15 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2008-09-19 21:33:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-23 02:20:56 +00:00
|
|
|
CakePlugin::routes();
|
|
|
|
|
2010-12-08 01:12:50 +00:00
|
|
|
Router::parse('/');
|
2008-09-19 21:33:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-03 23:55:07 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|