mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-02 17:42:41 +00:00
adding plugin task, closes #965
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6179 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
c9f59b8713
commit
ef3b73d690
8 changed files with 154 additions and 82 deletions
|
@ -41,7 +41,24 @@ class BakeShell extends Shell {
|
|||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View');
|
||||
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin');
|
||||
/**
|
||||
* Override loadTasks() to handle paths
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function loadTasks() {
|
||||
parent::loadTasks();
|
||||
$task = Inflector::classify($this->command);
|
||||
if (isset($this->{$task})) {
|
||||
$path = Inflector::underscore(Inflector::pluralize($this->command));
|
||||
$this->{$task}->path = $this->params['working'] . DS . $path . 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));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Override main() to handle action
|
||||
*
|
||||
|
@ -54,7 +71,7 @@ class BakeShell extends Shell {
|
|||
}
|
||||
|
||||
if (!config('database')) {
|
||||
$this->out("Your database configuration was not found. Take a moment to create one.\n");
|
||||
$this->out(__("Your database configuration was not found. Take a moment to create one.", true));
|
||||
$this->args = null;
|
||||
return $this->DbConfig->execute();
|
||||
}
|
||||
|
@ -67,7 +84,7 @@ class BakeShell extends Shell {
|
|||
$this->out('[P]roject');
|
||||
$this->out('[Q]uit');
|
||||
|
||||
$classToBake = strtoupper($this->in('What would you like to Bake?', array('D', 'M', 'V', 'C', 'P', 'Q')));
|
||||
$classToBake = strtoupper($this->in(__('What would you like to Bake?', true), array('D', 'M', 'V', 'C', 'P', 'Q')));
|
||||
switch($classToBake) {
|
||||
case 'D':
|
||||
$this->DbConfig->execute();
|
||||
|
|
|
@ -170,8 +170,8 @@ class Shell extends Object {
|
|||
* @access protected
|
||||
*/
|
||||
function _welcome() {
|
||||
$this->out('App : '. APP_DIR);
|
||||
$this->out('Path: '. ROOT . DS . APP_DIR);
|
||||
$this->out('App : '. $this->params['app']);
|
||||
$this->out('Path: '. $this->params['working']);
|
||||
$this->hr();
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -40,12 +40,20 @@ class ControllerTask extends Shell {
|
|||
* @access public
|
||||
*/
|
||||
var $tasks = array('Project');
|
||||
/**
|
||||
* path to CONTROLLERS directory
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $path = CONTROLLERS;
|
||||
/**
|
||||
* Override initialize
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function initialize() {}
|
||||
function initialize() {
|
||||
}
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
|
@ -91,7 +99,7 @@ class ControllerTask extends Shell {
|
|||
if (!$controllerName) {
|
||||
$this->interactive = false;
|
||||
$this->hr();
|
||||
$this->out('Controller Bake:');
|
||||
$this->out(sprintf("Bake Controller\nPath: %s", $this->path));
|
||||
$this->hr();
|
||||
$actions = '';
|
||||
$uses = array();
|
||||
|
@ -107,10 +115,10 @@ class ControllerTask extends Shell {
|
|||
$this->out("Baking {$controllerName}Controller");
|
||||
$this->hr();
|
||||
|
||||
$controllerPath = low(Inflector::underscore($controllerName));
|
||||
$controllerFile = low(Inflector::underscore($controllerName));
|
||||
|
||||
$question[] = __("Would you like to build your controller interactively?", true);
|
||||
if (file_exists(CONTROLLERS . $controllerPath .'_controller.php')) {
|
||||
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');
|
||||
|
@ -435,7 +443,7 @@ class ControllerTask extends Shell {
|
|||
}
|
||||
$out .= "}\n";
|
||||
$out .= "?>";
|
||||
$filename = CONTROLLERS . $this->_controllerPath($controllerName) . '_controller.php';
|
||||
$filename = $this->path . $this->_controllerPath($controllerName) . '_controller.php';
|
||||
return $this->createFile($filename, $out);
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,13 @@
|
|||
* @subpackage cake.cake.console.libs.tasks
|
||||
*/
|
||||
class ModelTask extends Shell {
|
||||
/**
|
||||
* path to MODELS directory
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $path = MODELS;
|
||||
/**
|
||||
* Execution method always used for tasks
|
||||
*
|
||||
|
@ -59,7 +66,7 @@ class ModelTask extends Shell {
|
|||
*/
|
||||
function __interactive() {
|
||||
$this->hr();
|
||||
$this->out('Model Bake:');
|
||||
$this->out(sprintf("Bake Model\nPath: %s", $this->path));
|
||||
$this->hr();
|
||||
$this->interactive = true;
|
||||
|
||||
|
@ -491,7 +498,7 @@ class ModelTask extends Shell {
|
|||
}
|
||||
$out .= "}\n";
|
||||
$out .= "?>";
|
||||
$filename = MODELS . Inflector::underscore($name) . '.php';
|
||||
$filename = $this->path . Inflector::underscore($name) . '.php';
|
||||
return $this->createFile($filename, $out);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class ProjectTask extends Shell {
|
|||
}
|
||||
/**
|
||||
* Checks that given project path does not already exist, and
|
||||
* finds the app directory in it. Then it calls __buildDirLayout() with that information.
|
||||
* finds the app directory in it. Then it calls bake() with that information.
|
||||
*
|
||||
* @param string $project Project path
|
||||
* @access public
|
||||
|
@ -111,10 +111,35 @@ class ProjectTask extends Shell {
|
|||
}
|
||||
|
||||
if (!is_dir($this->params['root'])) {
|
||||
$this->err('The directory path you supplied was not found. Please try again.');
|
||||
$this->err(__('The directory path you supplied was not found. Please try again.', true));
|
||||
}
|
||||
|
||||
$this->__buildDirLayout($project);
|
||||
if($this->bake($project)) {
|
||||
$path = Folder::slashTerm($project);
|
||||
if ($this->createHome($path)) {
|
||||
$this->out(__('Welcome page created', true));
|
||||
} else {
|
||||
$this->out(__('The Welcome page was NOT created', true));
|
||||
}
|
||||
|
||||
if ($this->securitySalt($path) === true ) {
|
||||
$this->out(__('Random hash key created for \'Security.salt\'', true));
|
||||
} else {
|
||||
$this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
|
||||
}
|
||||
|
||||
$corePath = $this->corePath($path);
|
||||
if ($corePath === true ) {
|
||||
$this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s'), true, CAKE_CORE_INCLUDE_PATH));
|
||||
} elseif ($corePath === false) {
|
||||
$this->err(sprintf(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', true), $path . 'webroot' .DS .'index.php'));
|
||||
}
|
||||
$Folder = new Folder($path);
|
||||
if (!$Folder->chmod($path . 'tmp', 0777)) {
|
||||
$this->err(sprintf(__('Could not set permissions on %s', true), $path . DS .'tmp'));
|
||||
$this->out(sprintf(__('chmod -R 0777 %s', true), $path . DS .'tmp'));
|
||||
}
|
||||
}
|
||||
exit();
|
||||
}
|
||||
/**
|
||||
|
@ -124,17 +149,21 @@ class ProjectTask extends Shell {
|
|||
* A default home page will be added, and the tmp file storage will be chmod'ed to 0777.
|
||||
*
|
||||
* @param string $path Project path
|
||||
* @param string $skel Path to copy from
|
||||
* @param string $skip array of directories to skip when copying
|
||||
* @access private
|
||||
*/
|
||||
function __buildDirLayout($path) {
|
||||
$skel = $this->params['skel'];
|
||||
while ($skel == '') {
|
||||
$skel = $this->in("What is the path to the app directory you wish to copy?\nExample: ".APP, null, ROOT.DS.'myapp'.DS);
|
||||
function bake($path, $skel = null, $skip = array('empty')) {
|
||||
if(!$skel) {
|
||||
$skel = $this->params['skel'];
|
||||
}
|
||||
while (!$skel) {
|
||||
$skel = $this->in(sprintf(__("What is the path to the directory layout you wish to copy?\nExample: %s"), APP, null, ROOT . DS . 'myapp' . DS));
|
||||
if ($skel == '') {
|
||||
$this->out('The directory path you supplied was empty. Please try again.');
|
||||
$this->out(__('The directory path you supplied was empty. Please try again.', true));
|
||||
} else {
|
||||
while (is_dir($skel) === false) {
|
||||
$skel = $this->in('Directory path does not exist please choose another:');
|
||||
$skel = $this->in(__('Directory path does not exist please choose another:', true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,57 +174,29 @@ class ProjectTask extends Shell {
|
|||
$this->out("Skel Directory: $skel");
|
||||
$this->out("Will be copied to: {$path}");
|
||||
$this->hr();
|
||||
|
||||
$looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
|
||||
|
||||
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
||||
$verboseOuptut = $this->in('Do you want verbose output?', array('y', 'n'), 'n');
|
||||
$verbose = false;
|
||||
|
||||
if (low($verboseOuptut) == 'y' || low($verboseOuptut) == 'yes') {
|
||||
$verbose = true;
|
||||
}
|
||||
$verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');
|
||||
|
||||
$Folder = new Folder($skel);
|
||||
if ($Folder->copy($path)) {
|
||||
$path = $Folder->slashTerm($path);
|
||||
if ($Folder->copy(array('to' => $path, 'skip' => $skip))) {
|
||||
$this->hr();
|
||||
$this->out(sprintf(__("Created: %s in %s", true), $app, $path));
|
||||
$this->hr();
|
||||
|
||||
if ($this->createHome($path)) {
|
||||
$this->out('Welcome page created');
|
||||
} else {
|
||||
$this->out('The Welcome page was NOT created');
|
||||
}
|
||||
|
||||
if ($this->securitySalt($path) === true ) {
|
||||
$this->out('Random hash key created for \'Security.salt\'');
|
||||
} else {
|
||||
$this->err('Unable to generate random hash for \'Security.salt\', please change this yourself in ' . CONFIGS . 'core.php');
|
||||
}
|
||||
|
||||
$corePath = $this->corePath($path);
|
||||
if ($corePath === true ) {
|
||||
$this->out('CAKE_CORE_INCLUDE_PATH set to ' . CAKE_CORE_INCLUDE_PATH);
|
||||
} elseif ($corePath === false) {
|
||||
$this->err('Unable to to set CAKE_CORE_INCLUDE_PATH, please change this yourself in ' . $path . 'webroot' .DS .'index.php');
|
||||
}
|
||||
|
||||
if (!$Folder->chmod($path . 'tmp', 0777)) {
|
||||
$this->err('Could not set permissions on '. $path . DS .'tmp');
|
||||
$this->out('You must manually check that these directories can be wrote to by the server');
|
||||
}
|
||||
} else {
|
||||
$this->err(" '".$app."' could not be created properly");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($verbose) {
|
||||
if (low($verbose) == 'y' || low($verbose) == 'yes') {
|
||||
foreach ($Folder->messages() as $message) {
|
||||
$this->out($message);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return true;
|
||||
} elseif (low($looksGood) == 'q' || low($looksGood) == 'quit') {
|
||||
$this->out('Bake Aborted.');
|
||||
} else {
|
||||
|
@ -261,6 +262,19 @@ class ProjectTask extends Shell {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$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);
|
||||
if ($File->write($result)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -285,5 +299,21 @@ class ProjectTask extends Shell {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Help
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->hr();
|
||||
$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("");
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -41,6 +41,13 @@ class ViewTask extends Shell {
|
|||
* @access public
|
||||
*/
|
||||
var $tasks = array('Project', 'Controller');
|
||||
/**
|
||||
* path to VIEWS directory
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $path = VIEWS;
|
||||
/**
|
||||
* Name of the controller being used
|
||||
*
|
||||
|
@ -140,7 +147,7 @@ class ViewTask extends Shell {
|
|||
*/
|
||||
function __interactive() {
|
||||
$this->hr();
|
||||
$this->out('View Bake:');
|
||||
$this->out(sprintf("Bake View\nPath: %s", $this->path));
|
||||
$this->hr();
|
||||
$wannaDoAdmin = 'n';
|
||||
$wannaDoScaffold = 'y';
|
||||
|
@ -221,14 +228,13 @@ class ViewTask extends Shell {
|
|||
*/
|
||||
function __loadController() {
|
||||
if (!$this->controllerName) {
|
||||
$this->err('could not find the controller');
|
||||
$this->err(__('Controller not found', true));
|
||||
}
|
||||
|
||||
$controllerClassName = $this->controllerName . 'Controller';
|
||||
if (!class_exists($this->controllerName . 'Controller') && !App::import('Controller', $this->controllerName)) {
|
||||
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
||||
$shortPath = $this->shortPath($file);
|
||||
$this->err("The file '{$shortPath}' could not be found.\nIn order to bake a view, you'll need to first create the controller.");
|
||||
$file = $this->controllerPath . '_controller.php';
|
||||
$this->err(sprintf(__("The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", true), $file));
|
||||
exit();
|
||||
}
|
||||
$controllerObj = & new $controllerClassName();
|
||||
|
@ -259,8 +265,8 @@ class ViewTask extends Shell {
|
|||
if ($content === true) {
|
||||
$content = $this->getContent();
|
||||
}
|
||||
$filename = VIEWS . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp';
|
||||
$Folder =& new Folder(VIEWS . $this->controllerPath, true);
|
||||
$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());
|
||||
|
@ -313,7 +319,7 @@ class ViewTask extends Shell {
|
|||
$content = ob_get_clean();
|
||||
return $content;
|
||||
}
|
||||
$this->err('Template for '. $template .' could not be found');
|
||||
$this->err(sprintf(__('Template for %s could not be found', true), $template));
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -261,20 +261,6 @@ class Folder extends Object{
|
|||
$match = preg_match('/^\\//', $path) || preg_match('/^[A-Z]:\\\\/i', $path);
|
||||
return $match;
|
||||
}
|
||||
/**
|
||||
* Returns true if given $path ends in a slash (i.e. is slash-terminated).
|
||||
*
|
||||
* @param string $path Path to check
|
||||
* @return boolean true if path ends with slash, false otherwise
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function isSlashTerm($path) {
|
||||
if (preg_match('/[\/\\\]$/', $path)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.)
|
||||
*
|
||||
|
@ -284,7 +270,7 @@ class Folder extends Object{
|
|||
* @static
|
||||
*/
|
||||
function normalizePath($path) {
|
||||
if ($this->isWindowsPath($path)) {
|
||||
if (Folder::isWindowsPath($path)) {
|
||||
return '\\';
|
||||
}
|
||||
return '/';
|
||||
|
@ -298,7 +284,7 @@ class Folder extends Object{
|
|||
* @static
|
||||
*/
|
||||
function correctSlashFor($path) {
|
||||
if ($this->isWindowsPath($path)) {
|
||||
if (Folder::isWindowsPath($path)) {
|
||||
return '\\';
|
||||
}
|
||||
return '/';
|
||||
|
@ -312,10 +298,10 @@ class Folder extends Object{
|
|||
* @static
|
||||
*/
|
||||
function slashTerm($path) {
|
||||
if ($this->isSlashTerm($path)) {
|
||||
if (Folder::isSlashTerm($path)) {
|
||||
return $path;
|
||||
}
|
||||
return $path . $this->correctSlashFor($path);
|
||||
return $path . Folder::correctSlashFor($path);
|
||||
}
|
||||
/**
|
||||
* Returns $path with $element added, with correct slash in-between.
|
||||
|
@ -363,7 +349,7 @@ class Folder extends Object{
|
|||
/**
|
||||
* Change the mode on a directory structure recursively.
|
||||
*
|
||||
* @param string $pathname The directory structure to create
|
||||
* @param string $path The path to chmod
|
||||
* @param integer $mode octal value 0755
|
||||
* @param boolean $recursive chmod recursively
|
||||
* @param array $exceptions array of files, directories to skip
|
||||
|
@ -775,6 +761,20 @@ class Folder extends Object{
|
|||
}
|
||||
return $newpath;
|
||||
}
|
||||
/**
|
||||
* Returns true if given $path ends in a slash (i.e. is slash-terminated).
|
||||
*
|
||||
* @param string $path Path to check
|
||||
* @return boolean true if path ends with slash, false otherwise
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function isSlashTerm($path) {
|
||||
if (preg_match('/[\/\\\]$/', $path)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @deprecated
|
||||
|
|
|
@ -190,5 +190,9 @@ class FolderTest extends UnitTestCase {
|
|||
$this->assertTrue($Folder->isSlashTerm('/usr/local/'));
|
||||
$this->assertFalse($Folder->isSlashTerm('cake'));
|
||||
}
|
||||
function testStatic() {
|
||||
$result = Folder::slashTerm('/path/to/file');
|
||||
$this->assertEqual($result, '/path/to/file/');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue