2005-05-22 23:24:09 +00:00
|
|
|
<?PHP
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// + $Id$
|
|
|
|
// +------------------------------------------------------------------+ //
|
|
|
|
// + Cake <https://developers.nextco.com/cake/> + //
|
|
|
|
// + Copyright: (c) 2005, Cake Authors/Developers + //
|
|
|
|
// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
|
|
|
|
// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
|
|
|
|
// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
|
|
|
|
// +------------------------------------------------------------------+ //
|
|
|
|
// + Licensed under The MIT License + //
|
|
|
|
// + Redistributions of files must retain the above copyright notice. + //
|
|
|
|
// + See: http://www.opensource.org/licenses/mit-license.php + //
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads all models.
|
|
|
|
*
|
|
|
|
* @uses listModules()
|
|
|
|
* @uses APP
|
|
|
|
* @uses MODELS
|
|
|
|
*/
|
|
|
|
function loadModels () {
|
|
|
|
require (APP.'app_model.php');
|
|
|
|
foreach (listClasses(MODELS) as $model_fn) {
|
|
|
|
require (MODELS.$model_fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads all controllers.
|
|
|
|
*
|
|
|
|
* @uses APP
|
|
|
|
* @uses listModules()
|
|
|
|
* @uses HELPERS
|
|
|
|
* @uses CONTROLLERS
|
|
|
|
*/
|
|
|
|
function loadControllers () {
|
|
|
|
require (APP.'app_controller.php');
|
|
|
|
|
|
|
|
foreach (listClasses(HELPERS) as $helper) {
|
|
|
|
require (HELPERS.$helper.'.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (listClasses(CONTROLLERS) as $controller) {
|
|
|
|
require (CONTROLLERS.$controller.'.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-05-31 23:18:22 +00:00
|
|
|
* Loads a controller and its helper libraries.
|
2005-05-22 23:24:09 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function loadController ($name) {
|
|
|
|
$controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php';
|
|
|
|
$helper_fn = HELPERS.Inflector::underscore($name).'_helper.php';
|
|
|
|
|
|
|
|
require(APP.'app_controller.php');
|
|
|
|
|
|
|
|
if (file_exists($helper_fn))
|
|
|
|
require($helper_fn);
|
2005-06-11 03:45:31 +00:00
|
|
|
|
2005-05-22 23:24:09 +00:00
|
|
|
return file_exists($controller_fn)? require($controller_fn): false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-05-31 23:18:22 +00:00
|
|
|
* Lists PHP files in given directory.
|
2005-05-22 23:24:09 +00:00
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return array
|
|
|
|
*/
|
2005-06-11 03:45:31 +00:00
|
|
|
function listClasses($path)
|
|
|
|
{
|
2005-05-22 23:24:09 +00:00
|
|
|
$modules = new Folder($path);
|
|
|
|
return $modules->find('(.+)\.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads configuration files
|
|
|
|
*/
|
|
|
|
function config () {
|
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $arg) {
|
2005-06-12 20:50:12 +00:00
|
|
|
if (('database' == $arg) && file_exists(CONFIGS.$arg.'.php'))
|
|
|
|
{
|
|
|
|
include_once(CONFIGS.$arg.'.php');
|
|
|
|
}
|
|
|
|
elseif (file_exists(CONFIGS.$arg.'.php')) {
|
2005-06-11 03:45:31 +00:00
|
|
|
include (CONFIGS.$arg.'.php');
|
2005-05-29 19:43:59 +00:00
|
|
|
if (count($args) == 1) return true;
|
2005-05-22 23:24:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-05-29 19:43:59 +00:00
|
|
|
if (count($args) == 1) return false;
|
2005-05-22 23:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
I've merged in Olle's changes.
Larry, I've merged in _some_ of your changes, I'll merge in the scaffolding and joins code when you tell me it's ready. But I don't want to break how the Controller class works, can't we really do without the constructClasses() method call? Which reminds me, with your joins code, will we be able to use constructs like $user->post->findAll() and $user->post->save()?
Also, what are your changes to the DBO_MySQL class? I mean the mysqlResultSet(), and fetchResult() methods. I didn't see any MySQL-specific code inside them, perhaps they belong to the DBO class itself?
- I've changed the headers on user-editable files in /app and /config. I hope they will constitute a compromise between readability and legality. I've left file Id, copyright, and licence notices.
- /libs/basic.php::uses() function logs included files in global $loaded. Please, consider it a note to myself. Also, I've moved the NeatArray class out of the /libs/basics.php (into /libs/neat_array.php).
- Some cleanups in the Controller and Dispatcher classes.
- DBO::Prepare() accepts strings _and_ arrays now. It's a step towards a unified params theory.
- I think I've added some comments to DBO sub-classes, but it might have been Olle.
- A fix in Model class (findAll didn't work properly)
- Object's constructor sets $this->db to &DBO, which means all Object-descendand classes have default access to the database if it's connected. We need to clean up the code accordingly (some classes set their own $this->db references).
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@236 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-06-05 11:05:24 +00:00
|
|
|
|
|
|
|
return true;
|
2005-05-22 23:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads component/components from LIBS.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* <code>
|
2005-06-11 03:45:31 +00:00
|
|
|
* uses('flay', 'time');
|
2005-05-22 23:24:09 +00:00
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @uses LIBS
|
|
|
|
*/
|
I've merged in Olle's changes.
Larry, I've merged in _some_ of your changes, I'll merge in the scaffolding and joins code when you tell me it's ready. But I don't want to break how the Controller class works, can't we really do without the constructClasses() method call? Which reminds me, with your joins code, will we be able to use constructs like $user->post->findAll() and $user->post->save()?
Also, what are your changes to the DBO_MySQL class? I mean the mysqlResultSet(), and fetchResult() methods. I didn't see any MySQL-specific code inside them, perhaps they belong to the DBO class itself?
- I've changed the headers on user-editable files in /app and /config. I hope they will constitute a compromise between readability and legality. I've left file Id, copyright, and licence notices.
- /libs/basic.php::uses() function logs included files in global $loaded. Please, consider it a note to myself. Also, I've moved the NeatArray class out of the /libs/basics.php (into /libs/neat_array.php).
- Some cleanups in the Controller and Dispatcher classes.
- DBO::Prepare() accepts strings _and_ arrays now. It's a step towards a unified params theory.
- I think I've added some comments to DBO sub-classes, but it might have been Olle.
- A fix in Model class (findAll didn't work properly)
- Object's constructor sets $this->db to &DBO, which means all Object-descendand classes have default access to the database if it's connected. We need to clean up the code accordingly (some classes set their own $this->db references).
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@236 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-06-05 11:05:24 +00:00
|
|
|
function uses ()
|
|
|
|
{
|
2005-06-12 20:50:12 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
|
|
|
require_once(LIBS.strtolower($arg).'.php');
|
|
|
|
}
|
|
|
|
}
|
I've merged in Olle's changes.
Larry, I've merged in _some_ of your changes, I'll merge in the scaffolding and joins code when you tell me it's ready. But I don't want to break how the Controller class works, can't we really do without the constructClasses() method call? Which reminds me, with your joins code, will we be able to use constructs like $user->post->findAll() and $user->post->save()?
Also, what are your changes to the DBO_MySQL class? I mean the mysqlResultSet(), and fetchResult() methods. I didn't see any MySQL-specific code inside them, perhaps they belong to the DBO class itself?
- I've changed the headers on user-editable files in /app and /config. I hope they will constitute a compromise between readability and legality. I've left file Id, copyright, and licence notices.
- /libs/basic.php::uses() function logs included files in global $loaded. Please, consider it a note to myself. Also, I've moved the NeatArray class out of the /libs/basics.php (into /libs/neat_array.php).
- Some cleanups in the Controller and Dispatcher classes.
- DBO::Prepare() accepts strings _and_ arrays now. It's a step towards a unified params theory.
- I think I've added some comments to DBO sub-classes, but it might have been Olle.
- A fix in Model class (findAll didn't work properly)
- Object's constructor sets $this->db to &DBO, which means all Object-descendand classes have default access to the database if it's connected. We need to clean up the code accordingly (some classes set their own $this->db references).
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@236 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-06-05 11:05:24 +00:00
|
|
|
|
2005-06-12 20:50:12 +00:00
|
|
|
function vendor($name)
|
|
|
|
{
|
2005-05-22 23:24:09 +00:00
|
|
|
$args = func_get_args();
|
I've merged in Olle's changes.
Larry, I've merged in _some_ of your changes, I'll merge in the scaffolding and joins code when you tell me it's ready. But I don't want to break how the Controller class works, can't we really do without the constructClasses() method call? Which reminds me, with your joins code, will we be able to use constructs like $user->post->findAll() and $user->post->save()?
Also, what are your changes to the DBO_MySQL class? I mean the mysqlResultSet(), and fetchResult() methods. I didn't see any MySQL-specific code inside them, perhaps they belong to the DBO class itself?
- I've changed the headers on user-editable files in /app and /config. I hope they will constitute a compromise between readability and legality. I've left file Id, copyright, and licence notices.
- /libs/basic.php::uses() function logs included files in global $loaded. Please, consider it a note to myself. Also, I've moved the NeatArray class out of the /libs/basics.php (into /libs/neat_array.php).
- Some cleanups in the Controller and Dispatcher classes.
- DBO::Prepare() accepts strings _and_ arrays now. It's a step towards a unified params theory.
- I think I've added some comments to DBO sub-classes, but it might have been Olle.
- A fix in Model class (findAll didn't work properly)
- Object's constructor sets $this->db to &DBO, which means all Object-descendand classes have default access to the database if it's connected. We need to clean up the code accordingly (some classes set their own $this->db references).
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@236 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-06-05 11:05:24 +00:00
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
2005-06-12 20:50:12 +00:00
|
|
|
require_once(VENDORS.$arg.'.php');
|
2005-05-22 23:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup a debug point.
|
|
|
|
*
|
|
|
|
* @param boolean $var
|
|
|
|
* @param boolean $show_html
|
|
|
|
*/
|
2005-06-11 03:45:31 +00:00
|
|
|
function debug($var = false, $show_html = false)
|
|
|
|
{
|
|
|
|
if (DEBUG)
|
|
|
|
{
|
2005-05-22 23:24:09 +00:00
|
|
|
print "\n<pre>\n";
|
|
|
|
if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
|
|
|
|
print_r($var);
|
|
|
|
print "\n</pre>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-11 03:45:31 +00:00
|
|
|
if (!function_exists('getMicrotime'))
|
|
|
|
{
|
2005-05-22 23:24:09 +00:00
|
|
|
/**
|
|
|
|
* Returns microtime for execution time checking.
|
|
|
|
*
|
|
|
|
* @return integer
|
|
|
|
*/
|
|
|
|
function getMicrotime() {
|
|
|
|
list($usec, $sec) = explode(" ", microtime());
|
|
|
|
return ((float)$usec + (float)$sec);
|
|
|
|
}
|
|
|
|
}
|
I've merged in Olle's changes.
Larry, I've merged in _some_ of your changes, I'll merge in the scaffolding and joins code when you tell me it's ready. But I don't want to break how the Controller class works, can't we really do without the constructClasses() method call? Which reminds me, with your joins code, will we be able to use constructs like $user->post->findAll() and $user->post->save()?
Also, what are your changes to the DBO_MySQL class? I mean the mysqlResultSet(), and fetchResult() methods. I didn't see any MySQL-specific code inside them, perhaps they belong to the DBO class itself?
- I've changed the headers on user-editable files in /app and /config. I hope they will constitute a compromise between readability and legality. I've left file Id, copyright, and licence notices.
- /libs/basic.php::uses() function logs included files in global $loaded. Please, consider it a note to myself. Also, I've moved the NeatArray class out of the /libs/basics.php (into /libs/neat_array.php).
- Some cleanups in the Controller and Dispatcher classes.
- DBO::Prepare() accepts strings _and_ arrays now. It's a step towards a unified params theory.
- I think I've added some comments to DBO sub-classes, but it might have been Olle.
- A fix in Model class (findAll didn't work properly)
- Object's constructor sets $this->db to &DBO, which means all Object-descendand classes have default access to the database if it's connected. We need to clean up the code accordingly (some classes set their own $this->db references).
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@236 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-06-05 11:05:24 +00:00
|
|
|
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!function_exists('sortByKey')) {
|
|
|
|
/**
|
|
|
|
* Sorts given $array by key $sortby.
|
|
|
|
*
|
|
|
|
* @param array $array
|
|
|
|
* @param string $sortby
|
2005-05-31 23:18:22 +00:00
|
|
|
* @param string $order Sort order asc/desc (ascending or descending).
|
2005-05-22 23:24:09 +00:00
|
|
|
* @param integer $type
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC) {
|
|
|
|
|
2005-06-11 03:45:31 +00:00
|
|
|
if (is_array($array)) {
|
2005-05-22 23:24:09 +00:00
|
|
|
|
2005-06-11 03:45:31 +00:00
|
|
|
foreach ($array as $key => $val)
|
2005-05-22 23:24:09 +00:00
|
|
|
$sa[$key] = $val[$sortby];
|
|
|
|
|
2005-06-11 03:45:31 +00:00
|
|
|
if ($order == 'asc')
|
|
|
|
asort($sa, $type);
|
2005-05-22 23:24:09 +00:00
|
|
|
else
|
2005-06-11 03:45:31 +00:00
|
|
|
arsort($sa, $type);
|
2005-05-22 23:24:09 +00:00
|
|
|
|
2005-06-11 03:45:31 +00:00
|
|
|
foreach ($sa as $key=>$val)
|
|
|
|
$out[] = $array[$key];
|
2005-05-22 23:24:09 +00:00
|
|
|
|
|
|
|
return $out;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2005-06-11 03:45:31 +00:00
|
|
|
return null;
|
2005-05-22 23:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('array_combine')) {
|
|
|
|
/**
|
|
|
|
* Combines given identical arrays by using the first array's values as keys,
|
2005-05-31 23:18:22 +00:00
|
|
|
* and the second one's values as values. (Implemented for back-compatibility with PHP4.)
|
2005-05-22 23:24:09 +00:00
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
$c1 = count($a1);
|
|
|
|
$c2 = count($a2);
|
|
|
|
|
|
|
|
if ($c1 != $c2) return false; // different lenghts
|
|
|
|
if ($c1 <= 0) return false; // arrays are the same and both are empty
|
|
|
|
|
|
|
|
$output = array();
|
|
|
|
|
|
|
|
for ($i = 0; $i < $c1; $i++) {
|
|
|
|
$output[$a1[$i]] = $a2[$i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|