Skip to content
Permalink
Browse files

Start updating components, controllers and tests.

Start updating the various classes, and tests for changes in component
events. There is still more to be done, as a number of tests are still
failing.
  • Loading branch information...
markstory committed Jul 11, 2013
1 parent 83281e5 commit 835c59e3ee469f574333a88649f45470b0efdf8b
@@ -15,7 +15,9 @@
namespace Cake\Controller;
use Cake\Core\Object;
use Cake\Event\Event;
use Cake\Event\EventListener;
use Cake\Utility\ObjectCollection;
/**
* Base class for an individual Component. Components provide reusable bits of
@@ -30,10 +32,18 @@
* - `initialize()` - Fired before the controller's beforeFilter method.
* - `startup()` - Fired after the controller's beforeFilter method.
* - `beforeRender()` - Fired before the view + layout are rendered.
* - `shutdown()` - Fired after the action is complete and the view has been rendered
* - `shutdown()` - Fired after the action is complete and the view has been rendered.
* but before Controller::afterFilter().
* - `beforeRedirect()` - Fired before a redirect() is done.
*
* Each callback has a slightly different signature:
*
* - `intitalize(Event $event, Controller $controller)`
* - `startup(Event $event, Controller $controller)`
* - `beforeRender(Event $event, Controller $controller)`
* - `beforeRedirect(Event $event, Controller $controller, $url, $status, $exit)`
* - `shutdown(Event $event, Controller $controller)`
*
* @package Cake.Controller
* @link http://book.cakephp.org/2.0/en/controllers/components.html
* @see Controller::$components
@@ -79,7 +89,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
$this->settings = $settings;
$this->_set($settings);
if (!empty($this->components)) {
$this->_componentMap = ComponentCollection::normalizeObjectArray($this->components);
$this->_componentMap = ObjectCollection::normalizeObjectArray($this->components);
}
}
@@ -102,42 +112,46 @@ public function __get($name) {
/**
* Called before the Controller::beforeFilter().
*
* @param Event $event An Event instance
* @param Controller $controller Controller with components to initialize
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize
*/
public function initialize(Controller $controller) {
public function initialize(Event $event, Controller $controller) {
}
/**
* Called after the Controller::beforeFilter() and before the controller action
*
* @param Event $event An Event instance
* @param Controller $controller Controller with components to startup
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup
*/
public function startup(Controller $controller) {
public function startup(Event $event, Controller $controller) {
}
/**
* Called before the Controller::beforeRender(), and before
* the view class is loaded, and before Controller::render()
*
* @param Event $event An Event instance
* @param Controller $controller Controller with components to beforeRender
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRender
*/
public function beforeRender(Controller $controller) {
public function beforeRender(Event $event, Controller $controller) {
}
/**
* Called after Controller::render() and before the output is printed to the browser.
*
* @param Event $event An Event instance
* @param Controller $controller Controller with components to shutdown
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::shutdown
*/
public function shutdown(Controller $controller) {
public function shutdown(Event $event, Controller $controller) {
}
/**
@@ -152,14 +166,15 @@ public function shutdown(Controller $controller) {
* If your response is a string or an array that does not contain a 'url' key it will
* be used as the new URL to redirect to.
*
* @param Event $event An Event instance
* @param Controller $controller Controller with components to beforeRedirect
* @param string|array $url Either the string or URL array that is being redirected to.
* @param integer $status The status code of the redirect
* @param boolean $exit Will the script exit.
* @return array|void Either an array or null.
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect
*/
public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
public function beforeRedirect(Event $event, Controller $controller, $url, $status = null, $exit = true) {
}
/**
@@ -190,4 +205,5 @@ public function implementedEvents() {
}
return $events;
}
}
@@ -23,6 +23,7 @@
use Cake\Controller\ComponentCollection;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Utility\Hash;
@@ -204,10 +205,11 @@ public function __construct(ComponentCollection $collection, $settings = array()
/**
* Start CookieComponent for use in the controller
*
* @param Event $event An Event instance
* @param Controller $controller
* @return void
*/
public function startup(Controller $controller) {
public function startup(Event $event, Controller $controller) {
$this->_expire($this->time);
$this->_values[$this->name] = array();
@@ -19,6 +19,7 @@
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Error;
use Cake\Event\Event;
use Cake\Network\Request;
use Cake\Utility\Hash;
use Cake\Utility\Security;
@@ -216,10 +217,11 @@ class SecurityComponent extends Component {
/**
* Component startup. All security checking happens here.
*
* @param Event $event An Event instance
* @param Controller $controller Instantiating controller
* @return void
*/
public function startup(Controller $controller) {
public function startup(Event $event, Controller $controller) {
$this->request = $controller->request;
$this->_action = $this->request->params['action'];
$this->_methodsRequired($controller);
@@ -17,7 +17,6 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Object;
use Cake\Core\ObjectCollection;
use Cake\Core\Plugin;
use Cake\Error;
use Cake\Event\Event;
@@ -29,6 +28,7 @@
use Cake\Routing\Router;
use Cake\Utility\ClassRegistry;
use Cake\Utility\Inflector;
use Cake\Utility\ObjectCollection;
use Cake\Utility\MergeVariablesTrait;
use Cake\Utility\ViewVarsTrait;
use Cake\View\View;
@@ -565,8 +565,8 @@ public function implementedEvents() {
return array(
'Controller.initialize' => 'beforeFilter',
'Controller.beforeRender' => 'beforeRender',
'Controller.beforeRedirect' => array('callable' => 'beforeRedirect', 'passParams' => true),
'Controller.shutdown' => 'afterFilter'
'Controller.beforeRedirect' => 'beforeRedirect',
'Controller.shutdown' => 'afterFilter',
);
}
@@ -979,20 +979,22 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
* Called before the controller action. You can use this method to configure and customize components
* or perform logic that needs to happen before each controller action.
*
* @param Event $event An Event instance
* @return void
* @link http://book.cakephp.org/2.0/en/controllers.html#request-life-cycle-callbacks
*/
public function beforeFilter() {
public function beforeFilter(Event $event) {
}
/**
* Called after the controller action is run, but before the view is rendered. You can use this method
* to perform logic or set view variables that are required on every request.
*
* @param Event $event An Event instance
* @return void
* @link http://book.cakephp.org/2.0/en/controllers.html#request-life-cycle-callbacks
*/
public function beforeRender() {
public function beforeRender(Event $event) {
}
/**
@@ -1004,6 +1006,7 @@ public function beforeRender() {
* return a string which will be interpreted as the url to redirect to or return associative array with
* key 'url' and optionally 'status' and 'exit'.
*
* @param Event $event An Event instance
* @param string|array $url A string or array-based URL pointing to another location within the app,
* or an absolute URL
* @param integer $status Optional HTTP status code (eg: 404)
@@ -1014,16 +1017,17 @@ public function beforeRender() {
* array with the keys url, status and exit to be used by the redirect method.
* @link http://book.cakephp.org/2.0/en/controllers.html#request-life-cycle-callbacks
*/
public function beforeRedirect($url, $status = null, $exit = true) {
public function beforeRedirect(Event $event, $url, $status = null, $exit = true) {
}
/**
* Called after the controller action is run and rendered.
*
* @param Event $event An Event instance
* @return void
* @link http://book.cakephp.org/2.0/en/controllers.html#request-life-cycle-callbacks
*/
public function afterFilter() {
public function afterFilter(Event $event) {
}
/**
@@ -53,11 +53,12 @@ public function __construct($request = null, $response = null) {
) {
$this->RequestHandler = $this->Components->load('RequestHandler');
}
if ($this->Components->enabled('Auth')) {
$this->Components->disable('Auth');
$eventManager = $this->getEventManager();
if (isset($this->Auth)) {
$eventManager->detach($this->Auth);
}
if ($this->Components->enabled('Security')) {
$this->Components->disable('Security');
if (isset($this->Security)) {
$eventManager->detach($this->Security);
}
$this->_set(array('cacheAction' => false, 'viewPath' => 'Errors'));
}
@@ -162,7 +162,7 @@ protected function _getController($exception) {
$controller = new ErrorController($request, $response);
$controller->startupProcess();
} catch (\Exception $e) {
if (!empty($controller) && $controller->Components->enabled('RequestHandler')) {
if (!empty($controller) && isset($controller->RequestHandler)) {
$controller->RequestHandler->startup($controller);
}
}
@@ -141,7 +141,7 @@ public function setUp() {
$request = new Request('posts/index');
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
$this->Controller = new SecurityTestController($request);
$this->Controller->Components->init($this->Controller);
$this->Controller->constructClasses();
$this->Controller->Security = $this->Controller->TestSecurity;
$this->Controller->Security->blackHoleCallback = 'fail';
$this->Security = $this->Controller->Security;
@@ -118,9 +118,7 @@ public function testSomethingReferencingCookieComponent() {
$Controller->components = array('SomethingWithCookie');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Components->trigger('initialize', array(&$Controller));
$Controller->beforeFilter();
$Controller->Components->trigger('startup', array(&$Controller));
$Controller->startupProcess();
$this->assertInstanceOf('TestApp\Controller\Component\SomethingWithCookieComponent', $Controller->SomethingWithCookie);
$this->assertInstanceOf('Cake\Controller\Component\CookieComponent', $Controller->SomethingWithCookie->Cookie);
@@ -20,6 +20,7 @@
use Cake\Core\Configure;
use Cake\Error;
use Cake\Error\ExceptionRenderer;
use Cake\Event\Event;
use Cake\Network\Request;
use Cake\Routing\Router;
use Cake\TestSuite\Fixture\TestModel;
@@ -59,7 +60,7 @@ class BlueberryComponent extends Component {
*
* @return void
*/
public function initialize(Controller $controller) {
public function initialize(Event $event, Controller $controller) {
$this->testName = 'BlueberryComponent';
}
@@ -91,7 +92,7 @@ class TestErrorController extends Controller {
*
* @return void
*/
public function beforeRender() {
public function beforeRender(Event $event) {
echo $this->Blueberry->testName;
}

0 comments on commit 835c59e

Please sign in to comment.
You can’t perform that action at this time.