2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2008-05-30 11:40:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Controller
|
2010-07-04 17:14:04 +00:00
|
|
|
* @since CakePHP(tm) v 1.2
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2010-12-03 22:38:52 +00:00
|
|
|
App::uses('ComponentCollection', 'Controller');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* Base class for an individual Component. Components provide reusable bits of
|
|
|
|
* controller logic that can be composed into a controller. Components also
|
2010-07-04 18:58:57 +00:00
|
|
|
* provide request life-cycle callbacks for injecting logic at specific points.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-09-15 03:01:39 +00:00
|
|
|
* ## Life cycle callbacks
|
|
|
|
*
|
|
|
|
* Components can provide several callbacks that are fired at various stages of the request
|
2012-12-22 22:48:15 +00:00
|
|
|
* cycle. The available callbacks are:
|
2010-09-15 03:01:39 +00:00
|
|
|
*
|
|
|
|
* - `initialize()` - Fired before the controller's beforeFilter method.
|
|
|
|
* - `startup()` - Fired after the controller's beforeFilter method.
|
|
|
|
* - `beforeRender()` - Fired before the view + layout are rendered.
|
2011-05-28 20:38:46 +00:00
|
|
|
* - `shutdown()` - Fired after the action is complete and the view has been rendered
|
|
|
|
* but before Controller::afterFilter().
|
2010-09-15 03:01:39 +00:00
|
|
|
* - `beforeRedirect()` - Fired before a redirect() is done.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Controller
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/controllers/components.html
|
2010-07-04 18:58:57 +00:00
|
|
|
* @see Controller::$components
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class Component extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-07-04 18:58:57 +00:00
|
|
|
* Component collection class used to lazy load components.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-07-04 18:58:57 +00:00
|
|
|
* @var ComponentCollection
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
protected $_Collection;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-07-04 18:58:57 +00:00
|
|
|
* Settings for this Component
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-07-04 18:58:57 +00:00
|
|
|
* @var array
|
2008-10-15 13:07:46 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
public $settings = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-15 13:07:46 +00:00
|
|
|
/**
|
2010-07-04 18:58:57 +00:00
|
|
|
* Other Components this component uses.
|
2008-10-15 13:07:46 +00:00
|
|
|
*
|
2010-07-04 18:58:57 +00:00
|
|
|
* @var array
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
public $components = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-04 02:39:05 +00:00
|
|
|
/**
|
2010-07-04 18:58:57 +00:00
|
|
|
* A component lookup table used to lazy load component objects.
|
2008-06-04 02:39:05 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
protected $_componentMap = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-07-04 18:58:57 +00:00
|
|
|
* Constructor
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-07-04 18:58:57 +00:00
|
|
|
* @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components
|
|
|
|
* @param array $settings Array of configuration settings.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-07-04 18:58:57 +00:00
|
|
|
public function __construct(ComponentCollection $collection, $settings = array()) {
|
|
|
|
$this->_Collection = $collection;
|
|
|
|
$this->settings = $settings;
|
2010-07-04 21:09:44 +00:00
|
|
|
$this->_set($settings);
|
2010-07-04 18:58:57 +00:00
|
|
|
if (!empty($this->components)) {
|
|
|
|
$this->_componentMap = ComponentCollection::normalizeObjectArray($this->components);
|
2008-10-15 13:07:46 +00:00
|
|
|
}
|
2010-07-04 18:58:57 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-04 18:58:57 +00:00
|
|
|
/**
|
|
|
|
* Magic method for lazy loading $components.
|
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @param string $name Name of component to get.
|
2010-07-04 18:58:57 +00:00
|
|
|
* @return mixed A Component object or null.
|
|
|
|
*/
|
|
|
|
public function __get($name) {
|
|
|
|
if (isset($this->_componentMap[$name]) && !isset($this->{$name})) {
|
2014-04-07 23:49:33 +00:00
|
|
|
$settings = array('enabled' => false) + (array)$this->_componentMap[$name]['settings'];
|
2010-11-07 04:07:27 +00:00
|
|
|
$this->{$name} = $this->_Collection->load($this->_componentMap[$name]['class'], $settings);
|
2010-07-04 18:58:57 +00:00
|
|
|
}
|
|
|
|
if (isset($this->{$name})) {
|
|
|
|
return $this->{$name};
|
|
|
|
}
|
2008-05-31 03:54:22 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-31 03:54:22 +00:00
|
|
|
/**
|
2008-10-30 19:39:18 +00:00
|
|
|
* Called before the Controller::beforeFilter().
|
2008-05-31 03:54:22 +00:00
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @param Controller $controller Controller with components to initialize
|
2008-09-25 16:49:56 +00:00
|
|
|
* @return void
|
2011-10-15 16:08:49 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize
|
2008-05-31 03:54:22 +00:00
|
|
|
*/
|
2012-03-04 00:27:46 +00:00
|
|
|
public function initialize(Controller $controller) {
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-31 03:54:22 +00:00
|
|
|
/**
|
|
|
|
* Called after the Controller::beforeFilter() and before the controller action
|
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @param Controller $controller Controller with components to startup
|
2008-09-25 16:49:56 +00:00
|
|
|
* @return void
|
2011-10-15 16:08:49 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup
|
2008-05-31 03:54:22 +00:00
|
|
|
*/
|
2012-03-04 00:27:46 +00:00
|
|
|
public function startup(Controller $controller) {
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-31 03:54:22 +00:00
|
|
|
/**
|
2012-07-18 01:55:29 +00:00
|
|
|
* Called before the Controller::beforeRender(), and before
|
2012-03-12 01:35:11 +00:00
|
|
|
* the view class is loaded, and before Controller::render()
|
2008-05-31 03:54:22 +00:00
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @param Controller $controller Controller with components to beforeRender
|
2008-09-25 16:49:56 +00:00
|
|
|
* @return void
|
2011-10-15 16:08:49 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRender
|
2008-05-31 03:54:22 +00:00
|
|
|
*/
|
2012-03-04 00:27:46 +00:00
|
|
|
public function beforeRender(Controller $controller) {
|
|
|
|
}
|
2010-07-04 18:58:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after Controller::render() and before the output is printed to the browser.
|
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @param Controller $controller Controller with components to shutdown
|
2010-07-04 18:58:57 +00:00
|
|
|
* @return void
|
2012-12-28 20:54:00 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::shutdown
|
2010-07-04 18:58:57 +00:00
|
|
|
*/
|
2012-03-04 00:27:46 +00:00
|
|
|
public function shutdown(Controller $controller) {
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-31 03:54:22 +00:00
|
|
|
/**
|
2013-04-29 09:05:17 +00:00
|
|
|
* Called before Controller::redirect(). Allows you to replace the URL that will
|
|
|
|
* be redirected to with a new URL. The return of this method can either be an array or a string.
|
2010-08-11 03:45:28 +00:00
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* If the return is an array and contains a 'url' key. You may also supply the following:
|
2011-05-28 20:38:46 +00:00
|
|
|
*
|
2010-08-11 03:45:28 +00:00
|
|
|
* - `status` The status code for the redirect
|
|
|
|
* - `exit` Whether or not the redirect should exit.
|
|
|
|
*
|
2011-05-28 20:38:46 +00:00
|
|
|
* If your response is a string or an array that does not contain a 'url' key it will
|
2013-04-29 09:05:17 +00:00
|
|
|
* be used as the new URL to redirect to.
|
2008-05-31 03:54:22 +00:00
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @param Controller $controller Controller with components to beforeRedirect
|
2013-04-29 09:05:17 +00:00
|
|
|
* @param string|array $url Either the string or URL array that is being redirected to.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $status The status code of the redirect
|
|
|
|
* @param bool $exit Will the script exit.
|
2015-10-10 13:49:00 +00:00
|
|
|
* @return array|null Either an array or null.
|
2013-02-27 02:43:53 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect
|
2008-05-31 03:54:22 +00:00
|
|
|
*/
|
2012-03-04 00:27:46 +00:00
|
|
|
public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
|
|
|
|
}
|
2010-02-28 02:47:32 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|