From ab1db2532e6e12d196e6ec7857178eb1024eb4ef Mon Sep 17 00:00:00 2001 From: phpnut Date: Mon, 3 Oct 2005 04:43:55 +0000 Subject: [PATCH] removing changes made in trunk after directory changes made on next release git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1056 3807eeeb-6ff5-0310-8944-8be069107fe0 --- config/acl.ini.php | 2 +- config/routes.php | 8 +- config/routes.php.default | 6 +- libs/acl.php | 30 +- libs/acl_base.php | 33 +- libs/bake.php | 995 +++++++++++++++++++------------------- 6 files changed, 536 insertions(+), 538 deletions(-) diff --git a/config/acl.ini.php b/config/acl.ini.php index f66d1ca3a..0940ec8a8 100644 --- a/config/acl.ini.php +++ b/config/acl.ini.php @@ -1,4 +1,4 @@ -; + ; acl.ini.php - Cake ACL Configuration ; --------------------------------------------------------------------- diff --git a/config/routes.php b/config/routes.php index 671d1ba5c..1d81a3743 100644 --- a/config/routes.php +++ b/config/routes.php @@ -38,17 +38,17 @@ * its action called 'display', and we pass a param to select the view file * to use (in this case, /app/views/pages/home.thtml)... */ -$Route->connect('/', array('controller'=>'Pages', 'action'=>'display', 'home')); +$Route->connect ('/', array('controller'=>'Pages', 'action'=>'display', 'home')); /** * ...and connect the rest of 'Pages' controller's urls. */ -$Route->connect('/pages/*', array('controller'=>'Pages', 'action'=>'display')); +$Route->connect ('/pages/*', array('controller'=>'Pages', 'action'=>'display')); /** * Then we connect url '/test' to our test controller. This is helpfull in * developement. */ -$Route->connect('/test', array('controller'=>'Tests', 'action'=>'index')); +$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'index')); -?> \ No newline at end of file +?> diff --git a/config/routes.php.default b/config/routes.php.default index bf19a9cd4..d28391028 100644 --- a/config/routes.php.default +++ b/config/routes.php.default @@ -22,17 +22,17 @@ * and its action called 'display'. We pass a parameter to select the view file * to use (in this case, /app/views/pages/home.thtml). */ -$Route->connect('/', array('controller'=>'Pages', 'action'=>'display', 'home')); +$Route->connect ('/', array('controller'=>'Pages', 'action'=>'display', 'home')); /** * ...and connect the rest of 'Pages' controller's URLs. */ -$Route->connect('/pages/*', array('controller'=>'Pages', 'action'=>'display')); +$Route->connect ('/pages/*', array('controller'=>'Pages', 'action'=>'display')); /** * Then we connect url '/test' to our test controller. This is helpful in * development. */ -$Route->connect('/test', array('controller'=>'Tests', 'action'=>'test_all')); +$Route->connect ('/test', array('controller'=>'Tests', 'action'=>'test_all')); ?> \ No newline at end of file diff --git a/libs/acl.php b/libs/acl.php index b8a6ed4aa..d860a2d34 100644 --- a/libs/acl.php +++ b/libs/acl.php @@ -42,19 +42,21 @@ * */ class Acl -{ - /** - * Static function used to gain an instance of the correct ACL class. - * - * @return MyACL - */ - function getACL() - { - require_once CONFIGS.'core.php'; - require_once APP.'apis'.DS.ACL_FILENAME; +{ + + /** + * Static function used to gain an instance of the correct ACL class. + * + * @return MyACL + */ + function getACL() + { + require_once(CONFIGS.'core.php'); + require_once(APP.'apis'.DS.ACL_FILENAME); + + $myacl = ACL_CLASSNAME; + return new $myacl; + } - $myacl = ACL_CLASSNAME; - return new $myacl; - } } -?> \ No newline at end of file +?> diff --git a/libs/acl_base.php b/libs/acl_base.php index 9673a6795..ed87b7f65 100644 --- a/libs/acl_base.php +++ b/libs/acl_base.php @@ -36,25 +36,26 @@ uses('error_messages'); * Access Control List abstract class. Not to be instantiated. * Subclasses of this class are used by AclHelper to perform ACL checks in Cake. * - * @package cake + * @package cake * @subpackage libs - * @since CakePHP v 0.9.2 + * @since CakePHP v 0.9.2 * */ class AclBase { - function AclBase() - { - //No instantiations or constructor calls (even statically) - if (strcasecmp(get_class($this), "AclBase") == 0 || !is_subclass_of($this, "AclBase")) - { - trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR); - return NULL; - } - } - - function check($aro, $aco) - { - } -} + + function AclBase() + { + //No instantiations or constructor calls (even statically) + if (strcasecmp(get_class($this), "AclBase") == 0 || !is_subclass_of($this, "AclBase")) + { + trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR); + return NULL; + } + + } + + function check($aro, $aco) {} + +} ?> \ No newline at end of file diff --git a/libs/bake.php b/libs/bake.php index 3b47d513a..a851f6d37 100644 --- a/libs/bake.php +++ b/libs/bake.php @@ -47,525 +47,520 @@ uses('object', 'inflector'); * @subpackage cake.libs * @since CakePHP v 0.2.9 */ -class Bake extends Object -{ - /** - * Standard input stream (php://stdin). - * - * @var resource - * @access private - */ - var $stdin = null; +class Bake extends Object { - /** - * Standard output stream (php://stdout). - * - * @var resource - * @access private - */ - var $stdout = null; +/** + * Standard input stream (php://stdin). + * + * @var resource + * @access private + */ + var $stdin = null; - /** - * Standard error stream (php://stderr). - * - * @var resource - * @access private - */ - var $stderr = null; +/** + * Standard output stream (php://stdout). + * + * @var resource + * @access private + */ + var $stdout = null; - /** - * Counts actions taken. - * - * @var integer - * @access private - */ - var $actions = null; +/** + * Standard error stream (php://stderr). + * + * @var resource + * @access private + */ + var $stderr = null; - /** - * Decides whether to overwrite existing files without asking. - * - * @var boolean - * @access private - */ - var $dontAsk = false; +/** + * Counts actions taken. + * + * @var integer + * @access private + */ + var $actions = null; - /** - * Returns code template for PHP file generator. - * - * @param string $type - * @return string - * @access private - */ - function template($type) - { - switch ($type) - { - case 'view': return "%s"; - case 'model': return ""; - case 'action': return "\n\tfunction %s () {\n\t}\n"; - case 'ctrl': return ""; - case 'helper': return ""; - case 'test': return '"; + case 'action': return "\n\tfunction %s () {\n\t}\n"; + case 'ctrl': return ""; + case 'helper': return ""; + case 'test': return 'abc = new %s (); - } +class %sTest extends TestCase { + var $abc; - // called after the tests - function tearDown() - { - unset($this->abc); - } + // called before the tests + function setUp() + { + $this->abc = new %s (); + } + + // called after the tests + function tearDown() + { + unset($this->abc); + } /* - function testFoo () - { - $result = $this->abc->Foo(); - $expected = \'\'; - $this->assertEquals($result, $expected); - } + function testFoo () + { + $result = $this->abc->Foo(); + $expected = \'\'; + $this->assertEquals($result, $expected); + } */ } ?>'; - default: return false; - } - } - - - /** - * Baker's constructor method. Initialises bakery, and starts production. - * - * @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) - { - $this->stdin = fopen('php://stdin', 'r'); - $this->stdout = fopen('php://stdout', 'w'); - $this->stderr = fopen('php://stderr', 'w'); - - // Output directory name - fwrite($this->stderr, "\n".substr(ROOT,0,strlen(ROOT)-1).":\n".str_repeat('-',strlen(ROOT)+1)."\n"); - - switch ($type) - { - case 'model': - case 'models': - foreach ($names as $model_name) - { - $this->newModel($model_name); - } - break; - - case 'controller': - case 'ctrl': - $controller = array_shift($names); - $add_actions = array(); - foreach ($names as $action) - { - $add_actions[] = $action; - $this->newView($controller, $action); - } - - $this->newController($controller, $add_actions); - break; - - case 'view': - case 'views': - $r = null; - foreach ($names as $model_name) - { - if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r)) - { - $this->newView($r[1], $r[2]); - } - } - break; - } - - if (!$this->actions) - { - fwrite($this->stderr, "Nothing to do, quitting.\n"); - } - - } - - /** - * Creates new view in VIEWS/$controller/ directory. - * - * @param string $controller - * @param string $name - * @access private - * @uses Inflector::underscore() Underscores directory's name. - * @uses Bake::createDir() Creates new directory in views dir, named after the controller. - * @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) - { - //$controller = Inflector::pluralize($controller); - $dir = Inflector::underscore($controller); - $path = $dir.DS.strtolower($name).".thtml"; - $this->createDir(VIEWS.$dir); - $fn = VIEWS.$path; - $this->createFile($fn, sprintf($this->template('view'), "

Edit app".DS."views".DS."{$path} to change this message.

")); - $this->actions++; - } - - /** - * Creates new controller with defined actions, controller's test and helper - * with helper's test. - * - * @param string $name - * @param array $actions - * @access private - * @uses Inflector::pluralize() - * @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()) - { - //$name = Inflector::pluralize($name); - $this->makeController($name, $actions); - $this->makeControllerTest($name); - $this->makeHelper($name); - $this->makeHelperTest($name); - $this->actions++; - } - - /** - * Creates new controller file with defined actions. - * - * @param string $name - * @param array $actions - * @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); - $helper = $this->makeHelperName($name); - $body = sprintf($this->template('ctrl'), $ctrl, $helper, join('', $this->getActions($actions))); - return $this->createFile($this->makeControllerFn($name), $body); - } - - /** - * Returns controller's name in CamelCase. - * - * @param string $name - * @return string - * @access private - * @uses Inflector::camelize CamelCase for controller name. - */ - function makeControllerName($name) - { - return Inflector::camelize($name).'Controller'; - } - - /** - * Returns a name for controller's file, underscored. - * - * @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'; - } - - /** - * Creates new test for a controller. - * - * @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'; - $body = $this->getTestBody($this->makeControllerName($name)); - return $this->createFile($fn, $body); - } - - /** - * Creates new helper. - * - * @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)); - return $this->createFile($this->makeHelperFn($name), $body); - } - - /** - * Returns CamelCase name for a helper. - * - * @param string $name - * @return string - * @access private - * @uses Inflector::camelize() - */ - function makeHelperName($name) - { - return Inflector::camelize($name).'Helper'; - } - - /** - * Underscores file name for a helper. - * - * @param string $name - * @return string - * @access private - * @uses HELPERS - * @uses Inflector::underscore() - */ - function makeHelperFn($name) - { - return HELPERS.Inflector::underscore($name).'_helper.php'; - } - - /** - * Creates new test for a helper. - * - * @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'; - $body = $this->getTestBody($this->makeHelperName($name)); - return $this->createFile($fn, $body); - } - - /** - * Returns an array of actions' templates. - * - * @param array $as - * @return array - * @access private - * @uses Bake::template() - */ - function getActions($as) - { - $out = array(); - foreach ($as as $a) - { - $out[] = sprintf($this->template('action'), $a); - } - return $out; - } - - /** - * Returns a test template for given class. - * - * @param string $class - * @return string - * @access private - * @uses Bake::template() - */ - function getTestBody($class) - { - return sprintf($this->template('test'), $class, $class); - } - - /** - * Creates new model. - * - * @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))); - $this->makeModelTest ($name); - $this->actions++; - } - - /** - * Returns an underscored filename for a model. - * - * @param string $name - * @return string - * @access private - * @uses MODELS - * @uses Inflector::underscore() - */ - function getModelFn($name) - { - return MODELS.Inflector::underscore($name).'.php'; - } - - /** - * Creates a test for given model. - * - * @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'; - $body = $this->getTestBody($this->getModelName($name)); - return $this->createFile($fn, $body); - } - - /** - * Returns CamelCased name of a model. - * - * @param string $name - * @return string - * @access private - * @uses Inflector::camelize() - */ - function getModelName($name) - { - return Inflector::camelize($name); - } - - /** - * Creates a file with given path and contents. - * - * @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) - { - $shortPath = str_replace(ROOT,null,$path); - - if (is_file($path) && !$this->dontAsk) - { - fwrite($this->stdout, "File {$shortPath} exists, overwrite? (yNaq) "); - $key = trim(fgets($this->stdin)); - - if ($key=='q') - { - fwrite($this->stdout, "Quitting.\n"); - exit; - } - elseif ($key=='a') - { - $this->dont_ask = true; - } - elseif ($key=='y') - { - } - else - { - fwrite($this->stdout, "Skip {$shortPath}\n"); - return false; - } - } - - if ($f = fopen($path, 'w')) - { - fwrite($f, $contents); - fclose($f); - fwrite($this->stdout, "Wrote {$shortPath}\n"); - // debug ("Wrote {$path}"); - return true; - } - else - { - fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n"); - // debug ("Error! Couldn't open {$path} for writing."); + default: return false; - } - } + } + } - /** - * Creates a directory with given path. - * - * @param string $path - * @return boolean - * @access private - * @uses Bake::stdin - * @uses Bake::stdout - */ - function createDir($path) - { - if (is_dir($path)) - { - return true; - } - $shortPath = str_replace(ROOT, null, $path); +/** + * Baker's constructor method. Initialises bakery, and starts production. + * + * @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) + { - if (mkdir($path)) - { - fwrite($this->stdout, "Created {$shortPath}\n"); - // debug ("Created {$path}"); - return true; - } - else - { - fwrite($this->stderr, "Error! Couldn't create dir {$shortPath}\n"); - // debug ("Error! Couldn't create dir {$path}"); + $this->stdin = fopen('php://stdin', 'r'); + $this->stdout = fopen('php://stdout', 'w'); + $this->stderr = fopen('php://stderr', 'w'); + + // Output directory name + fwrite($this->stderr, "\n".substr(ROOT,0,strlen(ROOT)-1).":\n".str_repeat('-',strlen(ROOT)+1)."\n"); + + switch ($type) + { + + case 'model': + case 'models': + foreach ($names as $model_name) + $this->newModel($model_name); + break; + + case 'controller': + case 'ctrl': + $controller = array_shift($names); + + $add_actions = array(); + foreach ($names as $action) + { + $add_actions[] = $action; + $this->newView($controller, $action); + } + + $this->newController($controller, $add_actions); + break; + + case 'view': + case 'views': + $r = null; + foreach ($names as $model_name) + { + if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r)) + { + $this->newView($r[1], $r[2]); + } + } + break; + } + + if (!$this->actions) + fwrite($this->stderr, "Nothing to do, quitting.\n"); + + } + +/** + * Creates new view in VIEWS/$controller/ directory. + * + * @param string $controller + * @param string $name + * @access private + * @uses Inflector::underscore() Underscores directory's name. + * @uses Bake::createDir() Creates new directory in views dir, named after the controller. + * @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) + { +// $controller = Inflector::pluralize($controller); + $dir = Inflector::underscore($controller); + $path = $dir.DS.strtolower($name).".thtml"; + $this->createDir(VIEWS.$dir); + $fn = VIEWS.$path; + $this->createFile($fn, sprintf($this->template('view'), "

Edit app".DS."views".DS."{$path} to change this message.

")); + $this->actions++; + } + +/** + * Creates new controller with defined actions, controller's test and helper + * with helper's test. + * + * @param string $name + * @param array $actions + * @access private + * @uses Inflector::pluralize() + * @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()) + { +// $name = Inflector::pluralize($name); + $this->makeController($name, $actions); + $this->makeControllerTest($name); + $this->makeHelper($name); + $this->makeHelperTest($name); + $this->actions++; + } + +/** + * Creates new controller file with defined actions. + * + * @param string $name + * @param array $actions + * @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); + $helper = $this->makeHelperName($name); + $body = sprintf($this->template('ctrl'), $ctrl, $helper, join('', $this->getActions($actions))); + return $this->createFile($this->makeControllerFn($name), $body); + } + +/** + * Returns controller's name in CamelCase. + * + * @param string $name + * @return string + * @access private + * @uses Inflector::camelize CamelCase for controller name. + */ + function makeControllerName ($name) + { + return Inflector::camelize($name).'Controller'; + } + +/** + * Returns a name for controller's file, underscored. + * + * @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'; + } + +/** + * Creates new test for a controller. + * + * @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'; + $body = $this->getTestBody($this->makeControllerName($name)); + return $this->createFile($fn, $body); + } + +/** + * Creates new helper. + * + * @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)); + return $this->createFile($this->makeHelperFn($name), $body); + } + +/** + * Returns CamelCase name for a helper. + * + * @param string $name + * @return string + * @access private + * @uses Inflector::camelize() + */ + function makeHelperName ($name) + { + return Inflector::camelize($name).'Helper'; + } + +/** + * Underscores file name for a helper. + * + * @param string $name + * @return string + * @access private + * @uses HELPERS + * @uses Inflector::underscore() + */ + function makeHelperFn ($name) + { + return HELPERS.Inflector::underscore($name).'_helper.php'; + } + +/** + * Creates new test for a helper. + * + * @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'; + $body = $this->getTestBody($this->makeHelperName($name)); + return $this->createFile($fn, $body); + } + +/** + * Returns an array of actions' templates. + * + * @param array $as + * @return array + * @access private + * @uses Bake::template() + */ + function getActions ($as) + { + $out = array(); + foreach ($as as $a) + $out[] = sprintf($this->template('action'), $a); + return $out; + } + +/** + * Returns a test template for given class. + * + * @param string $class + * @return string + * @access private + * @uses Bake::template() + */ + function getTestBody ($class) + { + return sprintf($this->template('test'), $class, $class); + } + +/** + * Creates new model. + * + * @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))); + $this->makeModelTest ($name); + $this->actions++; + } + +/** + * Returns an underscored filename for a model. + * + * @param string $name + * @return string + * @access private + * @uses MODELS + * @uses Inflector::underscore() + */ + function getModelFn ($name) + { + return MODELS.Inflector::underscore($name).'.php'; + } + +/** + * Creates a test for given model. + * + * @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'; + $body = $this->getTestBody($this->getModelName($name)); + return $this->createFile($fn, $body); + } + +/** + * Returns CamelCased name of a model. + * + * @param string $name + * @return string + * @access private + * @uses Inflector::camelize() + */ + function getModelName ($name) + { + return Inflector::camelize($name); + } + +/** + * Creates a file with given path and contents. + * + * @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) + { + $shortPath = str_replace(ROOT,null,$path); + + if (is_file($path) && !$this->dontAsk) + { + fwrite($this->stdout, "File {$shortPath} exists, overwrite? (yNaq) "); + $key = trim(fgets($this->stdin)); + + if ($key=='q') + { + fwrite($this->stdout, "Quitting.\n"); + exit; + } + elseif ($key=='a') + { + $this->dont_ask = true; + } + elseif ($key=='y') + { + } + else + { + fwrite($this->stdout, "Skip {$shortPath}\n"); return false; - } - } + } + } + + if ($f = fopen($path, 'w')) + { + fwrite($f, $contents); + fclose($f); + fwrite($this->stdout, "Wrote {$shortPath}\n"); +// debug ("Wrote {$path}"); + return true; + } + else + { + fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n"); +// debug ("Error! Couldn't open {$path} for writing."); + return false; + } + } + +/** + * Creates a directory with given path. + * + * @param string $path + * @return boolean + * @access private + * @uses Bake::stdin + * @uses Bake::stdout + */ + function createDir ($path) + { + if (is_dir($path)) + return true; + + $shortPath = str_replace(ROOT, null, $path); + + if (mkdir($path)) + { + fwrite($this->stdout, "Created {$shortPath}\n"); +// debug ("Created {$path}"); + return true; + } + else + { + fwrite($this->stderr, "Error! Couldn't create dir {$shortPath}\n"); +// debug ("Error! Couldn't create dir {$path}"); + return false; + } + } } -?> \ No newline at end of file +?>