From 9bbe2759032b7373a8d4a6f148636f3c6775f9c3 Mon Sep 17 00:00:00 2001 From: pies Date: Tue, 31 May 2005 23:18:22 +0000 Subject: [PATCH] (I don't know what's happening:/ ) git-svn-id: https://svn.cakephp.org/repo/trunk/cake@207 3807eeeb-6ff5-0310-8944-8be069107fe0 --- app/controllers/pages_controller.php | 3 + app/controllers/tests_controller.php | 3 + libs/bake.php | 16 +- libs/basics.php | 28 +- libs/cache.php | 38 +- libs/controller.php | 592 +++++++++++++++++++++------ libs/dbo.php | 93 +++-- libs/dbo_adodb.php | 38 +- libs/dbo_mysql.php | 56 +-- libs/dbo_postgres.php | 46 +-- libs/dispatcher.php | 52 +-- libs/flay.php | 14 +- libs/folder.php | 81 ++-- libs/inflector.php | 52 +-- libs/model.php | 200 +++++---- libs/object.php | 12 +- libs/test.php | 44 +- libs/time.php | 32 +- libs/validators.php | 24 +- 19 files changed, 892 insertions(+), 532 deletions(-) diff --git a/app/controllers/pages_controller.php b/app/controllers/pages_controller.php index 12a27db40..28dbf598d 100644 --- a/app/controllers/pages_controller.php +++ b/app/controllers/pages_controller.php @@ -2,6 +2,9 @@ class PagesController extends PagesHelper { +/** + * Displays a view + */ function display () { if (!func_num_args()) diff --git a/app/controllers/tests_controller.php b/app/controllers/tests_controller.php index 9cc5dc220..5b3702786 100644 --- a/app/controllers/tests_controller.php +++ b/app/controllers/tests_controller.php @@ -4,6 +4,9 @@ uses('test', 'folder', 'inflector'); class TestsController extends TestsHelper { +/** + * Runs all library and application tests + */ function test_all () { $this->layout = 'test'; diff --git a/libs/bake.php b/libs/bake.php index d78a2d806..5b8402379 100644 --- a/libs/bake.php +++ b/libs/bake.php @@ -70,7 +70,7 @@ class Bake extends Object { var $stderr = null; /** - * Counts taken actions. + * Counts actions taken. * * @var integer * @access private @@ -78,7 +78,7 @@ class Bake extends Object { var $actions = null; /** - * Decides wether to overwrite existing files without asking. + * Decides whether to overwrite existing files without asking. * * @var boolean * @access private @@ -86,7 +86,7 @@ class Bake extends Object { var $dontAsk = false; /** - * Returns template for file generator. + * Returns code template for PHP file generator. * * @param string $type * @return string @@ -195,8 +195,8 @@ class %sTest extends TestCase { * @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 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. @@ -358,7 +358,7 @@ class %sTest extends TestCase { } /** - * Returns array of actions' templates. + * Returns an array of actions' templates. * * @param array $as * @return array @@ -373,7 +373,7 @@ class %sTest extends TestCase { } /** - * Returns test template for defined class. + * Returns a test template for given class. * * @param string $class * @return string @@ -403,7 +403,7 @@ class %sTest extends TestCase { } /** - * Returns underscored name for model's file. + * Returns an underscored filename for a model. * * @param string $name * @return string diff --git a/libs/basics.php b/libs/basics.php index 0f75de07e..9eded39a9 100644 --- a/libs/basics.php +++ b/libs/basics.php @@ -65,7 +65,7 @@ function loadControllers () { } /** - * Loads a controller and it's helper libraries + * Loads a controller and its helper libraries. * * @param string $name * @return boolean @@ -83,7 +83,7 @@ function loadController ($name) { } /** - * Lists PHP files in a specified directory + * Lists PHP files in given directory. * * @param string $path * @return array @@ -143,7 +143,6 @@ function debug($var = false, $show_html = false) { if (!function_exists('getMicrotime')) { - /** * Returns microtime for execution time checking. * @@ -154,13 +153,14 @@ if (!function_exists('getMicrotime')) { return ((float)$usec + (float)$sec); } } + if (!function_exists('sortByKey')) { /** * Sorts given $array by key $sortby. * * @param array $array * @param string $sortby - * @param string $order + * @param string $order Sort order asc/desc (ascending or descending). * @param integer $type * @return mixed */ @@ -190,7 +190,7 @@ if (!function_exists('sortByKey')) { if (!function_exists('array_combine')) { /** * Combines given identical arrays by using the first array's values as keys, - * and second one's values as values. + * and the second one's values as values. (Implemented for back-compatibility with PHP4.) * * @param array $a1 * @param array $a2 @@ -216,7 +216,7 @@ if (!function_exists('array_combine')) { } /** - * Class used for internal manipulation of multiarrays (arrays of arrays) + * Class used for internal manipulation of multiarrays (arrays of arrays). * * @package cake * @subpackage cake.libs @@ -232,7 +232,7 @@ class NeatArray { var $value; /** - * Constructor. + * Constructor. Defaults to an empty array. * * @param array $value * @access public @@ -243,7 +243,7 @@ class NeatArray { } /** - * Checks wheter $fieldName with $value exists in this NeatArray object. + * Checks whether $fieldName with $value exists in this NeatArray object. * * @param string $fieldName * @param string $value @@ -282,7 +282,7 @@ class NeatArray { /** * Adds elements from the supplied array to itself. * - * @param string $array + * @param string $value * @return bool * @access public * @uses NeatArray::value @@ -293,9 +293,9 @@ class NeatArray { /** - * Returns itself merged with supplied array. + * Returns itself merged with given array. * - * @param string $array + * @param array $value Array to add to NeatArray. * @return array * @access public * @uses NeatArray::value @@ -307,7 +307,7 @@ class NeatArray { /** * Counts repeating strings and returns an array of totals. * - * @param int $sortedBy 1 sorts by values, 2 by keys, default null (no sort) + * @param int $sortedBy A value of 1 sorts by values, a value of 2 sorts by keys. Defaults to null (no sorting). * @return array * @access public * @uses NeatArray::value @@ -333,7 +333,7 @@ class NeatArray { } /** - * Passes each of it's values thrue a specified function or method. + * Passes each of its values through a specified function or method. Think of PHP's array_walk. * * @return array * @access public @@ -345,7 +345,7 @@ class NeatArray { } /** - * Extracts a value from all array items + * Extracts a value from all array items. * * @return array * @access public diff --git a/libs/cache.php b/libs/cache.php index 1ffb3d90b..a61e0866b 100644 --- a/libs/cache.php +++ b/libs/cache.php @@ -46,35 +46,35 @@ uses('model'); class Cache extends Model { /** - * Enter description here... + * Identifier. Either an MD5 string or NULL. * * @var unknown_type */ var $id = null; /** - * Enter description here... + * Content container for cache data. * * @var unknown_type */ var $data = null; /** - * Enter description here... + * Content to be cached. * * @var unknown_type */ var $for_caching = null; /** - * Enter description here... + * Name of the database table used for caching. * * @var unknown_type */ var $use_table = 'cache'; /** - * Enter description here... + * Constructor. Generates an md5'ed id for internal use. Calls the constructor on Model as well. * * @param unknown_type $id */ @@ -84,7 +84,7 @@ class Cache extends Model { } /** - * Enter description here... + * Returns this object's id after setting it. If no $id is given then $this->id is returned. * * @param unknown_type $id * @return unknown @@ -95,10 +95,10 @@ class Cache extends Model { } /** - * Enter description here... + * Save $content in cache for $keep_for seconds. * - * @param unknown_type $content - * @param unknown_type $keep_for + * @param string $content Content to keep in cache. + * @param int $keep_for Number of seconds to keep data in cache. * @return unknown */ function remember ($content, $keep_for=CACHE_PAGES_FOR) { @@ -108,11 +108,11 @@ class Cache extends Model { } /** - * Enter description here... + * Returns content from the Cache object itself, if the Cache object has a non-empty data property. Else from the database cache. * * @return unknown */ - function restore () { + function restore() { if (empty($this->data['data'])) return $this->find("id='{$this->id}' AND expire>NOW()"); @@ -120,29 +120,29 @@ class Cache extends Model { } /** - * Enter description here... + * Returns true if the cache data property has current (non-stale) content for given id. * - * @return unknown + * @return boolean */ - function has () { + function has() { return is_array($this->data = $this->find("id='{$this->id}' AND expire>NOW()")); } /** - * Enter description here... + * Appends $string to the for_caching property of the Cache object. * - * @param unknown_type $string + * @param string $string */ - function append ($string) { + function append($string) { $this->for_caching .= $string; } /** - * Enter description here... + * Clears the cache database table. * * @return unknown */ - function clear () { + function clear() { return $this->query("DELETE FROM {$this->use_table}"); } } diff --git a/libs/controller.php b/libs/controller.php index d30244a98..55d72f53e 100644 --- a/libs/controller.php +++ b/libs/controller.php @@ -51,7 +51,7 @@ uses('model', 'template', 'inflector', 'folder'); class Controller extends Template { /** - * Enter description here... + * Name of the controller. * * @var unknown_type * @access public @@ -75,7 +75,7 @@ class Controller extends Template { var $action = null; /** - * Enter description here... + * This Controller's Model. * * @var unknown_type * @access public @@ -99,7 +99,7 @@ class Controller extends Template { var $_crumbs = array(); /** - * Enter description here... + * Constructor. * */ function __construct () { @@ -140,7 +140,7 @@ class Controller extends Template { } /** - * Enter description here... + * Redirects to given $url, after turning off $this->autoRender. * * @param unknown_type $url */ @@ -162,30 +162,32 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an URL for a combination of controller and action. * - * @param unknown_type $url - * @return unknown + * @param string $url + * @return string Full constructed URL as a string. */ function urlFor ($url=null) { if (empty($url)) { - return $this->base.'/'.strtolower($this->params['controller']).'/'.strtolower($this->params['action']); + $out = $this->base.'/'.strtolower($this->params['controller']).'/'.strtolower($this->params['action']); } elseif ($url[0] == '/') { - return $this->base . $url; + $out = $this->base . $url; } else { - return $this->base . '/' . strtolower($this->params['controller']) . '/' . $url; + $out = $this->base . '/' . strtolower($this->params['controller']) . '/' . $url; } + + return ereg_replace('&([^a])', '&\1', $out); } /** - * Enter description here... + * Returns a space-separated string with items of the $options array. * - * @param unknown_type $options - * @param unknown_type $insert_before + * @param array $options Array of HTML options. + * @param string $insert_before * @param unknown_type $insert_after - * @return unknown + * @return string */ function parseHtmlOptions ($options, $insert_before=' ', $insert_after=null) { if (is_array($options)) { @@ -202,13 +204,13 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an HTML link to $url for given $title, optionally using $html_options and $confirm_message (for "flash"). * - * @param unknown_type $title - * @param unknown_type $url - * @param unknown_type $html_options - * @param unknown_type $confirm_message - * @return unknown + * @param string $title The content of the A tag. + * @param string $url + * @param array $html_options Array of HTML options. + * @param string $confirm_message Message to be shown in "flash". + * @return string */ function linkTo ($title, $url, $html_options=null, $confirm_message=false) { $confirm_message? $html_options['onClick'] = "return confirm('{$confirm_message}')": null; @@ -216,12 +218,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an external HTML link to $url for given $title, optionally using $html_options. * - * @param unknown_type $title - * @param unknown_type $url - * @param unknown_type $html_options - * @return unknown + * @param string $title + * @param string $url + * @param array $html_options + * @return string */ function linkOut ($title, $url=null, $html_options=null) { $url = $url? $url: $title; @@ -229,32 +231,31 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an HTML FORM element. * - * @param unknown_type $target - * @param unknown_type $type - * @param unknown_type $html_options - * @return unknown + * @param string $target URL for the FORM's ACTION attribute. + * @param string $type FORM type (POST/GET). + * @param array $html_options + * @return string An formatted opening FORM tag. */ function formTag ($target=null, $type='post', $html_options=null) { $html_options['action'] = $this->UrlFor($target); $html_options['method'] = $type=='get'? 'get': 'post'; $type == 'file'? $html_options['enctype'] = 'multipart/form-data': null; - return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, '')); } /** - * Creates a generic html tag (no content) + * Returns a generic HTML tag (no content). * * Examples: * * tag("br") =>
* * tag("input", array("type" => "text")) => * - * @param string $name name of element - * @param array $options html options - * @param bool $open is the tag open or closed (default closed "/>") - * @return string html tag + * @param string $name Name of HTML element + * @param array $options HTML options + * @param bool $open Is the tag open or closed? (defaults to closed "/>") + * @return string The formatted HTML tag */ function tag($name, $options=null, $open=false) { $tag = "<$name ". $this->parseHtmlOptions($options); @@ -263,28 +264,28 @@ class Controller extends Template { } /** - * Creates a generic html tag with content + * Returns a generic HTML tag with content. * * Examples: * * content_tag("p", "Hello world!") =>

Hello world!

* * content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => *

Hello world!

* - * @param string $name name of element - * @param array $options html options - * @param bool $open is the tag open or closed (default closed "/>") - * @return string html tag + * @param string $name Name of HTML element + * @param array $options HTML options + * @param bool $open Is the tag open or closed? (defaults to closed "/>") + * @return string The formatted HTML tag */ function contentTag($name, $content, $options=null) { return "<$name ". $this->parseHtmlOptions($options). ">$content"; } /** - * Enter description here... + * Returns a formatted SUBMIT button for HTML FORMs. * - * @param unknown_type $caption - * @param unknown_type $html_options - * @return unknown + * @param string $caption Text on SUBMIT button + * @param array $html_options HTML options + * @return string The formatted SUBMIT button */ function submitTag ($caption='Submit', $html_options=null) { $html_options['value'] = $caption; @@ -292,12 +293,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns a formatted INPUT tag for HTML FORMs. * - * @param unknown_type $tag_name - * @param unknown_type $size - * @param unknown_type $html_options - * @return unknown + * @param string $tag_name Name attribute for INPUT element + * @param int $size Size attribute for INPUT element + * @param array $html_options + * @return string The formatted INPUT element */ function inputTag ($tag_name, $size=20, $html_options=null) { $html_options['size'] = $size; @@ -307,12 +308,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an INPUT element with type="password". * - * @param unknown_type $tag_name - * @param unknown_type $size - * @param unknown_type $html_options - * @return unknown + * @param string $tag_name + * @param int $size + * @param array $html_options + * @return string */ function passwordTag ($tag_name, $size=20, $html_options=null) { $html_options['size'] = $size; @@ -321,12 +322,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an INPUT element with type="hidden". * - * @param unknown_type $tag_name - * @param unknown_type $value - * @param unknown_type $html_options - * @return unknown + * @param string $tag_name + * @param string $value + * @param array $html_options + * @return string */ function hiddenTag ($tag_name, $value=null, $html_options=null) { $html_options['value'] = $value? $value: $this->tagValue($tag_name); @@ -334,24 +335,24 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an INPUT element with type="file". * - * @param unknown_type $tag_name - * @param unknown_type $html_options - * @return unknown + * @param string $tag_name + * @param array $html_options + * @return string */ function fileTag ($tag_name, $html_options=null) { return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, '', ' ')); } /** - * Enter description here... + * Returns a TEXTAREA element. * - * @param unknown_type $tag_name - * @param unknown_type $cols - * @param unknown_type $rows - * @param unknown_type $html_options - * @return unknown + * @param string $tag_name + * @param int $cols + * @param int $rows + * @param array $html_options + * @return string */ function areaTag ($tag_name, $cols=60, $rows=10, $html_options=null) { $value = empty($html_options['value'])? $this->tagValue($tag_name): empty($html_options['value']); @@ -361,12 +362,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns an INPUT element with type="checkbox". Checkedness is to be passed as string "checked" with the key "checked" in the $html_options array. * - * @param unknown_type $tag_name - * @param unknown_type $title - * @param unknown_type $html_options - * @return unknown + * @param string $tag_name + * @param string $title + * @param array $html_options + * @return string */ function checkboxTag ($tag_name, $title=null, $html_options=null) { $this->tagValue($tag_name)? $html_options['checked'] = 'checked': null; @@ -375,13 +376,13 @@ class Controller extends Template { } /** - * Enter description here... + * Returns a set of radio buttons. * - * @param unknown_type $tag_name - * @param unknown_type $options - * @param unknown_type $inbetween - * @param unknown_type $html_options - * @return unknown + * @param string $tag_name + * @param array $options Array of options to select from + * @param string $inbetween String to separate options. See PHP's implode() function + * @param array $html_options + * @return string */ function radioTags ($tag_name, $options, $inbetween=null, $html_options=null) { $value = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name); @@ -399,13 +400,13 @@ class Controller extends Template { } /** - * Enter description here... + * Returns a SELECT element, * - * @param unknown_type $tag_name - * @param unknown_type $options - * @param unknown_type $outer_options - * @param unknown_type $inner_options - * @return unknown + * @param string $tag_name Name attribute of the SELECT + * @param array $options Array of the OPTION elements to be used in the SELECT element + * @param array $outer_options Array of HTML options for the opening SELECT element + * @param array $inner_options + * @return string Formatted SELECT element */ function selectTag ($tag_name, $options, $outer_options=null, $inner_options=null) { if (!is_array($options) || !count($options)) @@ -425,12 +426,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns a formatted IMG element. * - * @param unknown_type $path - * @param unknown_type $alt - * @param unknown_type $html_options - * @return unknown + * @param string $path Path to the image file + * @param string $alt ALT attribute for the IMG tag + * @param array $html_options + * @return string Formatted IMG tag */ function imageTag ($path, $alt=null, $html_options=null) { $url = "{$this->base}/images/{$path}"; @@ -439,12 +440,12 @@ class Controller extends Template { /** - * Returns a CSS link meta-tag + * Returns a LINK element for CSS stylesheets. * - * @param string $path - * @param string $rel + * @param string $path Path to CSS file + * @param string $rel Rel attribute. Defaults to "stylesheet". * @param array $html_options - * @return string + * @return string Formatted LINK element. */ function cssTag ($path, $rel='stylesheet', $html_options=null) { $url = "{$this->base}/css/{$path}.css"; @@ -463,19 +464,19 @@ class Controller extends Template { } /** - * Returns a javascript script tag + * Returns a JavaScript script tag. * - * @param string $script the javascript - * @return string + * @param string $script The JavaScript to be wrapped in SCRIPT tags. + * @return string The full SCRIPT element, with the JavaScript inside it. */ function javascriptTag ($script) { return sprintf(TAG_JAVASCRIPT, $script); } /** - * Returns a javascript include tag + * Returns a JavaScript include tag * - * @param string $url url to javascript file. + * @param string $url URL to JavaScript file. * @return string */ function javascriptIncludeTag ($url) { @@ -483,12 +484,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns a row of formatted and named TABLE headers. * - * @param unknown_type $names - * @param unknown_type $tr_options - * @param unknown_type $th_options - * @return unknown + * @param array $names + * @param array $tr_options + * @param array $th_options + * @return string */ function tableHeaders ($names, $tr_options=null, $th_options=null) { $args = func_get_args(); @@ -501,12 +502,12 @@ class Controller extends Template { } /** - * Enter description here... + * Returns a formatted string of table rows (TR's with TD's in them). * - * @param unknown_type $data - * @param unknown_type $tr_options - * @param unknown_type $td_options - * @return unknown + * @param array $data Array of table data + * @param array $tr_options HTML options for TR elements + * @param array $td_options HTML options for TD elements + * @return string */ function tableCells ($data, $odd_tr_options=null, $even_tr_options=null) { if (empty($data[0]) || !is_array($data[0])) @@ -527,7 +528,7 @@ class Controller extends Template { } /** - * Generates a nested