- I've rebuilt the startup a bit, more libraries are explicitly loaded at startup. They were loaded anyway (Object, Inflector), but implicitly thru uses() calls. I did it to untangle the relationships between files.

- Link tag generator fixed for compatibility with XHTML (& => &)
- prepare() and tables() methods renamed to prepareField() and tablesList() in database layers, prepare() and tables() meta-methods created in Model. The first one so that prepare() can accept both strings and arrays, the second one to fix Ticket #26 (case-sensitive table names didn't work for DB2).
- Few minor changes of includes() to requires() and the other way, to prevent unnecessary program terminations, and potential crashes.
- Time::toAtom() and Time::toRss() to format dates for XML feeds.
- Some code cleanups (unnecessary __construct()'s), also, I'm changing the parentheses into:

if (true)
{
}

I hope that's ok with everybody? I find it easier to understand code with that formatting. Does anyone know a highly configurable tool that would format PHP code automatically?

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@241 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
pies 2005-06-11 03:45:31 +00:00
parent f2f3d56e36
commit 39132f9bcf
21 changed files with 327 additions and 268 deletions

View file

@ -30,8 +30,6 @@
* *
*/ */
uses('neat_array');
/** /**
* Loads all models. * Loads all models.
* *
@ -90,7 +88,8 @@ function loadController ($name) {
* @param string $path * @param string $path
* @return array * @return array
*/ */
function listClasses($path) { function listClasses($path)
{
$modules = new Folder($path); $modules = new Folder($path);
return $modules->find('(.+)\.php'); return $modules->find('(.+)\.php');
} }
@ -102,7 +101,7 @@ function config () {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) { foreach ($args as $arg) {
if (file_exists(CONFIGS.$arg.'.php')) { if (file_exists(CONFIGS.$arg.'.php')) {
require_once (CONFIGS.$arg.'.php'); include (CONFIGS.$arg.'.php');
if (count($args) == 1) return true; if (count($args) == 1) return true;
} }
else { else {
@ -118,7 +117,7 @@ function config () {
* *
* Example: * Example:
* <code> * <code>
* uses('inflector', 'object'); * uses('flay', 'time');
* </code> * </code>
* *
* @uses LIBS * @uses LIBS
@ -147,8 +146,10 @@ function uses ()
* @param boolean $var * @param boolean $var
* @param boolean $show_html * @param boolean $show_html
*/ */
function debug($var = false, $show_html = false) { function debug($var = false, $show_html = false)
if (DEBUG) { {
if (DEBUG)
{
print "\n<pre>\n"; print "\n<pre>\n";
if ($show_html) $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var)); if ($show_html) $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
print_r($var); print_r($var);
@ -157,7 +158,8 @@ function debug($var = false, $show_html = false) {
} }
if (!function_exists('getMicrotime')) { if (!function_exists('getMicrotime'))
{
/** /**
* Returns microtime for execution time checking. * Returns microtime for execution time checking.
* *
@ -183,7 +185,7 @@ if (!function_exists('sortByKey')) {
if (is_array($array)) { if (is_array($array)) {
foreach( $array AS $key => $val ) foreach ($array as $key => $val)
$sa[$key] = $val[$sortby]; $sa[$key] = $val[$sortby];
if ($order == 'asc') if ($order == 'asc')

View file

@ -224,6 +224,7 @@ class Controller extends Template {
/** /**
* Returns an external HTML link to $url for given $title, optionally using $html_options. * Returns an external HTML link to $url for given $title, optionally using $html_options.
* The ereg_replace is to replace the '&' in the URL into &amp; for XHTML purity.
* *
* @param string $title * @param string $title
* @param string $url * @param string $url
@ -232,7 +233,7 @@ class Controller extends Template {
*/ */
function linkOut ($title, $url=null, $html_options=null) { function linkOut ($title, $url=null, $html_options=null) {
$url = $url? $url: $title; $url = $url? $url: $title;
return sprintf(TAG_LINK, $url, $this->parseHtmlOptions($html_options), $title); return sprintf(TAG_LINK, ereg_replace('&([^a])', '&amp;\1', $url), $this->parseHtmlOptions($html_options), $title);
} }
/** /**
@ -247,6 +248,7 @@ class Controller extends Template {
$html_options['action'] = $this->UrlFor($target); $html_options['action'] = $this->UrlFor($target);
$html_options['method'] = $type=='get'? 'get': 'post'; $html_options['method'] = $type=='get'? 'get': 'post';
$type == 'file'? $html_options['enctype'] = 'multipart/form-data': null; $type == 'file'? $html_options['enctype'] = 'multipart/form-data': null;
return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, '')); return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, ''));
} }
@ -631,8 +633,6 @@ class Controller extends Template {
return empty($this->validationErrors[$field])? 0: $this->validationErrors[$field]; return empty($this->validationErrors[$field])? 0: $this->validationErrors[$field];
} }
/** /**
* Adds $name and $link to the breadcrumbs array. * Adds $name and $link to the breadcrumbs array.
* *

View file

@ -23,7 +23,7 @@
* Example usage: * Example usage:
* *
* <code> * <code>
* require('dbo_mysql.php'); // or 'dbo_postgres.php' * require_once('dbo_mysql.php'); // or 'dbo_postgres.php'
* *
* // create and connect the object * // create and connect the object
* $db = new DBO_MySQL(array( // or 'DBO_Postgres' * $db = new DBO_MySQL(array( // or 'DBO_Postgres'
@ -186,7 +186,6 @@ class DBO extends Object {
*/ */
var $_queriesLogMax=200; var $_queriesLogMax=200;
// specific for each database, implemented in db drivers // specific for each database, implemented in db drivers
function connect ($config) { function connect ($config) {
die('Please implement DBO::connect() first.'); die('Please implement DBO::connect() first.');
@ -204,7 +203,7 @@ class DBO extends Object {
die('Please implement DBO::fetchRow() first.'); die('Please implement DBO::fetchRow() first.');
} }
function tables() { function tablesList() {
die('Please implement DBO::tables() first.'); die('Please implement DBO::tables() first.');
} }
@ -212,6 +211,10 @@ class DBO extends Object {
die('Please implement DBO::fields() first.'); die('Please implement DBO::fields() first.');
} }
function prepareField ($data) {
die('Please implement DBO::prepareField() first.');
}
function lastError ($result) { function lastError ($result) {
die('Please implement DBO::lastError() first.'); die('Please implement DBO::lastError() first.');
} }
@ -278,11 +281,7 @@ class DBO extends Object {
*/ */
function prepare ($data) function prepare ($data)
{ {
if (is_string($data)) if (is_array($data))
{
return $this->prepareValue($data);
}
else
{ {
$out = null; $out = null;
foreach ($data as $key=>$item) foreach ($data as $key=>$item)
@ -291,7 +290,17 @@ class DBO extends Object {
} }
return $out; return $out;
} }
else
{
return $this->prepareValue($data);
} }
}
function tables()
{
return array_map('strtolower', $this->tablesList());
}
/** /**
* Executes given SQL statement. * Executes given SQL statement.
@ -312,7 +321,8 @@ class DBO extends Object {
* @param string $sql * @param string $sql
* @return unknown * @return unknown
*/ */
function query($sql) { function query($sql)
{
$t = getMicrotime(); $t = getMicrotime();
$this->_result = $this->execute($sql); $this->_result = $this->execute($sql);
$this->affected = $this->lastAffected(); $this->affected = $this->lastAffected();

View file

@ -14,7 +14,6 @@
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/** /**
* Purpose: DBO_AdoDB
* AdoDB layer for DBO. * AdoDB layer for DBO.
* *
* @filesource * @filesource
@ -32,7 +31,6 @@
/** /**
* Include AdoDB files. * Include AdoDB files.
*
*/ */
require_once(VENDORS.'adodb/adodb.inc.php'); require_once(VENDORS.'adodb/adodb.inc.php');
@ -42,7 +40,6 @@ require_once(VENDORS.'adodb/adodb.inc.php');
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
*
*/ */
class DBO_AdoDB extends DBO { class DBO_AdoDB extends DBO {
@ -99,7 +96,7 @@ class DBO_AdoDB extends DBO {
* *
* @return array Array of tablenames in the database * @return array Array of tablenames in the database
*/ */
function tables() { function tablesList() {
$tables = $this->_adodb->MetaTables('TABLES'); $tables = $this->_adodb->MetaTables('TABLES');
if (!sizeof($tables)>0) { if (!sizeof($tables)>0) {

View file

@ -37,7 +37,6 @@
/** /**
* Include DBO. * Include DBO.
*
*/ */
uses('dbo'); uses('dbo');
@ -47,7 +46,6 @@ uses('dbo');
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
*
*/ */
class DBO_MySQL extends DBO { class DBO_MySQL extends DBO {
@ -104,7 +102,7 @@ class DBO_MySQL extends DBO {
* *
* @return array Array of tablenames in the database * @return array Array of tablenames in the database
*/ */
function tables () { function tablesList () {
$result = mysql_list_tables($this->config['database']); $result = mysql_list_tables($this->config['database']);
if (!$result) { if (!$result) {
@ -177,7 +175,6 @@ class DBO_MySQL extends DBO {
/** /**
* Returns the ID generated from the previous INSERT operation. * Returns the ID generated from the previous INSERT operation.
* *
* @param string $table Name of the database table
* @return int * @return int
*/ */
function lastInsertId() { function lastInsertId() {

View file

@ -37,16 +37,15 @@
/** /**
* Include DBO. * Include DBO.
*
*/ */
uses('dbo'); uses('dbo');
/** /**
* Pear::DB layer for DBO. * Pear::DB layer for DBO.
* *
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
*
*/ */
class DBO_Pear extends DBO { class DBO_Pear extends DBO {
@ -54,6 +53,7 @@ class DBO_Pear extends DBO {
* Connects to the database using options in the given configuration array. * Connects to the database using options in the given configuration array.
* *
* @param array $config Configuration array for connecting * @param array $config Configuration array for connecting
* @return unknown
*/ */
function connect ($config) { function connect ($config) {
die('Please implement DBO::connect() first.'); die('Please implement DBO::connect() first.');
@ -93,7 +93,7 @@ class DBO_Pear extends DBO {
* *
* @return array Array of tablenames in the database * @return array Array of tablenames in the database
*/ */
function tables () { // POSTGRESQL ONLY! PEAR:DB DOESN'T SUPPORT LISTING TABLES function tablesList () { // POSTGRESQL ONLY! PEAR:DB DOESN'T SUPPORT LISTING TABLES
$sql = "SELECT a.relname AS name $sql = "SELECT a.relname AS name
FROM pg_class a, pg_user b FROM pg_class a, pg_user b
WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_' WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'
@ -144,8 +144,10 @@ class DBO_Pear extends DBO {
* *
* @return string Error message * @return string Error message
*/ */
function lastError () { function lastError ($result=null) {
return PEAR::isError($this->_result)? $this->_result->getMessage(): null; if (!$result) $result = $this->_result;
return PEAR::isError($result)? $result->getMessage(): null;
} }
/** /**

View file

@ -31,7 +31,6 @@
/** /**
* Include DBO. * Include DBO.
*
*/ */
uses('dbo'); uses('dbo');
@ -41,7 +40,6 @@ uses('dbo');
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.114 * @since Cake v 1.0.0.114
*
*/ */
class DBO_Postgres extends DBO { class DBO_Postgres extends DBO {
@ -49,6 +47,7 @@ class DBO_Postgres extends DBO {
* Connects to the database using options in the given configuration array. * Connects to the database using options in the given configuration array.
* *
* @param array $config Configuration array for connecting * @param array $config Configuration array for connecting
* @return True if successfully connected.
*/ */
function connect ($config) { function connect ($config) {
if($config) { if($config) {
@ -98,7 +97,7 @@ class DBO_Postgres extends DBO {
* *
* @return array Array of tablenames in the database * @return array Array of tablenames in the database
*/ */
function tables () { function tablesList () {
$sql = "SELECT a.relname AS name $sql = "SELECT a.relname AS name
FROM pg_class a, pg_user b FROM pg_class a, pg_user b
WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_' WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'

View file

@ -99,7 +99,7 @@ class DBO_SQLite extends DBO {
* *
* @return array Array of tablenames in the database * @return array Array of tablenames in the database
*/ */
function tables () { function tablesList () {
$result = sqlite_query($this->_conn, "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"); $result = sqlite_query($this->_conn, "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
$this->_conn $this->_conn
if (!$result) { if (!$result) {

View file

@ -40,13 +40,12 @@ uses('error_messages', 'object', 'router', 'controller');
/** /**
* Dispatches the request, creating appropriate models and controllers. * Dispatches the request, creating appropriate models and controllers.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
*
*/ */
class Dispatcher extends Object { class Dispatcher extends Object {
/** /**
* Base URL * Base URL
* *
@ -75,7 +74,8 @@ class Dispatcher extends Object {
* @param string $url * @param string $url
* @return unknown * @return unknown
*/ */
function dispatch ($url) { function dispatch ($url)
{
global $_POST, $_GET, $_FILES, $_SESSION; global $_POST, $_GET, $_FILES, $_SESSION;
/* @var $params array */ /* @var $params array */
@ -141,12 +141,13 @@ class Dispatcher extends Object {
* @param string $from_url * @param string $from_url
* @return array Parameters found in POST and GET. * @return array Parameters found in POST and GET.
*/ */
function parseParams ($from_url) { function parseParams ($from_url)
{
global $_POST, $_FILES; global $_POST, $_FILES;
// load routes config // load routes config
$Route = new Router(); $Route = new Router();
require CONFIGS.'routes.php'; include CONFIGS.'routes.php';
$params = $Route->parse ($from_url); $params = $Route->parse ($from_url);
// add submitted form data // add submitted form data

View file

@ -31,97 +31,81 @@
/** /**
* Error string for when the specified database driver can not be found. * Error string for when the specified database driver can not be found.
*
*/ */
define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found'); define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found');
/** /**
* Error string for when the dispatcher can not find a default controller. * Error string for when the dispatcher can not find a default controller.
*
*/ */
define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config'); define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config');
/** /**
* Error string for when the dispatcher can not find a default action. * Error string for when the dispatcher can not find a default action.
*
*/ */
define ('ERROR_NO_ACTION_SET', '[Dispatcher] No default action, can\'t continue, check routes config'); define ('ERROR_NO_ACTION_SET', '[Dispatcher] No default action, can\'t continue, check routes config');
/** /**
* Error string for when the dispatcher can not find given controller. * Error string for when the dispatcher can not find given controller.
*
*/ */
define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first'); define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first');
/** /**
* Error string for when the dispatcher can not find expected action in controller. * Error string for when the dispatcher can not find expected action in controller.
*
*/ */
define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first'); define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first');
/** /**
* Error string for errors in view. * Error string for errors in view.
*
*/ */
define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got: <blockquote>%s</blockquote>'); define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got: <blockquote>%s</blockquote>');
/** /**
* Error string for when the controller can not find expected view. * Error string for when the controller can not find expected view.
*
*/ */
define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first'); define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first');
/** /**
* Error string for errors in layout. * Error string for errors in layout.
*
*/ */
define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got: <blockquote>"%s"</blockquote>'); define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got: <blockquote>"%s"</blockquote>');
/** /**
* Error string for when the controller can not find expected layout. * Error string for when the controller can not find expected layout.
*
*/ */
define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first'); define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first');
/** /**
* Error string for database not being able to access the table list. * Error string for database not being able to access the table list.
*
*/ */
define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config'); define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config');
/** /**
* Error string for No corresponding database table found for model. * Error string for no corresponding database table found for model.
*
*/ */
define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first'); define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first');
/** /**
* Error string for Field not present in table. * Error string for Field not present in table.
*
*/ */
define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema'); define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema');
/** /**
* Error string short short error message. * Error string short short error message.
*
*/ */
define ('SHORT_ERROR_MESSAGE', '<div class="error_message"><i>%s</i></div>'); define ('SHORT_ERROR_MESSAGE', '<div class="error_message"><i>%s</i></div>');
/** /**
* Error string for when original image can not be loaded. * Error string for when original image can not be loaded.
*
*/ */
define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couldn\'t load original image %s (tried from "%s")'); define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couldn\'t load original image %s (tried from "%s")');
/** /**
* Error string for error 404. * Error string for error 404.
*
*/ */
define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message
/** /**
* Error string for error 500. * Error string for error 500.
*
*/ */
define ('ERROR_500', "Application error, sorry."); define ('ERROR_500', "Application error, sorry.");

View file

@ -16,8 +16,6 @@
/** /**
* Purpose: Flay * Purpose: Flay
* Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax. * Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax.
* See Flay::test() for examples.
* Test with $flay = new Flay(); $flay->test();
* *
* @filesource * @filesource
* @author Cake Authors/Developers * @author Cake Authors/Developers
@ -34,20 +32,19 @@
/** /**
* Enter description here... * Enter description here...
*
*/ */
uses('object'); uses('object');
/** /**
* Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax. * Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
*
*/ */
class Flay extends Object {
class Flay extends Object
{
/** /**
* Enter description here... * Enter description here...
* *
@ -146,13 +143,17 @@ class Flay extends Object {
if (!$bare) { if (!$bare) {
// guess links // guess links
$urls = null; $urls = null;
if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) { if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls))
foreach ($urls[1] as $url) { {
foreach ($urls[1] as $url)
{
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line); $line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
} }
} }
if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) { if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls))
foreach ($urls[1] as $url) { {
foreach ($urls[1] as $url)
{
$line = str_replace($url, "<a href=\"http://{$url}\">{$url}</a>", $line); $line = str_replace($url, "<a href=\"http://{$url}\">{$url}</a>", $line);
} }
} }

View file

@ -30,16 +30,9 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
/**
* Enter description here...
*
*/
uses('object');
/** /**
* Folder structure browser, lists folders and files. * Folder structure browser, lists folders and files.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9

View file

@ -32,11 +32,6 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
/**
* Enter description here...
*/
uses('object');
/** /**
* This is a port of Ruby on Rails' Inflector class. * This is a port of Ruby on Rails' Inflector class.
* Inflector pluralizes and singularizes English nouns. * Inflector pluralizes and singularizes English nouns.
@ -46,7 +41,8 @@ uses('object');
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
*/ */
class Inflector extends Object { class Inflector extends Object
{
/** /**
* Constructor. * Constructor.
@ -168,8 +164,9 @@ class Inflector extends Object {
* @param string $table_name Name of database table to get class name for * @param string $table_name Name of database table to get class name for
* @return string * @return string
*/ */
function classify($table_name) { function classify($table_name)
return $this->camelize($this->singularize($table_name)); {
return Inflector::camelize(Inflector::singularize($table_name));
} }
/** /**
@ -179,8 +176,48 @@ class Inflector extends Object {
* @param string $class_name * @param string $class_name
* @return string * @return string
*/ */
function foreignKey($class_name) { function foreignKey($class_name)
return $this->underscore($class_name) . "_id"; {
return Inflector::underscore($class_name) . "_id";
}
function toControllerFilename($name)
{
return CONTROLLERS.Inflector::underscore($name).'.php';
}
function toHelperFilename($name)
{
return HELPERS.Inflector::underscore($name).'.php';
}
function toFullName($name, $correct)
{
if (strstr($name, '_') && (strtolower($name) == $name))
{
return Inflector::camelize($name);
}
if (preg_match("/^(.*)({$correct})$/i", $name, $reg))
{
if ($reg[2] == $correct)
{
return $name;
}
else
{
return ucfirst($reg[1].$correct);
}
}
else
{
return ucfirst($name.$correct);
}
}
function toLibraryFilename ($name)
{
return LIBS.Inflector::underscore($name).'.php';
} }
} }

View file

@ -39,7 +39,6 @@
/** /**
* Enter description here... * Enter description here...
*
*/ */
uses('object', 'validators', 'inflector'); uses('object', 'validators', 'inflector');
@ -50,13 +49,13 @@ uses('object', 'validators', 'inflector');
* The table is required to have at least 'id auto_increment', 'created datetime', * The table is required to have at least 'id auto_increment', 'created datetime',
* and 'modified datetime' fields. * and 'modified datetime' fields.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
* *
*/ */
class Model extends Object { class Model extends Object
{
/** /**
* Enter description here... * Enter description here...
@ -153,17 +152,11 @@ class Model extends Object {
* @param string $table Database table to use. * @param string $table Database table to use.
* @param unknown_type $db Database connection object. * @param unknown_type $db Database connection object.
*/ */
function __construct ($id=false, $table=null, $db=null) { function __construct ($id=false, $table=null, $db=null)
{
global $DB; global $DB;
if ($db) $this->db = $db? $db: $DB;
{
$this->db = $db;
}
else
{
$this->db = &$DB;
}
if ($id) if ($id)
$this->id = $id; $this->id = $id;
@ -178,13 +171,14 @@ class Model extends Object {
* Creates has-many relationships, and then call relink. * Creates has-many relationships, and then call relink.
* *
* @see relink() * @see relink()
*
*/ */
function createLinks () { function createLinks ()
{
if (!empty($this->hasMany)) if (!empty($this->hasMany))
$this->_hasMany = explode(',', $this->hasMany); $this->_hasMany = explode(',', $this->hasMany);
foreach ($this->_hasMany as $model_name) { foreach ($this->_hasMany as $model_name)
{
// todo fix strip the model name // todo fix strip the model name
$model_name = Inflector::singularize($model_name); $model_name = Inflector::singularize($model_name);
$this->$model_name = new $model_name(); $this->$model_name = new $model_name();
@ -197,10 +191,11 @@ class Model extends Object {
* Updates this model's many-to-one links, by emptying the links list, and then linkManyToOne again. * Updates this model's many-to-one links, by emptying the links list, and then linkManyToOne again.
* *
* @see linkManyToOne() * @see linkManyToOne()
*
*/ */
function relink () { function relink ()
foreach ($this->_hasMany as $model) { {
foreach ($this->_hasMany as $model)
{
$name = Inflector::singularize($model); $name = Inflector::singularize($model);
$this->$name->clearLinks(); $this->$name->clearLinks();
$this->$name->linkManyToOne(get_class($this), $this->id); $this->$name->linkManyToOne(get_class($this), $this->id);
@ -215,7 +210,8 @@ class Model extends Object {
* @param string $model_name Name of model to link to * @param string $model_name Name of model to link to
* @param unknown_type $value Defaults to NULL. * @param unknown_type $value Defaults to NULL.
*/ */
function linkManyToOne ($model_name, $value=null) { function linkManyToOne ($model_name, $value=null)
{
$table_name = Inflector::tableize($model_name); $table_name = Inflector::tableize($model_name);
$field_name = Inflector::singularize($table_name).'_id'; $field_name = Inflector::singularize($table_name).'_id';
$this->_one_to_many[] = array($table_name, $field_name, $value); $this->_one_to_many[] = array($table_name, $field_name, $value);
@ -225,7 +221,8 @@ class Model extends Object {
* Removes all one-to-many links to other Models. * Removes all one-to-many links to other Models.
* *
*/ */
function clearLinks () { function clearLinks ()
{
$this->_one_to_many = array(); $this->_one_to_many = array();
} }
@ -234,12 +231,15 @@ class Model extends Object {
* *
* @param string $table_name Name of the custom table * @param string $table_name Name of the custom table
*/ */
function useTable ($table_name) { function useTable ($table_name)
if (!in_array($table_name, $this->db->tables())) { {
if (!in_array(strtolower($table_name), $this->db->tables()))
{
trigger_error (sprintf(ERROR_NO_MODEL_TABLE, get_class($this), $table_name), E_USER_ERROR); trigger_error (sprintf(ERROR_NO_MODEL_TABLE, get_class($this), $table_name), E_USER_ERROR);
die(); die();
} }
else { else
{
$this->table = $table_name; $this->table = $table_name;
$this->loadInfo(); $this->loadInfo();
} }
@ -258,11 +258,13 @@ class Model extends Object {
* @param string $two Value string for the alternative indata method * @param string $two Value string for the alternative indata method
* @return unknown * @return unknown
*/ */
function set ($one, $two=null) { function set ($one, $two=null)
{
$this->validationErrors = null; $this->validationErrors = null;
$data = is_array($one)? $one: array($one=>$two); $data = is_array($one)? $one: array($one=>$two);
foreach ($data as $n => $v) { foreach ($data as $n => $v)
{
/* /*
if (!$this->hasField($n)) { if (!$this->hasField($n)) {
DEBUG? DEBUG?
@ -281,7 +283,8 @@ class Model extends Object {
* *
* @param int $id Id * @param int $id Id
*/ */
function setId ($id) { function setId ($id)
{
$this->id = $id; $this->id = $id;
$this->relink(); $this->relink();
} }
@ -291,7 +294,8 @@ class Model extends Object {
* *
* @return array Array of table metadata * @return array Array of table metadata
*/ */
function loadInfo () { function loadInfo ()
{
if (empty($this->_table_info)) if (empty($this->_table_info))
$this->_table_info = new NeatArray($this->db->fields($this->table)); $this->_table_info = new NeatArray($this->db->fields($this->table));
return $this->_table_info; return $this->_table_info;
@ -304,7 +308,8 @@ class Model extends Object {
* @param string $name Name of table to look in * @param string $name Name of table to look in
* @return boolean * @return boolean
*/ */
function hasField ($name) { function hasField ($name)
{
if (empty($this->_table_info)) $this->loadInfo(); if (empty($this->_table_info)) $this->loadInfo();
return $this->_table_info->findIn('name', $name); return $this->_table_info->findIn('name', $name);
} }
@ -315,7 +320,8 @@ class Model extends Object {
* @param mixed $fields String of single fieldname, or an array of fieldnames. * @param mixed $fields String of single fieldname, or an array of fieldnames.
* @return array Array of database fields * @return array Array of database fields
*/ */
function read ($fields=null) { function read ($fields=null)
{
$this->validationErrors = null; $this->validationErrors = null;
return $this->id? $this->find("id = '{$this->id}'", $fields): false; return $this->id? $this->find("id = '{$this->id}'", $fields): false;
} }
@ -327,18 +333,25 @@ class Model extends Object {
* @param string $conditions SQL conditions (defaults to NULL) * @param string $conditions SQL conditions (defaults to NULL)
* @return field contents * @return field contents
*/ */
function field ($name, $conditions=null) { function field ($name, $conditions=null)
if ($conditions) { {
if ($conditions)
{
$data = $this->find($conditions); $data = $this->find($conditions);
return $data[$name]; return $data[$name];
} }
if (isset($this->data[$name])) elseif (isset($this->data[$name]))
{
return $this->data[$name]; return $this->data[$name];
else { }
if ($this->id && $data = $this->read($name)) { else
{
if ($this->id && $data = $this->read($name))
{
return isset($data[$name])? $data[$name]: false; return isset($data[$name])? $data[$name]: false;
} }
else { else
{
return false; return false;
} }
} }
@ -351,7 +364,8 @@ class Model extends Object {
* @param mixed $value Value of the field * @param mixed $value Value of the field
* @return boolean True on success save * @return boolean True on success save
*/ */
function saveField($name, $value) { function saveField($name, $value)
{
return $this->save(array($name=>$value), false); return $this->save(array($name=>$value), false);
} }
@ -362,57 +376,75 @@ class Model extends Object {
* @param boolean $validate * @param boolean $validate
* @return boolean success * @return boolean success
*/ */
function save ($data=null, $validate=true) { function save ($data=null, $validate=true)
{
if ($data) $this->set($data); if ($data) $this->set($data);
if ($validate && !$this->validates()) if ($validate && !$this->validates())
return false; return false;
$fields = $values = array(); $fields = $values = array();
foreach ($this->data as $n=>$v) { foreach ($this->data as $n=>$v)
if ($this->hasField($n)) { {
if ($this->hasField($n))
{
$fields[] = $n; $fields[] = $n;
$values[] = $this->db->prepare($v); $values[] = $this->db->prepare($v);
} }
} }
if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields)) { if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields))
{
$fields[] = 'created'; $fields[] = 'created';
$values[] = date("'Y-m-d H:i:s'"); $values[] = date("'Y-m-d H:i:s'");
} }
if ($this->hasField('modified') && !in_array('modified', $fields)) { if ($this->hasField('modified') && !in_array('modified', $fields))
{
$fields[] = 'modified'; $fields[] = 'modified';
$values[] = 'NOW()'; $values[] = 'NOW()';
} }
if(count($fields)){ if(count($fields))
{
if($this->id){ if($this->id){
$sql = array(); $sql = array();
foreach (array_combine($fields, $values) as $field=>$value) { foreach (array_combine($fields, $values) as $field=>$value)
{
$sql[] = $field.'='.$value; $sql[] = $field.'='.$value;
} }
if($this->db->query("UPDATE {$this->table} SET ".join(',', $sql)." WHERE id = '{$this->id}'") && $this->db->lastAffected()){
$sql = "UPDATE {$this->table} SET ".join(',', $sql)." WHERE id = '{$this->id}'";
if ($this->db->query($sql) && $this->db->lastAffected())
{
$this->data = false; $this->data = false;
return true; return true;
} }
else { else
{
return $this->db->hasAny($this->table, "id = '{$this->id}'"); return $this->db->hasAny($this->table, "id = '{$this->id}'");
} }
} }
else { else
{
$fields = join(',', $fields); $fields = join(',', $fields);
$values = join(',', $values); $values = join(',', $values);
if($this->db->query("INSERT INTO {$this->table} ({$fields}) VALUES ({$values})")) { $sql = "INSERT INTO {$this->table} ({$fields}) VALUES ({$values})";
if($this->db->query($sql))
{
$this->id = $this->db->lastInsertId($this->table, 'id'); $this->id = $this->db->lastInsertId($this->table, 'id');
return true; return true;
} }
else { else
{
return false; return false;
} }
} }
} }
else { else
{
return false; return false;
} }
@ -425,7 +457,8 @@ class Model extends Object {
* @see function del * @see function del
* @return boolean True on success * @return boolean True on success
*/ */
function remove ($id=null) { function remove ($id=null)
{
return $this->del($id); return $this->del($id);
} }
@ -435,9 +468,11 @@ class Model extends Object {
* @param mixed $id Id of database record to delete * @param mixed $id Id of database record to delete
* @return boolean True on success * @return boolean True on success
*/ */
function del ($id=null) { function del ($id=null)
{
if ($id) $this->id = $id; if ($id) $this->id = $id;
if ($this->id && $this->db->query("DELETE FROM {$this->table} WHERE id = '{$this->id}'")) { if ($this->id && $this->db->query("DELETE FROM {$this->table} WHERE id = '{$this->id}'"))
{
$this->id = false; $this->id = false;
return true; return true;
} }
@ -450,7 +485,8 @@ class Model extends Object {
* *
* @return boolean True if such a record exists * @return boolean True if such a record exists
*/ */
function exists () { function exists ()
{
return $this->id? $this->db->hasAny($this->table, "id = '{$this->id}'"): false; return $this->id? $this->db->hasAny($this->table, "id = '{$this->id}'"): false;
} }
@ -460,7 +496,8 @@ class Model extends Object {
* *
* @return boolean True if such a record exists * @return boolean True if such a record exists
*/ */
function hasAny ($sql_conditions = null) { function hasAny ($sql_conditions = null)
{
return $this->db->hasAny($this->table, $sql_conditions); return $this->db->hasAny($this->table, $sql_conditions);
} }
@ -472,7 +509,8 @@ class Model extends Object {
* @param mixed $fields Either a single string of a field name, or an array of field names * @param mixed $fields Either a single string of a field name, or an array of field names
* @return array Array of records * @return array Array of records
*/ */
function find ($conditions = null, $fields = null) { function find ($conditions = null, $fields = null)
{
$data = $this->findAll($conditions, $fields, null, 1); $data = $this->findAll($conditions, $fields, null, 1);
return empty($data[0])? false: $data[0]; return empty($data[0])? false: $data[0];
} }
@ -481,18 +519,23 @@ class Model extends Object {
* @return string * @return string
* *
*/ */
function parseConditions ($conditions) { function parseConditions ($conditions)
if (is_string($conditions)) { {
if (is_string($conditions))
{
return $conditions; return $conditions;
} }
elseif (is_array($conditions)) { elseif (is_array($conditions))
{
$out = array(); $out = array();
foreach ($conditions as $key=>$value) { foreach ($conditions as $key=>$value)
{
$out[] = "{$key}=".($value===null? 'null': $this->db->prepare($value)); $out[] = "{$key}=".($value===null? 'null': $this->db->prepare($value));
} }
return join(' and ', $out); return join(' and ', $out);
} }
else { else
{
return null; return null;
} }
} }
@ -507,7 +550,8 @@ class Model extends Object {
* @param int $page Page number * @param int $page Page number
* @return array Array of records * @return array Array of records
*/ */
function findAll ($conditions = null, $fields = null, $order = null, $limit=50, $page=1) { function findAll ($conditions = null, $fields = null, $order = null, $limit=50, $page=1)
{
$conditions = $this->parseConditions($conditions); $conditions = $this->parseConditions($conditions);
@ -520,7 +564,8 @@ class Model extends Object {
$joins = $whers = array(); $joins = $whers = array();
foreach ($this->_oneToMany as $rule) { foreach ($this->_oneToMany as $rule)
{
list($table, $field, $value) = $rule; list($table, $field, $value) = $rule;
$joins[] = "LEFT JOIN {$table} ON {$this->table}.{$field} = {$table}.id"; $joins[] = "LEFT JOIN {$table} ON {$this->table}.{$field} = {$table}.id";
$whers[] = "{$this->table}.{$field} = '{$value}'"; $whers[] = "{$this->table}.{$field} = '{$value}'";
@ -551,7 +596,8 @@ class Model extends Object {
* @param string $sql SQL query * @param string $sql SQL query
* @return array * @return array
*/ */
function findBySql ($sql) { function findBySql ($sql)
{
return $this->db->all($sql); return $this->db->all($sql);
} }
@ -561,7 +607,8 @@ class Model extends Object {
* @param string $conditions SQL conditions (WHERE clause conditions) * @param string $conditions SQL conditions (WHERE clause conditions)
* @return int Number of matching rows * @return int Number of matching rows
*/ */
function findCount ($conditions) { function findCount ($conditions)
{
list($data) = $this->findAll($conditions, 'COUNT(id) AS count'); list($data) = $this->findAll($conditions, 'COUNT(id) AS count');
return $data['count']; return $data['count'];
} }
@ -573,7 +620,8 @@ class Model extends Object {
* @param unknown_type $fields * @param unknown_type $fields
* @return unknown * @return unknown
*/ */
function findAllThreaded ($conditions=null, $fields=null, $sort=null) { function findAllThreaded ($conditions=null, $fields=null, $sort=null)
{
return $this->_doThread($this->findAll($conditions, $fields, $sort), null); return $this->_doThread($this->findAll($conditions, $fields, $sort), null);
} }
@ -584,11 +632,14 @@ class Model extends Object {
* @param unknown_type $root NULL or id for root node of operation * @param unknown_type $root NULL or id for root node of operation
* @return array * @return array
*/ */
function _doThread ($data, $root) { function _doThread ($data, $root)
{
$out = array(); $out = array();
for ($ii=0; $ii<sizeof($data); $ii++) { for ($ii=0; $ii<sizeof($data); $ii++)
if ($data[$ii]['parent_id'] == $root) { {
if ($data[$ii]['parent_id'] == $root)
{
$tmp = $data[$ii]; $tmp = $data[$ii];
$tmp['children'] = isset($data[$ii]['id'])? $this->_doThread($data, $data[$ii]['id']): null; $tmp['children'] = isset($data[$ii]['id'])? $this->_doThread($data, $data[$ii]['id']): null;
$out[] = $tmp; $out[] = $tmp;
@ -607,7 +658,8 @@ class Model extends Object {
* @param unknown_type $value * @param unknown_type $value
* @return array Array with keys "prev" and "next" that holds the id's * @return array Array with keys "prev" and "next" that holds the id's
*/ */
function findNeighbours ($conditions, $field, $value) { function findNeighbours ($conditions, $field, $value)
{
list($prev) = $this->findAll($conditions." AND {$field} < '{$value}'", $field, "{$field} DESC", 1); list($prev) = $this->findAll($conditions." AND {$field} < '{$value}'", $field, "{$field} DESC", 1);
list($next) = $this->findAll($conditions." AND {$field} > '{$value}'", $field, "{$field} ASC", 1); list($next) = $this->findAll($conditions." AND {$field} > '{$value}'", $field, "{$field} ASC", 1);
@ -620,7 +672,8 @@ class Model extends Object {
* @param string $sql SQL statement * @param string $sql SQL statement
* @return array Resultset * @return array Resultset
*/ */
function query ($sql) { function query ($sql)
{
return $this->db->query($sql); return $this->db->query($sql);
} }
@ -630,7 +683,8 @@ class Model extends Object {
* @param array $data POST data * @param array $data POST data
* @return boolean True if there are no errors * @return boolean True if there are no errors
*/ */
function validates ($data=null) { function validates ($data=null)
{
$errors = count($this->invalidFields($data? $data: $this->data)); $errors = count($this->invalidFields($data? $data: $this->data));
return $errors == 0; return $errors == 0;
@ -642,7 +696,8 @@ class Model extends Object {
* @param array $data Posted data * @param array $data Posted data
* @return array Array of invalid fields * @return array Array of invalid fields
*/ */
function invalidFields ($data=null) { function invalidFields ($data=null)
{
return $this->_invalidFields($data); return $this->_invalidFields($data);
} }
@ -652,7 +707,8 @@ class Model extends Object {
* @param array $data * @param array $data
* @return array Array of invalid fields * @return array Array of invalid fields
*/ */
function _invalidFields ($data=null) { function _invalidFields ($data=null)
{
if (!isset($this->validate)) if (!isset($this->validate))
return true; return true;
@ -662,7 +718,8 @@ class Model extends Object {
$data = ($data? $data: (isset($this->data)? $this->data: array())); $data = ($data? $data: (isset($this->data)? $this->data: array()));
$errors = array(); $errors = array();
foreach ($this->validate as $field_name=>$validator) { foreach ($this->validate as $field_name=>$validator)
{
if (!isset($data[$field_name]) || !preg_match($validator, $data[$field_name])) if (!isset($data[$field_name]) || !preg_match($validator, $data[$field_name]))
$errors[$field_name] = 1; $errors[$field_name] = 1;
} }

View file

@ -30,8 +30,6 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
uses('log');
/** /**
* Enter description here... * Enter description here...
* *
@ -39,7 +37,8 @@ uses('log');
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
*/ */
class Object { class Object
{
/** /**
* A hack to support __construct() on PHP 4 * A hack to support __construct() on PHP 4

View file

@ -30,16 +30,11 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
/**
* Enter description here...
*
*/
uses('object'); uses('object');
/** /**
* Parses the request URL into controller, action, and parameters. * Parses the request URL into controller, action, and parameters.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
@ -54,14 +49,6 @@ class Router extends Object {
*/ */
var $routes = array(); var $routes = array();
/**
* Constructor.
*
*/
function __construct () {
parent::__construct();
}
/** /**
* TODO: Better description. Returns this object's routes array. Returns false if there are no routes available. * TODO: Better description. Returns this object's routes array. Returns false if there are no routes available.
* *
@ -178,6 +165,7 @@ class Router extends Object {
break; break;
} }
} }
return $out; return $out;
} }
} }

View file

@ -39,8 +39,6 @@ uses('object');
/** /**
* Templating for Controller class. Takes care of rendering views. * Templating for Controller class. Takes care of rendering views.
* *
*
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
@ -97,27 +95,19 @@ class Template extends Object {
var $_page_title = false; var $_page_title = false;
/** /**
* Constructor. * Choose the layout to be used when rendering.
* *
*/ * @param string $layout
function __construct () {
parent::__construct();
}
/**
* Enter description here...
*
* @param unknown_type $layout
*/ */
function setLayout ($layout) { function setLayout ($layout) {
$this->layout = $layout; $this->layout = $layout;
} }
/** /**
* Enter description here... * Saves a variable to use inside a template.
* *
* @param mixed $one An array of POST data. (Or: a string of a single POST datum.) * @param mixed $one A string or an array of data.
* @param string $two Value in case $one is a string (which then works as the key). * @param string $two Value in case $one is a string (which then works as the key), otherwise unused.
* @return unknown * @return unknown
*/ */
function set($one, $two=null) { function set($one, $two=null) {
@ -275,7 +265,8 @@ class Template extends Object {
* @param boolean $___play_safe If set to false, the include() of the $__view_fn is done without suppressing output of errors * @param boolean $___play_safe If set to false, the include() of the $__view_fn is done without suppressing output of errors
* @return string Rendered output * @return string Rendered output
*/ */
function _render($___view_fn, $___data_for_view, $___play_safe = true) { function _render($___view_fn, $___data_for_view, $___play_safe = true)
{
extract($___data_for_view, EXTR_SKIP); # load all view variables extract($___data_for_view, EXTR_SKIP); # load all view variables
$BASE = $this->base; $BASE = $this->base;
$params = &$this->params; $params = &$this->params;

View file

@ -76,7 +76,6 @@ if (phpversion() >= '4') {
/** /**
* Exception class for testing * Exception class for testing
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.0 * @since Cake v 1.0.0.0
@ -128,7 +127,6 @@ class TestException {
/** /**
* Asserts for Unit Testing * Asserts for Unit Testing
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.0 * @since Cake v 1.0.0.0
@ -589,7 +587,6 @@ class TestCase extends Assert /* implements Test */ {
/** /**
* Test Suite for Unit Testing. * Test Suite for Unit Testing.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.0 * @since Cake v 1.0.0.0
@ -724,7 +721,6 @@ class TestSuite /* implements Test */ {
/** /**
* Test Failure for Unit Testing * Test Failure for Unit Testing
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.0 * @since Cake v 1.0.0.0
@ -790,7 +786,6 @@ class TestFailure {
/** /**
* Test Result for Unit Testing * Test Result for Unit Testing
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.0 * @since Cake v 1.0.0.0
@ -961,7 +956,6 @@ class TestResult {
/** /**
* Mines data from test results. Used for Unit Testing. * Mines data from test results. Used for Unit Testing.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.0 * @since Cake v 1.0.0.0
@ -1038,7 +1032,6 @@ class ResultDataMiner extends TestResult {
/** /**
* Test Runner for Unit Testing. * Test Runner for Unit Testing.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 1.0.0.0 * @since Cake v 1.0.0.0

View file

@ -30,16 +30,11 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
/**
* Enter description here...
*
*/
uses ('object'); uses ('object');
/** /**
* Time related functions, formatting for dates etc. * Time related functions, formatting for dates etc.
* *
*
* @package cake * @package cake
* @subpackage cake.libs * @subpackage cake.libs
* @since Cake v 0.2.9 * @since Cake v 0.2.9
@ -112,7 +107,7 @@ class Time extends Object {
} }
/** /**
* Returns a Unix timestamp for a datetime string. Wrapper for PHP function strtotime(). * Returns a Unix timestamp from a textual datetime description. Wrapper for PHP function strtotime().
* *
* @param string $date_string Datetime string to be represented as a Unix timestamp * @param string $date_string Datetime string to be represented as a Unix timestamp
* @return int Unix timestamp * @return int Unix timestamp
@ -127,8 +122,18 @@ class Time extends Object {
* @param string $date Datetime string * @param string $date Datetime string
* @return string Formatted date string * @return string Formatted date string
*/ */
function toRss ($date) { function toAtom ($date) {
return date('Y-m-d', $date).'T'.date('H:i:s', $date).'Z'; return date('Y-m-d\TH:i:s\Z', $date);
}
/**
* Formats date for RSS feeds
*
* @param datetime $date Datetime string
* @return string Formatted date string
*/
function toRSS ($date) {
return date('D, d M Y H:i:s O', $date);
} }
/** /**
@ -149,8 +154,8 @@ class Time extends Object {
* @return string Relative time string. * @return string Relative time string.
*/ */
function timeAgoInWords ($datetime) { function timeAgoInWords ($datetime)
{
$in_seconds=strtotime($datetime); $in_seconds=strtotime($datetime);
$diff = time()-$in_seconds; $diff = time()-$in_seconds;
$months = floor($diff/2419200); $months = floor($diff/2419200);

View file

@ -32,19 +32,16 @@
/** /**
* Not empty. * Not empty.
*
*/ */
define('VALID_NOT_EMPTY', '/.+/'); define('VALID_NOT_EMPTY', '/.+/');
/** /**
* Numbers [0-9] only. * Numbers [0-9] only.
*
*/ */
define('VALID_NUMBER', '/^[0-9]+$/'); define('VALID_NUMBER', '/^[0-9]+$/');
/** /**
* A valid email address. * A valid email address.
*
*/ */
define('VALID_EMAIL', '/^([a-z0-9][a-z0-9_\-\.\+]*)@([a-z0-9][a-z0-9\.\-]{0,63}\.[a-z]{2,3})$/i'); define('VALID_EMAIL', '/^([a-z0-9][a-z0-9_\-\.\+]*)@([a-z0-9][a-z0-9\.\-]{0,63}\.[a-z]{2,3})$/i');

View file

@ -42,17 +42,23 @@ if (!defined('ROOT'))
define ('ROOT', dirname(dirname(__FILE__)).DS); define ('ROOT', dirname(dirname(__FILE__)).DS);
/** /**
* Directory layout and basic functions * Configuration, directory layout and standard libraries
*/ */
require (ROOT.'config/core.php'); require (ROOT.'config/core.php');
require (ROOT.'config/paths.php'); require (ROOT.'config/paths.php');
require (ROOT.'libs/log.php');
require (ROOT.'libs/object.php');
require (ROOT.'libs/neat_array.php');
require (ROOT.'libs/inflector.php');
require (ROOT.'libs/basics.php'); require (ROOT.'libs/basics.php');
require (ROOT.'libs/folder.php');
DEBUG? error_reporting(E_ALL): error_reporting(0); DEBUG? error_reporting(E_ALL): error_reporting(0);
$TIME_START = getMicrotime(); $TIME_START = getMicrotime();
uses ('folder', 'dispatcher', 'dbo_factory'); uses ('dispatcher', 'dbo_factory');
config ('tags', 'database'); config ('tags', 'database');
$DB = DboFactory::make('devel'); $DB = DboFactory::make('devel');