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

Commit 3ff4408

Browse files
author
nikolay
committed
AcceptableViewModelSelector notice fixed
InjectTemplateListener to work with preferController routeMatch flag and controller_map , so it can return proper template when using Apigility rest service
1 parent b58e9f1 commit 3ff4408

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Controller/Plugin/AcceptableViewModelSelector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function getDefaultMatchAgainst()
209209
protected function injectViewModelName($modelAcceptString, $modelName)
210210
{
211211
$modelName = str_replace('\\', '|', $modelName);
212-
$modelAcceptString = (is_array($modelAcceptString ))
212+
$modelAcceptString = (is_array($modelAcceptString))
213213
? $modelAcceptString[key($modelAcceptString)]
214214
: $modelAcceptString;
215215
return $modelAcceptString . '; ' . self::INJECT_VIEWMODEL_NAME . '="' . $modelName . '", ';

src/View/Http/InjectTemplateListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function injectTemplate(MvcEvent $e)
6161
}
6262

6363
$routeMatch = $e->getRouteMatch();
64-
if($preferRouteMatchController = $routeMatch->getParam('prefer_route_match_controller', false)){
64+
if ($preferRouteMatchController = $routeMatch->getParam('prefer_route_match_controller', false)) {
6565
$this->setPreferRouteMatchController($preferRouteMatchController);
6666
}
6767

test/View/InjectTemplateListenerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,28 @@ public function testPrefersRouteMatchController()
340340

341341
$this->assertEquals('some/other/service/namespace/sample', $myViewModel->getTemplate());
342342
}
343+
344+
public function testPrefersRouteMatchControllerWithRouteMatchAndControllerMap()
345+
{
346+
$this->assertFalse($this->listener->isPreferRouteMatchController());
347+
$controllerMap = [
348+
'Some\Other\Service\Namespace\Controller\Sample' => 'another/sample'
349+
];
350+
351+
$this->routeMatch->setParam('prefer_route_match_controller', true);
352+
$this->routeMatch->setParam('controller', 'Some\Other\Service\Namespace\Controller\Sample');
353+
354+
$preferRouteMatchControllerRouteMatchConfig = $this->routeMatch->getParam('prefer_route_match_controller', false);
355+
$this->listener->setPreferRouteMatchController($preferRouteMatchControllerRouteMatchConfig);
356+
$this->listener->setControllerMap($controllerMap);
357+
358+
$myViewModel = new ViewModel();
359+
$myController = new \ZendTest\Mvc\Controller\TestAsset\SampleController();
360+
361+
$this->event->setTarget($myController);
362+
$this->event->setResult($myViewModel);
363+
$this->listener->injectTemplate($this->event);
364+
365+
$this->assertEquals('another/sample', $myViewModel->getTemplate());
366+
}
343367
}

0 commit comments

Comments
 (0)