Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Remove SM-Aware requirement from Forward plugin #4330

Merged
merged 3 commits into from
Apr 30, 2013

Conversation

weierophinney
Copy link
Member

This is based on discussions in #4314 - essentially, the main reason that controllers are ServiceManagerAware is because it was the only way to have workflow-aware plugins such as the Forward plugin. Or so we thought.

On analysis, it's far simpler and easier to inject the ControllerManager instance directly into the Forward plugin on creation, as it allows us to remove quite some code, and remove the requirement that controllers be ServiceManagerAware in order to forward.

This PR modifies the Forward plugin to accept a ControllerManager instance via a setter, and adds a ForwardFactory that does this. Tests have been modified as the internal workflow was able to change and be simplified (much of the work done was validating the controller, and this is handled by the ControllerManager now).

- This was the old way of getting a controller to forward to:
  - Grab the currently set controller
  - Grab the service locator from the controller
  - Grab the ControllerLoader service from the service locator
  - Grab the new controller from the ControllerLoader service
- New way:
  - ForwardFactory injects the ControllerManager instance into the
    Forward instance on creation.
  - Forward plugin pulls the new controller from the composed
    ControllerManager.

Better separation of concerns, better usage of Dependency Injection,
controllers no longer need to be ServiceManagerAware in order to forward
(they just need the PluginManager injected).
@Thinkscape
Copy link
Member

👍

@prolic
Copy link
Contributor

prolic commented Apr 26, 2013

great!

* @param ControllerManager $locator
* @return self
*/
public function setLocator(ControllerManager $locator)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe setControllerPluginManager is a better name ? It reduces confusion that "locator" could be THE locator (although, I agree, it's still a locator)

Copy link
Member Author

Choose a reason for hiding this comment

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

I did this to be symmetric with the already existing getLocator() method. I'd rather be consistent here.

Copy link
Member

Choose a reason for hiding this comment

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

@weierophinney is this setter actually needed to be public?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Ocramius No, it's not -- that's a remnant from before I was injecting it via the constructor. I'll change that shortly.

- Use constructor injection for getting ControllerManager into Forward plugin
  (per @bakura10)
- Remove test case that's no longer applicable (we can now forward to any
  controller!)
- Fix test cases that were instantiating the Forward plugin directly to inject
  the ControllerManager
@GeeH
Copy link

GeeH commented Apr 30, 2013

Superb, I think this will make the controller much clearer :) :+1

*
* @return ControllerManager
*/
public function getLocator()
Copy link
Member

Choose a reason for hiding this comment

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

Would personally remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed.

- Since we're doing constructor injection, the setter is not necessary,
  and neither is the getter. As the setter did not exist previously, and
  the getter was protected previously, they can safely be removed.
- Renamed $locator to $controllers to make the name more semantic.
akrabat added a commit that referenced this pull request Apr 30, 2013
@akrabat akrabat merged commit 2917ef0 into zendframework:develop Apr 30, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants