Browse Source

Implement implementedEvents on all core components.

This saves the cost of doing reflection on each request. Because the
core components don't need any RAD affordances we can hardcode the
callback listeners and get a tiny performance increase.
mark_story 12 years ago
parent
commit
da143545fd

+ 12 - 0
src/Controller/Component/AuthComponent.php

@@ -273,6 +273,18 @@ class AuthComponent extends Component {
 	}
 
 /**
+ * Events supported by this component.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return [
+			'Controller.initialize' => 'initialize',
+			'Controller.startup' => 'startup',
+		];
+	}
+
+/**
  * Checks whether current action is accessible without authentication.
  *
  * @param Controller $controller A reference to the instantiating controller object

+ 11 - 0
src/Controller/Component/CookieComponent.php

@@ -154,6 +154,17 @@ class CookieComponent extends Component {
 	}
 
 /**
+ * Events supported by this component.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return [
+			'Controller.startup' => 'startup',
+		];
+	}
+
+/**
  * Write a value to the $_COOKIE[$key];
  *
  * Optional [Name.], required key, optional $value, optional $encrypt, optional $expires

+ 11 - 0
src/Controller/Component/CsrfComponent.php

@@ -96,6 +96,17 @@ class CsrfComponent extends Component {
 	}
 
 /**
+ * Events supported by this component.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return [
+			'Controller.startup' => 'startup',
+		];
+	}
+
+/**
  * Set the cookie in the response.
  *
  * Also sets the request->params['_csrfToken'] so the newly minted

+ 10 - 1
src/Controller/Component/PaginatorComponent.php

@@ -56,6 +56,15 @@ class PaginatorComponent extends Component {
 	);
 
 /**
+ * Events supported by this component.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return [];
+	}
+
+/**
  * Handles automatic pagination of model records.
  *
  * ## Configuring pagination
@@ -125,7 +134,7 @@ class PaginatorComponent extends Component {
  *
  * {{{
  * $query = $this->Articles->find('popular')->matching('Tags', function($q) {
- *	return $q->where(['name' => 'CakePHP'])
+ *   return $q->where(['name' => 'CakePHP'])
  * });
  * $results = $paginator->paginate($query);
  * }}}

+ 14 - 0
src/Controller/Component/RequestHandlerComponent.php

@@ -128,6 +128,20 @@ class RequestHandlerComponent extends Component {
 	}
 
 /**
+ * Events supported by this component.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return [
+			'Controller.initialize' => 'initialize',
+			'Controller.startup' => 'startup',
+			'Controller.beforeRender' => 'beforeRender',
+			'Controller.beforeRedirect' => 'beforeRedirect',
+		];
+	}
+
+/**
  * Checks to see if a specific content type has been requested and sets RequestHandler::$ext
  * accordingly. Checks the following in order: 1. The '_ext' value parsed by the Router. 2. A specific
  * AJAX type request indicated by the presence of a header. 3. The Accept header. With the exception

+ 11 - 0
src/Controller/Component/SecurityComponent.php

@@ -130,6 +130,17 @@ class SecurityComponent extends Component {
 	}
 
 /**
+ * Events supported by this component.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return [
+			'Controller.startup' => 'startup',
+		];
+	}
+
+/**
  * Sets the actions that require a request that is SSL-secured, or empty for all actions
  *
  * @param string|array $actions

+ 9 - 0
src/Controller/Component/SessionComponent.php

@@ -185,4 +185,13 @@ class SessionComponent extends Component {
 		return Session::started();
 	}
 
+/**
+ * Events supported by this component.
+ *
+ * @return array
+ */
+	public function implementedEvents() {
+		return [];
+	}
+
 }