mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Some docblock formatting changes, and /libs/bake.php - takes time, but domumenting is very educating :)
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@140 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ea0191d321
commit
ec0abbaac0
9 changed files with 381 additions and 296 deletions
|
@ -14,7 +14,6 @@
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Purpose: AppController
|
||||
* This file is application-wide controller file. You can put all
|
||||
* application-wide controller-related methods here.
|
||||
*
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Purpose: AppModel
|
||||
* This file is application-wide model file. You can put all
|
||||
* application-wide model-related methods here.
|
||||
*
|
||||
|
|
245
libs/bake.php
245
libs/bake.php
|
@ -14,9 +14,8 @@
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Purpose: Bake
|
||||
* Creates controller, model, view files, and the required directories on demand.
|
||||
* Used by scripts/add.php
|
||||
* Used by /scripts/add.php.
|
||||
*
|
||||
* @filesource
|
||||
* @author Cake Authors/Developers
|
||||
|
@ -32,62 +31,66 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* Require needed libraries.
|
||||
*/
|
||||
uses('object', 'inflector');
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* Bake class creates files in configured application directories. This is a
|
||||
* base class for /scripts/add.php.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs
|
||||
* @since Cake v 0.2.9
|
||||
*
|
||||
*/
|
||||
class Bake extends Object {
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Standard input stream (php://stdin).
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $stdin = null;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Standard output stream (php://stdout).
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $stdout = null;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Standard error stream (php://stderr).
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $stderr = null;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Counts taken actions.
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $actions = null;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Decides wether to overwrite existing files without asking.
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $dont_ask = false;
|
||||
var $dontAsk = false;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns template for file generator.
|
||||
*
|
||||
* @param unknown_type $type
|
||||
* @return unknown
|
||||
* @param string $type
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function template ($type) {
|
||||
switch ($type) {
|
||||
|
@ -128,10 +131,17 @@ class %sTest extends TestCase {
|
|||
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Baker's constructor method. Initialises bakery, and starts production.
|
||||
*
|
||||
* @param unknown_type $type
|
||||
* @param unknown_type $names
|
||||
* @param string $type
|
||||
* @param array $names
|
||||
* @access public
|
||||
* @uses Bake::stdin Opens stream for reading.
|
||||
* @uses Bake::stdout Opens stream for writing.
|
||||
* @uses Bake::stderr Opens stream for writing.
|
||||
* @uses Bake::newModel() Depending on the case, can create a new model.
|
||||
* @uses Bake::newView() Depending on the case, can create a new view.
|
||||
* @uses Bake::newController() Depending on the case, can create a new controller.
|
||||
*/
|
||||
function __construct ($type, $names) {
|
||||
|
||||
|
@ -177,10 +187,17 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates new view in VIEWS/$controller/ directory.
|
||||
*
|
||||
* @param unknown_type $controller
|
||||
* @param unknown_type $name
|
||||
* @param string $controller
|
||||
* @param string $name
|
||||
* @access private
|
||||
* @uses Inflector::underscore() Underscores directory' name.
|
||||
* @uses Bake::createDir() Creates new directory in views, depending on the controller's name.
|
||||
* @uses VIEWS
|
||||
* @uses Bake::createFile() Creates view file.
|
||||
* @uses Bake::template() Collects view template.
|
||||
* @uses Bake::actions Adds one action for each run.
|
||||
*/
|
||||
function newView ($controller, $name) {
|
||||
$dir = Inflector::underscore($controller);
|
||||
|
@ -192,10 +209,17 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates new controller with defined actions, controller's test and helper
|
||||
* with helper's test.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @param string $name
|
||||
* @param array $actions
|
||||
* @access private
|
||||
* @uses Bake::makeController()
|
||||
* @uses Bake::makeControllerTest()
|
||||
* @uses Bake::makeHelper()
|
||||
* @uses Bake::makeHelperTest()
|
||||
* @uses Bake::actions Adds one action for each run.
|
||||
*/
|
||||
function newController ($name, $actions=array()) {
|
||||
$this->makeController($name, $actions);
|
||||
|
@ -206,11 +230,18 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates new controller file with defined actions.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @param string $name
|
||||
* @param array $actions
|
||||
* @return unknown
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::makeControllerName() CamelCase for controller's name.
|
||||
* @uses Bake::makeHelperName() CamelCase for helper's name.
|
||||
* @uses Bake::template() Controller's template.
|
||||
* @uses Bake::getActions() Actions' templates to be included in the controller.
|
||||
* @uses Bake::createFile() Creates controller's file.
|
||||
* @uses Bake::makeControllerFn() Underscored name for controller's filename.
|
||||
*/
|
||||
function makeController ($name, $actions) {
|
||||
$ctrl = $this->makeControllerName($name);
|
||||
|
@ -220,30 +251,40 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns controller's name in CamelCase.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::camelize CamelCase for controller name.
|
||||
*/
|
||||
function makeControllerName ($name) {
|
||||
return Inflector::camelize($name).'Controller';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns a name for controller's file, underscored.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::underscore() Underscore for controller's file name.
|
||||
*/
|
||||
function makeControllerFn ($name) {
|
||||
return CONTROLLERS.Inflector::underscore($name).'_controller.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates new test for a controller.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses CONTROLLER_TESTS
|
||||
* @uses Inflector::underscore()
|
||||
* @uses Bake::getTestBody()
|
||||
* @uses Bake::makeControllerName()
|
||||
* @uses Bake::createFile()
|
||||
*/
|
||||
function makeControllerTest ($name) {
|
||||
$fn = CONTROLLER_TESTS.Inflector::underscore($name).'_controller_test.php';
|
||||
|
@ -252,10 +293,15 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates new helper.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::template()
|
||||
* @uses Bake::makeHelperName()
|
||||
* @uses Bake::createFile()
|
||||
* @uses Bake::makeHelperFn()
|
||||
*/
|
||||
function makeHelper ($name) {
|
||||
$body = sprintf($this->template('helper'), $this->makeHelperName($name));
|
||||
|
@ -263,30 +309,41 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns CamelCase name for a helper.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::camelize()
|
||||
*/
|
||||
function makeHelperName ($name) {
|
||||
return Inflector::camelize($name).'Helper';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Underscores file name for a helper.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses HELPERS
|
||||
* @uses Inflector::underscore()
|
||||
*/
|
||||
function makeHelperFn ($name) {
|
||||
return HELPERS.Inflector::underscore($name).'_helper.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates new test for a helper.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses HELPER_TESTS
|
||||
* @uses Inflector::underscore()
|
||||
* @uses Bake::getTestBody()
|
||||
* @uses Bake::makeHelperName()
|
||||
* @uses Bake::createFile()
|
||||
*/
|
||||
function makeHelperTest ($name) {
|
||||
$fn = HELPER_TESTS.Inflector::underscore($name).'_helper_test.php';
|
||||
|
@ -295,10 +352,12 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns array of actions' templates.
|
||||
*
|
||||
* @param unknown_type $as
|
||||
* @return unknown
|
||||
* @param array $as
|
||||
* @return array
|
||||
* @access private
|
||||
* @uses Bake::template()
|
||||
*/
|
||||
function getActions ($as) {
|
||||
$out = array();
|
||||
|
@ -308,19 +367,28 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns test template for defined class.
|
||||
*
|
||||
* @param unknown_type $class
|
||||
* @return unknown
|
||||
* @param string $class
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Bake::template()
|
||||
*/
|
||||
function getTestBody ($class) {
|
||||
return sprintf($this->template('test'), $class, $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates new model.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @param string $name
|
||||
* @access private
|
||||
* @uses Bake::createFile()
|
||||
* @uses Bake::getModelFn()
|
||||
* @uses Bake::template()
|
||||
* @uses Bake::getModelName()
|
||||
* @uses Bake::makeModelTest()
|
||||
* @uses Bake::actions
|
||||
*/
|
||||
function newModel ($name) {
|
||||
$this->createFile($this->getModelFn($name), sprintf($this->template('model'), $this->getModelName($name)));
|
||||
|
@ -329,20 +397,29 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns underscored name for model's file.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses MODELS
|
||||
* @uses Inflector::underscore()
|
||||
*/
|
||||
function getModelFn ($name) {
|
||||
return MODELS.Inflector::underscore($name).'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates a test for a given model.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses MODEL_TESTS
|
||||
* @uses Inflector::underscore()
|
||||
* @uses Bake::getTestBody()
|
||||
* @uses Bake::getModelName()
|
||||
* @uses Bake::createFile()
|
||||
*/
|
||||
function makeModelTest ($name) {
|
||||
$fn = MODEL_TESTS.Inflector::underscore($name).'_test.php';
|
||||
|
@ -351,25 +428,32 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Returns CamelCased name of a model.
|
||||
*
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::camelize()
|
||||
*/
|
||||
function getModelName ($name) {
|
||||
return Inflector::camelize($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates a file with given path and contents.
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $contents
|
||||
* @return unknown
|
||||
* @param string $path
|
||||
* @param string $contents
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::dontAsk
|
||||
* @uses Bake::stdin
|
||||
* @uses Bake::stdout
|
||||
* @uses Bake::stderr
|
||||
*/
|
||||
function createFile ($path, $contents) {
|
||||
|
||||
if (is_file($path) && !$this->dont_ask) {
|
||||
if (is_file($path) && !$this->dontAsk) {
|
||||
fwrite($this->stdout, "File {$path} exists, overwrite? (yNaq) ");
|
||||
$key = fgets($this->stdin);
|
||||
|
||||
|
@ -378,7 +462,7 @@ class %sTest extends TestCase {
|
|||
exit;
|
||||
}
|
||||
elseif (preg_match("/^a$/", $key)) {
|
||||
$this->dont_ask = true;
|
||||
$this->dontAsk = true;
|
||||
}
|
||||
elseif (preg_match("/^y$/", $key)) {
|
||||
}
|
||||
|
@ -403,10 +487,13 @@ class %sTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Creates a directory with given path.
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @return unknown
|
||||
* @param string $path
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::stdin
|
||||
* @uses Bake::stdout
|
||||
*/
|
||||
function createDir ($path) {
|
||||
if (is_dir($path))
|
||||
|
|
Loading…
Reference in a new issue