Skip to content

Commit

Permalink
Merge pull request #4864 from cakephp/3.0-component-initialize
Browse files Browse the repository at this point in the history
Use Component::initialize() instead of overriding constructor.
  • Loading branch information
ADmad committed Oct 12, 2014
2 parents 92e79f2 + 6078a18 commit 660c790
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
12 changes: 5 additions & 7 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -230,15 +230,13 @@ class AuthComponent extends Component {
protected $_authorizationProvider;

/**
* Constructor
* Initialize properties.
*
* @param ComponentRegistry $registry A ComponentRegistry object.
* @param array $config Array of configuration settings.
* @param array $config The config data.
* @return void
*/
public function __construct(ComponentRegistry $registry, array $config = []) {
parent::__construct($registry, $config);

$controller = $registry->getController();
public function initialize(array $config) {
$controller = $this->_registry->getController();
$this->request = $controller->request;
$this->response = $controller->response;
$this->session = $controller->request->session();
Expand Down
12 changes: 5 additions & 7 deletions src/Controller/Component/CookieComponent.php
Expand Up @@ -120,19 +120,17 @@ class CookieComponent extends Component {
protected $_validCiphers = ['aes', 'rijndael'];

/**
* Constructor
* Initialize config data and properties.
*
* @param ComponentRegistry $registry A ComponentRegistry for this component
* @param array $config Array of config.
* @param array $config The config data.
* @return void
*/
public function __construct(ComponentRegistry $registry, array $config = array()) {
parent::__construct($registry, $config);

public function initialize(array $config) {
if (!$this->_config['key']) {
$this->config('key', Security::salt());
}

$controller = $registry->getController();
$controller = $this->_registry->getController();
if ($controller && isset($controller->request)) {
$this->_request = $controller->request;
} else {
Expand Down
11 changes: 5 additions & 6 deletions src/Controller/Component/SessionComponent.php
Expand Up @@ -38,14 +38,13 @@ class SessionComponent extends Component {
protected $_session;

/**
* Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
* Initialize properties.
*
* @param ComponentRegistry $registry ComponentRegistry object.
* @param array $config Array of config.
* @param array $config The config data.
* @return void
*/
public function __construct(ComponentRegistry $registry, array $config = array()) {
parent::__construct($registry, $config);
$this->_session = $registry->getController()->request->session();
public function initialize(array $config) {
$this->_session = $this->_registry->getController()->request->session();
}

/**
Expand Down

0 comments on commit 660c790

Please sign in to comment.