-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Basz feature/accepted model controller plugin #2615
Basz feature/accepted model controller plugin #2615
Conversation
@weierophinney I incorporated @basz 's feedback. Up for review. |
Rebased! |
This plugin allows one to easily and safely define what View Model type should be used based on the accept header string.
Generally this mapping array will be defined on a controller level, or even application wide level. But it does allow one to deviate from the defaults. The need for this functionality arises because of multiple difficulties currently experienced with accept header handling and view model selection:
|
* @package Zend_Mvc | ||
* @subpackage Controller | ||
*/ | ||
class AcceptantViewModelSelector extends AbstractPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be AcceptedViewModelSelector
My only concern at this point is whether or not the ViewManager should allow registering strategies at initialization or not. Removing that functionality is technically a BC break, but, as you and others have noted, it could also be a potential security issue. I'll ask the security team their opinion. Otherwise, this is a great set of functionality, and I look forward to merging it and using it. |
* Set a Field Value Part this Field Value Part matched against. | ||
* | ||
* @param AbstractFieldValuePart $matchedPart | ||
* return AbstractFieldValuePart provides fluent interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed @
in front of return
…e request accept header
…tion is now cached
could not be found. Based on PR feedback
Would it be possible to make some use cases a bit easier to work with? In my particular case, I have quite often support for a Json model when I could imagine a simple way like this: class MyController
{
public function fooAction()
{
$service = $this->getService();
$result = $service->doSomeWork();
if ($this->accept()->match(array('application/json', 'application/javascript'))) {
return new JsonModel($result);
}
return $this->redirect()->toRoute('foo/bar');
}
} I can create my own plugin using |
@basz @Freeaqingme Don't forget send a PR to zf2-documentation documenting the plugn! |
I can start with this... but not within a few days... |
@juriansluiman We could indeed implement such functionality. However, it should be 100% configurable, and may need a little bit more thought put into it. Lets get this baby done first, then look what else we could do. @Maks3w No worries, you're getting your docs! ;) |
@Freeaqingme As noted yesterday on IRC, we'll need to merge this against the master branch as well. The only way I see to do this is to merge a range of commits or cherry-pick. My question is: do you want to do this, or are you okay with somebody else doing it? Both will rewrite history, so the question is if you want that rewrite to happen in your own branch, or in mine. |
- Added security note about change to JsonStrategy and FeedStrategy, and also detail AcceptableViewModelSelector usage
- Split testInvokeWithoutDefaults() into two separate tests, for the separate behaviors it tested (testInvokeWithoutDefaultsReturnsNullWhenNoMatchesOccur() and testInvokeReturnsFieldValuePartOnMatchWhenReferenceProvided()) - Renamed testInvoke__2() to testHonorsAcceptPrecedenceAndPriorityWhenInvoked()
Introduce AcceptableViewModelSelector, and remove Accept matching from JsonStrategy and FeedStrategy Close zendframework/zendframework#2615 Close zendframework/zendframework#2410
Forward port zendframework/zendframework#2615 and zendframework/zendframework#2410 Conflicts: library/Zend/Mvc/Controller/PluginManager.php
Introduce AcceptableViewModelSelector, and remove Accept matching from JsonStrategy and FeedStrategy Close zendframework/zendframework#2615 Close zendframework/zendframework#2410
Forward port zendframework/zendframework#2615 and zendframework/zendframework#2410 Conflicts: library/Zend/Mvc/Controller/PluginManager.php
This is a follow up of #2405: https://github.com/zendframework/zf2/pull/2405/files