Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #7300] Add ability to set custom ComponentRegistry to Controller object #7301

Merged
merged 1 commit into from Aug 26, 2015
Merged

[Fixes #7300] Add ability to set custom ComponentRegistry to Controller object #7301

merged 1 commit into from Aug 26, 2015

Conversation

korotovsky
Copy link
Contributor

No description provided.

$this->_Controller = $Controller;
$this->eventManager($Controller->eventManager());
}
$this->setController($Controller);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this inside the same if it had before

@markstory
Copy link
Member

Related to #7300

@@ -254,6 +255,11 @@ public function __construct(Request $request = null, Response $response = null,
$modelClass = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
$this->_setModelClass($modelClass);

if ($componentRegistry !== null) {
$this->_components = $componentRegistry;
$this->_components->setController($this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be done in the components() method when it is used as a setter?

public function components($components = null)
{
        if ($components === null && $this->_components === null) {
            $components = new ComponentRegistry($this);
        }
        if ($components !== null) {
           $components->setController($this);
           $this->_components = $components;
        }
        return $this->_components;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea. thanks.

@rchavik
Copy link
Member

rchavik commented Aug 25, 2015

I do not understand why we need a custom registry. Can you please explain?

@korotovsky
Copy link
Contributor Author

@rchavik If you'd like to implement DependencyInjection plugin for Cake3, then you have to replace the default ComponentRegistry to your own ContainerAwareComponentRegistry with overrided _create method.

P.S. I know about https://github.com/lorenzo/piping-bag abd https://github.com/rochamarcelo/cake-pimple-di, but the second one for example makes DI container accessible from everywhere, it's not good. Container should be silent for another application components and should not be used directly in your code.

// updated due to typos.

@lorenzo
Copy link
Member

lorenzo commented Aug 25, 2015

@korotovsky btw piping-bag's aim is so that you don't have to sue the container in your code

@korotovsky
Copy link
Contributor Author

@lorenzo Yes, but it has another disadvantages for us, AOP for example.

@lorenzo
Copy link
Member

lorenzo commented Aug 25, 2015

Any other comments on this before I merge?

@@ -61,6 +60,18 @@ public function getController()
}

/**
* Set the controller associated with the collection.
*
* @param Controller $controller Controller instance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fullynamespaced class is required.

@markstory
Copy link
Member

Looks good to me. Making the framework more DI container friendly is nice given that we don't provide a DI container.

@steefaan
Copy link
Contributor

👍

@rchavik
Copy link
Member

rchavik commented Aug 26, 2015

Can we change the last two args as an array?

*/
public function __construct(Request $request = null, Response $response = null, $name = null, $eventManager = null)
public function __construct(Request $request = null, Response $response = null, $name = null, $eventManager = null, $components = null)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, these two args here, ie: $config = array('eventManager' => null, 'components' => null)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just the last 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What benefits it will give to us? As for me - flat dependencies is the best solution. Moreover I afraid it's not a part of this task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory well, request and response was there in 2.x, so i figure we can make it the same. I don't mind getting them all into $config though.

@korotovsky to make it uniform like other classes do, eg: Table::__construct

lorenzo added a commit that referenced this pull request Aug 26, 2015
[Fixes #7300] Add ability to set custom ComponentRegistry to Controller object
@lorenzo lorenzo merged commit 2ddb0ff into cakephp:3.1 Aug 26, 2015
* @param \Cake\Controller\Controller $controller Controller instance.
* @return void
*/
public function setController(Controller $controller)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setController() is a public method but lacks an explicit test in ComponentRegistryTest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants