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

Commit

Permalink
AcceptableViewModelSelector notice fixed
Browse files Browse the repository at this point in the history
InjectTemplateListener  to work with preferController routeMatch flag and controller_map
, so it can return proper template when using Apigility rest service
  • Loading branch information
nikolay committed Jun 19, 2016
1 parent b58e9f1 commit 3ff4408
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Plugin/AcceptableViewModelSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function getDefaultMatchAgainst()
protected function injectViewModelName($modelAcceptString, $modelName)
{
$modelName = str_replace('\\', '|', $modelName);
$modelAcceptString = (is_array($modelAcceptString ))
$modelAcceptString = (is_array($modelAcceptString))
? $modelAcceptString[key($modelAcceptString)]
: $modelAcceptString;
return $modelAcceptString . '; ' . self::INJECT_VIEWMODEL_NAME . '="' . $modelName . '", ';
Expand Down
2 changes: 1 addition & 1 deletion src/View/Http/InjectTemplateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function injectTemplate(MvcEvent $e)
}

$routeMatch = $e->getRouteMatch();
if($preferRouteMatchController = $routeMatch->getParam('prefer_route_match_controller', false)){
if ($preferRouteMatchController = $routeMatch->getParam('prefer_route_match_controller', false)) {
$this->setPreferRouteMatchController($preferRouteMatchController);
}

Expand Down
24 changes: 24 additions & 0 deletions test/View/InjectTemplateListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,28 @@ public function testPrefersRouteMatchController()

$this->assertEquals('some/other/service/namespace/sample', $myViewModel->getTemplate());
}

public function testPrefersRouteMatchControllerWithRouteMatchAndControllerMap()
{
$this->assertFalse($this->listener->isPreferRouteMatchController());
$controllerMap = [
'Some\Other\Service\Namespace\Controller\Sample' => 'another/sample'
];

$this->routeMatch->setParam('prefer_route_match_controller', true);
$this->routeMatch->setParam('controller', 'Some\Other\Service\Namespace\Controller\Sample');

$preferRouteMatchControllerRouteMatchConfig = $this->routeMatch->getParam('prefer_route_match_controller', false);
$this->listener->setPreferRouteMatchController($preferRouteMatchControllerRouteMatchConfig);
$this->listener->setControllerMap($controllerMap);

$myViewModel = new ViewModel();
$myController = new \ZendTest\Mvc\Controller\TestAsset\SampleController();

$this->event->setTarget($myController);
$this->event->setResult($myViewModel);
$this->listener->injectTemplate($this->event);

$this->assertEquals('another/sample', $myViewModel->getTemplate());
}
}

0 comments on commit 3ff4408

Please sign in to comment.