Code formatting.

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1010 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
brego 2005-09-29 18:19:30 +00:00
parent b59672754b
commit a00a927cca
2 changed files with 206 additions and 184 deletions

View file

@ -565,7 +565,5 @@ class %sTest extends TestCase
return false; return false;
} }
} }
} }
?> ?>

View file

@ -34,13 +34,13 @@
/** /**
* Basic defines for timing functions. * Basic defines for timing functions.
*/ */
define('SECOND', 1); define('SECOND', 1);
define('MINUTE', 60 * SECOND); define('MINUTE', 60 * SECOND);
define('HOUR', 60 * MINUTE); define('HOUR', 60 * MINUTE);
define('DAY', 24 * HOUR); define('DAY', 24 * HOUR);
define('WEEK', 7 * DAY); define('WEEK', 7 * DAY);
define('MONTH', 30 * DAY); define('MONTH', 30 * DAY);
define('YEAR', 365 * DAY); define('YEAR', 365 * DAY);
/** /**
* Loads all models. * Loads all models.
@ -49,13 +49,13 @@ define('YEAR', 365 * DAY);
* @uses APP * @uses APP
* @uses MODELS * @uses MODELS
*/ */
function loadModels () function loadModels()
{ {
require (APP.'app_model.php'); require APP.'app_model.php';
foreach (listClasses(MODELS) as $model_fn) foreach (listClasses(MODELS) as $model_fn)
{ {
require_once (MODELS.$model_fn); require_once MODELS.$model_fn;
} }
} }
/** /**
@ -66,50 +66,59 @@ function loadModels ()
* @uses HELPERS * @uses HELPERS
* @uses CONTROLLERS * @uses CONTROLLERS
*/ */
function loadControllers () function loadControllers()
{ {
require (APP.'app_controller.php'); require APP.'app_controller.php';
foreach (listClasses(HELPERS) as $helper) foreach (listClasses(HELPERS) as $helper)
{ {
require_once (HELPERS.$helper.'.php'); require_once HELPERS.$helper.'.php';
} }
foreach (listClasses(CONTROLLERS) as $controller) foreach (listClasses(CONTROLLERS) as $controller)
{ {
require_once (CONTROLLERS.$controller.'.php'); require_once CONTROLLERS.$controller.'.php';
} }
} }
/** /**
* Loads a controller and its helper libraries. * Loads a controller and its helper libraries.
* *
* @param string $name Name of controller * @param string $name Name of controller
* @return boolean Success * @return boolean Success
*/ */
function loadController ($name) function loadController($name)
{ {
$controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php'; $controllerFn = CONTROLLERS.Inflector::underscore($name).'_controller.php';
$helper_fn = HELPERS.Inflector::underscore($name).'_helper.php'; $helperFn = HELPERS.Inflector::underscore($name).'_helper.php';
require_once(APP.'app_controller.php'); require_once(APP.'app_controller.php');
if (file_exists($helper_fn)) if (file_exists($helperFn))
require_once($helper_fn); {
require_once $helperFn;
}
return file_exists($controller_fn)? require_once($controller_fn): false; if (file_exists($controllerFn))
{
return require_once $controllerFn;
}
else
{
return false;
}
} }
/** /**
* Lists PHP files in given directory. * Lists PHP files in given directory.
* *
* @param string $path Path to scan for files * @param string $path Path to scan for files
* @return array List of files in directory * @return array List of files in directory
*/ */
function listClasses($path) function listClasses($path)
{ {
$modules = new Folder($path); $modules = new Folder($path);
return $modules->find('(.+)\.php'); return $modules->find('(.+)\.php');
} }
/** /**
@ -117,27 +126,30 @@ function listClasses($path)
* *
* @return boolean Success * @return boolean Success
*/ */
function config () function config()
{ {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) foreach ($args as $arg)
{ {
if (('database' == $arg) && file_exists(CONFIGS.$arg.'.php')) if (('database' == $arg) && file_exists(CONFIGS.$arg.'.php'))
{ {
include_once(CONFIGS.$arg.'.php'); require_once CONFIGS.$arg.'.php';
} }
elseif (file_exists(CONFIGS.$arg.'.php')) elseif (file_exists(CONFIGS.$arg.'.php'))
{ {
include_once (CONFIGS.$arg.'.php'); require_once CONFIGS.$arg.'.php';
if (count($args) == 1) return true;
} if (count($args) == 1)
else {
{ return true;
if (count($args) == 1) return false; }
} }
} elseif (count($args) == 1)
{
return true; return false;
}
}
return true;
} }
/** /**
@ -150,28 +162,25 @@ function config ()
* *
* @uses LIBS * @uses LIBS
*/ */
function uses () function uses()
{ {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) foreach ($args as $arg)
{ {
require_once(LIBS.strtolower($arg).'.php'); require_once LIBS.strtolower($arg).'.php';
} }
} }
/** /**
* Require given files in the VENDORS directory. Takes optional number of parameters. * Require given files in the VENDORS directory. Takes optional number of parameters.
*
* @param string $name Filename without the .php part.
*
*/ */
function vendor($name) function vendor()
{ {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) foreach ($args as $arg)
{ {
require_once(VENDORS.$arg.'.php'); require_once VENDORS.$arg.'.php';
} }
} }
/** /**
@ -182,156 +191,171 @@ function vendor($name)
* @param boolean $var Variable to show debug information for. * @param boolean $var Variable to show debug information for.
* @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way. * @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way.
*/ */
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)
print_r($var); {
print "\n</pre>\n"; $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
} }
print_r($var);
print "\n</pre>\n";
}
} }
if (!function_exists('getMicrotime')) if (!function_exists('getMicrotime'))
{ {
/** /**
* Returns microtime for execution time checking. * Returns microtime for execution time checking.
* *
* @return integer * @return integer
*/ */
function getMicrotime() function getMicrotime()
{ {
list($usec, $sec) = explode(" ", microtime()); list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec); return ((float)$usec + (float)$sec);
} }
} }
if (!function_exists('sortByKey')) if (!function_exists('sortByKey'))
{ {
/** /**
* Sorts given $array by key $sortby. * Sorts given $array by key $sortby.
* *
* @param array $array * @param array $array
* @param string $sortby * @param string $sortby
* @param string $order Sort order asc/desc (ascending or descending). * @param string $order Sort order asc/desc (ascending or descending).
* @param integer $type * @param integer $type
* @return mixed * @return mixed
*/ */
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC)
{ {
if (!is_array($array)) if (!is_array($array))
return null; {
return null;
}
foreach ($array as $key => $val) foreach ($array as $key => $val)
{ {
$sa[$key] = $val[$sortby]; $sa[$key] = $val[$sortby];
} }
$order == 'asc' if ($order == 'asc')
? asort($sa, $type) {
: arsort($sa, $type); asort($sa, $type);
}
else
{
arsort($sa, $type);
}
foreach ($sa as $key=>$val) foreach ($sa as $key=>$val)
{ {
$out[] = $array[$key]; $out[] = $array[$key];
} }
return $out; return $out;
} }
} }
if (!function_exists('array_combine')) if (!function_exists('array_combine'))
{ {
/** /**
* Combines given identical arrays by using the first array's values as keys, * Combines given identical arrays by using the first array's values as keys,
* and the second one's values as values. (Implemented for back-compatibility with PHP4.) * and the second one's values as values. (Implemented for back-compatibility with PHP4.)
* *
* @param array $a1 * @param array $a1
* @param array $a2 * @param array $a2
* @return mixed Outputs either combined array or false. * @return mixed Outputs either combined array or false.
*/ */
function array_combine($a1, $a2) function array_combine($a1, $a2)
{ {
$a1 = array_values($a1); $a1 = array_values($a1);
$a2 = array_values($a2); $a2 = array_values($a2);
$c1 = count($a1); $c1 = count($a1);
$c2 = count($a2); $c2 = count($a2);
if ($c1 != $c2) return false; // different lenghts if ($c1 != $c2)
if ($c1 <= 0) return false; // arrays are the same and both are empty {
// different lenghts
$output = array(); return false;
}
for ($i = 0; $i < $c1; $i++) if ($c1 <= 0)
{ {
$output[$a1[$i]] = $a2[$i]; // arrays are the same and both are empty
} return false;
}
return $output;
} $output = array();
for ($i = 0; $i < $c1; $i++)
{
$output[$a1[$i]] = $a2[$i];
}
return $output;
}
} }
function h($text) function h($text)
{ {
return htmlspecialchars($text); return htmlspecialchars($text);
} }
function a() function a()
{ {
$args = func_get_args(); $args = func_get_args();
return $args; return $args;
} }
function ha() function ha()
{ {
$args = func_get_args(); $args = func_get_args();
for($l=0 ; $l<count($args) ; $l++) for ($l=0 ; $l<count($args) ; $l++)
{ {
$a[$args[$l]] = $l+1<count($args) ? $args[$l+1] : null; $a[$args[$l]] = $l+1<count($args) ? $args[$l+1] : null;
$l++; $l++;
} }
return $a; return $a;
} }
function e($text) function e($text)
{ {
echo $text; echo $text;
} }
function pr($var) function pr($var)
{ {
if(DEBUG > 0) if (DEBUG > 0)
{ {
echo "<pre>"; echo "<pre>";
print_r($var); print_r($var);
echo "</pre>"; echo "</pre>";
} }
} }
function params($p) function params($p)
{ {
if(!is_array($p) || count($p) == 0) if (!is_array($p) || count($p) == 0)
{ {
return null; return null;
} }
else else
{ {
if(is_array($p[0]) && count($p) == 1) if (is_array($p[0]) && count($p) == 1)
{ {
return $p[0]; return $p[0];
} }
else else
{ {
return $p; return $p;
} }
} }
} }