diff --git a/libs/bake.php b/libs/bake.php index cc86cccd3..f44f86d9b 100644 --- a/libs/bake.php +++ b/libs/bake.php @@ -45,53 +45,53 @@ uses('object', 'inflector'); */ class Bake extends Object { -/** - * Standard input stream (php://stdin). - * - * @var resource - * @access private - */ - var $stdin = null; - -/** - * 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 taken actions. - * - * @var integer - * @access private - */ - var $actions = null; + /** + * Standard error stream (php://stderr). + * + * @var resource + * @access private + */ + var $stderr = null; -/** - * Decides wether to overwrite existing files without asking. - * - * @var boolean - * @access private - */ - var $dontAsk = false; + /** + * Counts taken actions. + * + * @var integer + * @access private + */ + var $actions = null; -/** - * Returns template for file generator. - * - * @param string $type - * @return string - * @access private - */ + /** + * Decides wether to overwrite existing files without asking. + * + * @var boolean + * @access private + */ + var $dontAsk = false; + + /** + * Returns template for file generator. + * + * @param string $type + * @return string + * @access private + */ function template ($type) { switch ($type) { case 'view': return "%s"; @@ -130,19 +130,19 @@ class %sTest extends TestCase { } -/** - * 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. - */ + /** + * 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'); @@ -186,19 +186,19 @@ class %sTest extends TestCase { } -/** - * Creates new view in VIEWS/$controller/ directory. - * - * @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. - */ + /** + * Creates new view in VIEWS/$controller/ directory. + * + * @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); $path = "{$dir}/".strtolower($name).".thtml"; @@ -208,19 +208,19 @@ class %sTest extends TestCase { $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 Bake::makeController() - * @uses Bake::makeControllerTest() - * @uses Bake::makeHelper() - * @uses Bake::makeHelperTest() - * @uses Bake::actions Adds one action for each run. - */ + /** + * Creates new controller with defined actions, controller's test and helper + * with helper's test. + * + * @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); $this->makeControllerTest($name); @@ -229,20 +229,20 @@ class %sTest extends TestCase { $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. - */ + /** + * 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); @@ -250,115 +250,115 @@ class %sTest extends TestCase { 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. - */ + /** + * 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. - */ + /** + * 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() - */ + /** + * 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() - */ + /** + * 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() - */ + /** + * 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() - */ + /** + * 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() - */ + /** + * 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 array of actions' templates. - * - * @param array $as - * @return array - * @access private - * @uses Bake::template() - */ + /** + * Returns array of actions' templates. + * + * @param array $as + * @return array + * @access private + * @uses Bake::template() + */ function getActions ($as) { $out = array(); foreach ($as as $a) @@ -366,91 +366,91 @@ class %sTest extends TestCase { return $out; } -/** - * Returns test template for defined class. - * - * @param string $class - * @return string - * @access private - * @uses Bake::template() - */ + /** + * Returns test template for defined 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 - */ + /** + * 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 underscored name for model's file. - * - * @param string $name - * @return string - * @access private - * @uses MODELS - * @uses Inflector::underscore() - */ + /** + * Returns underscored name for model's file. + * + * @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 a given model. - * - * @param string $name - * @return boolean - * @access private - * @uses MODEL_TESTS - * @uses Inflector::underscore() - * @uses Bake::getTestBody() - * @uses Bake::getModelName() - * @uses Bake::createFile() - */ + /** + * Creates a test for a 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() - */ + /** + * 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 - */ + /** + * 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) { if (is_file($path) && !$this->dontAsk) { @@ -486,15 +486,15 @@ class %sTest extends TestCase { } } -/** - * Creates a directory with given path. - * - * @param string $path - * @return boolean - * @access private - * @uses Bake::stdin - * @uses Bake::stdout - */ + /** + * 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; diff --git a/libs/basics.php b/libs/basics.php index f502544cf..c78a8e2d7 100644 --- a/libs/basics.php +++ b/libs/basics.php @@ -14,29 +14,30 @@ ////////////////////////////////////////////////////////////////////////// /** - * Purpose: Basics - * Basic Cake functionalities. - * - * @filesource - * @author Cake Authors/Developers - * @copyright Copyright (c) 2005, Cake Authors/Developers - * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - * - */ + * Basic Cake functionalities. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * + */ /** - * Enter description here... - * - */ -function load_libs () { - foreach (list_modules(LIBS) as $lib) { + * Loads all libs from LIBS directory. + * + * @uses listModules() + * @uses LIBS + */ +function loadLibs () { + foreach (listModules(LIBS) as $lib) { if ($lib != 'basics') { include_once (LIBS.$lib.'.php'); } @@ -44,40 +45,47 @@ function load_libs () { } /** - * Enter description here... - * - */ -function load_models () { + * Loads all models. + * + * @uses listModules() + * @uses APP + * @uses MODELS + */ +function loadModels () { require (APP.'app_model.php'); - foreach (list_modules(MODELS) as $model) { + foreach (listModules(MODELS) as $model) { require (MODELS.$model.'.php'); } } /** - * Enter description here... - * - */ -function load_controllers () { + * Loads all controllers. + * + * @uses APP + * @uses listModules() + * @uses HELPERS + * @uses CONTROLLERS + */ +function loadControllers () { require (APP.'app_controller.php'); - foreach (list_modules(HELPERS) as $helper) { + foreach (listModules(HELPERS) as $helper) { require (HELPERS.$helper.'.php'); } - foreach (list_modules(CONTROLLERS) as $controller) { + foreach (listModules(CONTROLLERS) as $controller) { require (CONTROLLERS.$controller.'.php'); } } /** - * Enter description here... - * - * @param unknown_type $path - * @param unknown_type $sort - * @return unknown - */ -function list_modules($path, $sort=true) { + * Lists all .php files from a given path. + * + * @param string $path + * @param boolean $sort + * @return array + */ +function listModules($path, $sort=true) { if ($d = opendir($path)) { $out = array(); $r = null; @@ -98,30 +106,37 @@ function list_modules($path, $sort=true) { } /** - * Enter description here... - * - */ -function uses_config () { + * Loads core config. + * + * @uses $TIME_START + * @uses CONFIGS + */ +function usesConfig () { global $TIME_START; require (CONFIGS.'core.php'); } /** - * Enter description here... - * - */ -function uses_database ($level='devel') { + * Loads database connection identified by $level. + * + * @param string $level + * @uses $DB + * @uses DbFactory::make() + * @uses loadDatabaseConfig() + */ +function usesDatabase ($level='devel') { global $DB; $DB = DbFactory::make(loadDatabaseConfig($level)); } /** - * Enter description here... - * - * @return unknown - */ + * Loads database configuration identified by $level from CONFIGS/database.php. + * + * @param string $level + * @return mixed + */ function loadDatabaseConfig ($level='devel') { if (file_exists(CONFIGS.'database.php')) require (CONFIGS.'database.php'); @@ -139,17 +154,24 @@ function loadDatabaseConfig ($level='devel') { } /** - * Enter description here... - * - */ -function uses_tag_generator () { + * Loads tags configuration from CONFIGS/tags.php. + * + * @uses CONFIGS + */ +function usesTagGenerator () { require (CONFIGS.'tags.php'); } /** - * Enter description here... - * - */ + * Loads component/components from LIBS. + * + * Example: + * + * uses('inflector', 'object'); + * + * + * @uses LIBS + */ function uses () { $args = func_get_args(); foreach ($args as $arg) { @@ -158,12 +180,12 @@ function uses () { } /** - * Enter description here... - * - * @param unknown_type $var - * @param unknown_type $show_html - */ -function debug($var = FALSE, $show_html = false) { + * Setup a debug point. + * + * @param boolean $var + * @param boolean $show_html + */ +function debug($var = false, $show_html = false) { if (DEBUG) { print "\n
\n";
 		if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
@@ -176,10 +198,10 @@ function debug($var = FALSE, $show_html = false) {
 if (!function_exists('getMicrotime')) {
 
 /**
-  * Enter description here...
-  *
-  * @return unknown
-  */
+ * Returns microtime for execution time checking.
+ *
+ * @return integer
+ */
 	function getMicrotime() {
 		list($usec, $sec) = explode(" ", microtime());
 		return ((float)$usec + (float)$sec);
@@ -187,14 +209,14 @@ if (!function_exists('getMicrotime')) {
 }
 if (!function_exists('sortByKey')) {
 /**
-  * Enter description here...
-  *
-  * @param unknown_type $array
-  * @param unknown_type $sortby
-  * @param unknown_type $order
-  * @param unknown_type $type
-  * @return unknown
-  */
+ * Sorts given $array by key $sortby.
+ *
+ * @param array $array
+ * @param string $sortby
+ * @param string $order
+ * @param integer $type
+ * @return mixed
+ */
 	function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) {
 
 		if( is_array($array) ) {
@@ -210,22 +232,23 @@ if (!function_exists('sortByKey')) {
 			foreach( $sa as $key=>$val )
 			$out[] = $array[$key];
 
-			Return $out;
+			return $out;
 
 		}
 		else
-		Return null;
+		return null;
 	}
 }
 
 if (!function_exists('array_combine')) {
 /**
-  * Enter description here...
-  *
-  * @param unknown_type $a1
-  * @param unknown_type $a2
-  * @return unknown
-  */
+ * Combines given identical arrays by using the first array's values as keys,
+ * and second one's values as values.
+ *
+ * @param array $a1
+ * @param array $a2
+ * @return mixed Outputs either combined array or false.
+ */
 	function array_combine($a1, $a2) {
 		$a1 = array_values($a1);
 		$a2 = array_values($a2);
@@ -235,7 +258,7 @@ if (!function_exists('array_combine')) {
 		
 		$output = array();
 		
-		for ($i = 0; $i < count($a1); $i++) {
+		for ($i = 0, $c = count($a1); $i < $c; $i++) {
 			$output[$a1[$i]] = $a2[$i];
 		}
 		
@@ -244,37 +267,45 @@ if (!function_exists('array_combine')) {
 }
 
 /**
-  * Enter description here...
-  *
-  *
-  * @package cake
-  * @subpackage cake.libs
-  * @since Cake v 0.2.9
-  *
-  */
+ * Class used for internal manipulation with recordsets (?).
+ *
+ * @package cake
+ * @subpackage cake.libs
+ * @since Cake v 0.2.9
+ */
 class NeatArray {
-
-/**
-  * Enter description here...
-  *
-  * @param unknown_type $value
-  * @return NeatArray
-  */
+	/**
+	 * Value of NeatArray.
+	 *
+	 * @var array
+	 * @access public
+	 */
+    var $value;
+    
+	/**
+	 * Constructor.
+	 *
+	 * @param array $value
+	 * @access public
+	 * @uses NeatArray::value
+	 */
 	function NeatArray ($value) {
 		$this->value = $value;
 	}
 
-/**
-  * Enter description here...
-  *
-  * @param unknown_type $field_name
-  * @param unknown_type $value
-  * @return unknown
-  */
-	function findIn ($field_name, $value) {
+	/**
+	 * Checks wheter $fieldName with $value exists in this NeatArray object.
+	 *
+	 * @param string $fieldName
+	 * @param string $value
+	 * @return mixed
+	 * @access public
+	 * @uses NeatArray::value
+	 */
+	function findIn ($fieldName, $value) {
 		$out = false;
 		foreach ($this->value as $k=>$v) {
-			if (isset($v[$field_name]) && ($v[$field_name] == $value)) {
+			if (isset($v[$fieldName]) && ($v[$fieldName] == $value)) {
 				$out[$k] = $v;
 			}
 		}
@@ -282,14 +313,19 @@ class NeatArray {
 		return $out;
 	}
 
-/**
-  * Enter description here...
-  *
-  */
-	function cleanup () {
+	/**
+	 * Checks if $this->value is array, and removes all empty elements.
+	 *
+	 * @access public
+	 * @uses NeatArray::value
+	 */
+	function cleanup ()
+	{
 		$out = is_array($this->value)? array(): null;
-		foreach ($this->value as $k=>$v) {
-			if ($v) {
+		foreach ($this->value as $k=>$v)
+		{
+			if ($v)
+			{
 				$out[$k] = $v;
 			}
 		}
@@ -297,4 +333,4 @@ class NeatArray {
 	}
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/public/dispatch.php b/public/dispatch.php
index a8bd06316..2edbc764c 100644
--- a/public/dispatch.php
+++ b/public/dispatch.php
@@ -14,39 +14,39 @@
 //////////////////////////////////////////////////////////////////////////
 
 /**
-  * Purpose: Dispatch
-  * The main "loop"
-  * 
-  * @filesource 
-  * @author Cake Authors/Developers
-  * @copyright Copyright (c) 2005, Cake Authors/Developers
-  * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
-  * @package cake
-  * @subpackage cake.public
-  * @since Cake v 0.2.9
-  * @version $Revision$
-  * @modifiedby $LastChangedBy$
-  * @lastmodified $Date$
-  * @license http://www.opensource.org/licenses/mit-license.php The MIT License
-  */
+ * Purpose: Dispatch
+ * The main "loop"
+ * 
+ * @filesource 
+ * @author Cake Authors/Developers
+ * @copyright Copyright (c) 2005, Cake Authors/Developers
+ * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
+ * @package cake
+ * @subpackage cake.public
+ * @since Cake v 0.2.9
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
 
 /**
-  * DIRECTORY LAYOUT
-  */
+ * DIRECTORY LAYOUT
+ */
 require ('../config/paths.php');
 
 /**
-  * Startup
-  */
+ * Startup
+ */
 require (LIBS.'basics.php');
 
 uses ('dispatcher', 'db_factory');
-uses_config();
-uses_database();
-uses_tag_generator();
+usesConfig();
+usesDatabase();
+usesTagGenerator();
 
-load_models ();
-load_controllers ();
+loadModels ();
+loadControllers ();
 
 session_start();
 
@@ -60,4 +60,4 @@ if ($DB) $DB->close();
 ## CLEANUP
 if (DEBUG) echo "";
 
-?>
\ No newline at end of file
+?>