cakephp2-php8/cake/libs/controller/component.php
phpnut 9a8d5c15fe Merging fixes and enhancements into trunk
Revision: [2009]
Adding fixes for session errors posted in the google group.
Changed the header for PHP version in the model classes.
Change uses() back to require_once 

Revision: [2008]
Adding reference back to the PHP 4 model

Revision: [2007]
Merging changes from model_php5

Revision: [2006]
Fixing recursive associations, adding whitelist to Model::save

Revision: [2005]
Added fix for error in CakeSession class.
Updated home.thtml

Revision: [2004]
Rearranged  some of the defines moving the most often changed ones to the top of the script

Revision: [2003]
Moved SQL files distributed with the core to app/config/sql/
Removed app/config/routes.php.default
Fixed class_exists check in TextHelper

Revision: [2002]
adding sql directory

Revision: [2001]
Fixed error when cake distribution is installed inside of the DOCUMENT ROOT 

Revision: [2000]
Adding checks for classes that are already loaded so the require() calls will not error

Revision: [1999]
Replacing all require_once() with require()

Revision: [1998]
Moved creation of the Dispatcher object to app/webroot/index.php

Revision: [1997]
Adding session sql file

Revision: [1996]
Revision: [1995]
Fixing session db queries

Revision: [1994]
Change the require_once in bootstrap to require.
Merged changes John made to the CakeSession database methods

Revision: [1993]
Removing some constants that are not needed

Revision: [1992]
Adding fix for Ticket #400

Revision: [1991]
Fixing Ticket #348

Revision: [1990]
Fixing Tickets #397 and #399

Revision: [1989]
Fixed callbacks in JavaScript events and Ajax, fixed Controller::beforeRender so you can set view variables, and fixed Ticket #394

Revision: [1988]
Renamed the $dir param to $direction.
Added default value to the DboSource::order() $direction param.

Revision: [1987]
Adding changes back to the sessions class I reverted in [1984]

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2010 3807eeeb-6ff5-0310-8944-8be069107fe0
2006-02-17 10:12:15 +00:00

154 lines
No EOL
4.8 KiB
PHP

<?php
/* SVN FILE: $Id$ */
/**
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2006, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.controller
* @since CakePHP v TBD
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
*
*
* @package cake
* @subpackage cake.cake.libs.controller
* @since CakePHP v TBD
*/
class Component extends Object
{
/**
* Enter description here...
*
* @var unknown_type
*/
var $components = array();
/**
* Enter description here...
*
* @var unknown_type
*/
var $controller = null;
/**
* Constructor
*
* @return Component
*/
function Component(&$controller)
{
$this->controller =& $controller;
if ($this->controller->components !== false)
{
$loaded = array();
$loaded = $this->_loadComponents($loaded,$this->controller->components);
foreach(array_keys($loaded) as $component)
{
$tempComponent =& $loaded[$component];
if(isset($tempComponent->components) && is_array($tempComponent->components))
{
foreach($tempComponent->components as $subComponent)
{
$this->controller->{$component}->{$subComponent} =& $loaded[$subComponent];
}
}
}
}
}
/**
* Enter description here...
*
* @param unknown_type $loaded
* @param unknown_type $components
* @return unknown
*/
function &_loadComponents(&$loaded, $components)
{
foreach ($components as $component)
{
if(in_array($component, array_keys($loaded)) !== true)
{
$componentFn = Inflector::underscore($component).'.php';
if(file_exists(APP.'plugins'.DS.$this->controller->plugin.'controllers'.DS.'components'.DS.$componentFn))
{
$componentFn = APP.'plugins'.DS.$this->controller->plugin.'controllers'.DS.'components'.DS.$componentFn;
}
else if(file_exists(COMPONENTS.$componentFn))
{
$componentFn = COMPONENTS.$componentFn;
}
else if($componentFn = fileExistsInPath(LIBS.'controller'.DS.'components'.DS.$componentFn))
{
}
$componentCn = $component.'Component';
if (is_file($componentFn))
{
if(!class_exists($componentCn))
{
require_once $componentFn;
}
if(class_exists($componentCn)===true)
{
if($componentCn == 'SessionComponent')
{
$param = $this->controller->base.'/';
}
else
{
$param = null;
}
$this->controller->{$component} =& new $componentCn($param);
$loaded[$component] =& $this->controller->{$component};
if (isset($this->controller->{$component}->components) && is_array($this->controller->{$component}->components))
{
$loaded =& $this->_loadComponents($loaded, $this->controller->{$component}->components);
}
}
else
{
return $this->cakeError('missingComponentClass',
array(array('className' => $this->controller->name,
'component' => $component,
'file' => $componentFn)));
}
}
else
{
return $this->cakeError('missingComponentFile',
array(array('className' => $this->controller->name,
'component' => $component,
'file' => $componentFn)));
}
}
}
return $loaded;
}
}
?>