Skip to content

Commit

Permalink
Updating intialiize() callbacks. Moving $this->_set() int Component::…
Browse files Browse the repository at this point in the history
…__construct as all the core components did it. Updating constructors and including parent calls.
  • Loading branch information
markstory committed Aug 11, 2010
1 parent 052c817 commit a4e2f7c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cake/libs/controller/component.php
Expand Up @@ -67,7 +67,7 @@ class Component extends Object {
public function __construct(ComponentCollection $collection, $settings = array()) {
$this->_Collection = $collection;
$this->settings = $settings;

$this->_set($settings);
if (!empty($this->components)) {
$this->_componentMap = ComponentCollection::normalizeObjectArray($this->components);
}
Expand Down
13 changes: 2 additions & 11 deletions cake/libs/controller/components/acl.php
Expand Up @@ -46,7 +46,8 @@ class AclComponent extends Component {
*
* @throws Exception when Acl.classname could not be loaded.
*/
public function __construct() {
public function __construct(ComponentCollection $collection, $settings = array()) {

This comment has been minimized.

Copy link
@CauanCabral

CauanCabral Jan 3, 2013

Contributor

I'm talking about that line @markstory , but that isn't in 1.3 branche.
So, again, sorry my mistake.

This comment has been minimized.

Copy link
@markstory

markstory Jan 3, 2013

Author Member

No worries 👍

parent::__construct($collection, $settings);
$name = Inflector::camelize(strtolower(Configure::read('Acl.classname')));
if (!class_exists($name)) {
if (App::import('Component', $name)) {
Expand Down Expand Up @@ -86,16 +87,6 @@ public function adapter($adapter = null) {
return $this->_Instance;
}

/**
* Startup is not used
*
* @param object $controller Controller using this component
* @return boolean Proceed with component usage (true), or fail (false)
*/
public function startup(&$controller) {
return true;
}

/**
* Pass-thru function for ACL check instance. Check methods
* are used to check whether or not an ARO can access an ACO
Expand Down
5 changes: 2 additions & 3 deletions cake/libs/controller/components/auth.php
Expand Up @@ -268,7 +268,7 @@ class AuthComponent extends Component {
* @param object $controller A reference to the instantiating controller object
* @return void
*/
public function initialize(&$controller, $settings = array()) {
public function initialize(&$controller) {

This comment has been minimized.

Copy link
@CauanCabral

CauanCabral Jan 3, 2013

Contributor

Why reference? Objects are always passed by reference: http://php.net/manual/en/language.oop5.references.php

This comment has been minimized.

Copy link
@dereuromark

dereuromark Jan 3, 2013

Member

Cake1.3 still had/has PHP4 BC.

This comment has been minimized.

Copy link
@CauanCabral

CauanCabral Jan 3, 2013

Contributor

Oh, its true.
But type hinting is supported in PHP 4? www.php.net/manual/en/language.oop5.typehinting.php

This comment has been minimized.

Copy link
@lorenzo

lorenzo Jan 3, 2013

Member

Why are you even commenting on something that happened 3 years ago?

This comment has been minimized.

Copy link
@ceeram

ceeram Jan 3, 2013

Contributor

That page clearly says it was introduced in php5, but typehinting does not make it a reference

This comment has been minimized.

Copy link
@ADmad

ADmad Jan 3, 2013

Member

Where did you see type hinting in 1.3?

This comment has been minimized.

Copy link
@CauanCabral

CauanCabral Jan 3, 2013

Contributor

Good question @lorenzo , I saw notification for that commit at some point but don't saw the date. Sorry.

Only for clarification, type hinting are introduced at acl.php file, line 49.

This comment has been minimized.

Copy link
@markstory

markstory Jan 3, 2013

Author Member

I don't see any typehinting in the current AclShell, AclComponent or AclBehavior on line 49.

$this->params = $controller->params;
$crud = array('create', 'read', 'update', 'delete');
$this->actionMap = array_merge($this->actionMap, array_combine($crud, $crud));
Expand All @@ -290,8 +290,7 @@ public function initialize(&$controller, $settings = array()) {
));
}
}
$this->_set($settings);
if (Configure::read('debug') > 0) {
if (Configure::read() > 0) {
App::import('Debugger');
Debugger::checkSecurityKeys();
}
Expand Down
3 changes: 1 addition & 2 deletions cake/libs/controller/components/cookie.php
Expand Up @@ -162,9 +162,8 @@ class CookieComponent extends Component {
*
* @param object $controller A reference to the instantiating controller object
*/
public function initialize(&$controller, $settings) {
public function initialize(&$controller) {
$this->key = Configure::read('Security.salt');
$this->_set($settings);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions cake/libs/controller/components/email.php
Expand Up @@ -303,12 +303,11 @@ class EmailComponent extends Component {
*
* @param object $controller Instantiating controller
*/
public function initialize(&$controller, $settings = array()) {
public function initialize(&$controller) {
$this->Controller = $controller;
if (Configure::read('App.encoding') !== null) {
$this->charset = Configure::read('App.encoding');
}
$this->_set($settings);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions cake/libs/controller/components/request_handler.php
Expand Up @@ -173,8 +173,10 @@ class RequestHandlerComponent extends Component {
/**
* Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
*
* @param ComponentCollection $collection ComponentCollection object.
* @param array $settings Array of settings.
*/
function __construct() {
function __construct(ComponentCollection $collection, $settings = array()) {
$this->__acceptTypes = explode(',', env('HTTP_ACCEPT'));

foreach ($this->__acceptTypes as $i => $type) {
Expand All @@ -183,7 +185,7 @@ function __construct() {
$this->__acceptTypes[$i] = $type[0];
}
}
parent::__construct();
parent::__construct($collection, $settings);
}

/**
Expand All @@ -197,11 +199,10 @@ function __construct() {
* @return void
* @see Router::parseExtensions()
*/
public function initialize(&$controller, $settings = array()) {
public function initialize(&$controller) {
if (isset($controller->params['url']['ext'])) {
$this->ext = $controller->params['url']['ext'];
}
$this->_set($settings);
}

/**
Expand Down
11 changes: 0 additions & 11 deletions cake/libs/controller/components/security.php
Expand Up @@ -169,17 +169,6 @@ class SecurityComponent extends Component {
*/
protected $_action = null;

/**
* Initialize the SecurityComponent
*
* @param object $controller Controller instance for the request
* @param array $settings Settings to set to the component
* @return void
*/
public function initialize(&$controller, $settings = array()) {
$this->_set($settings);
}

/**
* Component startup. All security checking happens here.
*
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/controller/controller.php
Expand Up @@ -625,7 +625,7 @@ public function redirect($url, $status = null, $exit = true) {
$response = $this->Components->trigger(
'beforeRedirect',
array(&$this, $url, $status, $exit),
array('break' => true, 'breakOn' => false)
array('break' => true, 'breakOn' => false, 'collectReturn' => true)
);

if ($response === false) {
Expand Down

0 comments on commit a4e2f7c

Please sign in to comment.