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

Commit 8413fb9

Browse files
committed
Merge pull request #39 from gsteel/access-rendering-engine
Retrieve the PhpRenderer from the container if it’s there…
2 parents 10e05f3 + e266418 commit 8413fb9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/ZendViewRendererFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public function __invoke(ContainerInterface $container)
6262
100
6363
);
6464

65-
// Create the renderer
66-
$renderer = new PhpRenderer();
65+
// Create, or Retrieve the renderer from the container
66+
$renderer = ($container->has(PhpRenderer::class))
67+
? $container->get(PhpRenderer::class)
68+
: new PhpRenderer();
6769
$renderer->setResolver($resolver);
6870

6971
// Inject helpers

test/ZendViewRendererFactoryTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Zend\View\Model\ModelInterface;
2323
use Zend\View\Resolver\AggregateResolver;
2424
use Zend\View\Resolver\TemplateMapResolver;
25+
use Zend\View\Renderer\PhpRenderer;
2526

2627
class ZendViewRendererFactoryTest extends TestCase
2728
{
@@ -125,6 +126,7 @@ public function testCallingFactoryWithNoConfigReturnsZendViewInstance()
125126
{
126127
$this->container->has('config')->willReturn(false);
127128
$this->container->has(HelperPluginManager::class)->willReturn(false);
129+
$this->container->has(PhpRenderer::class)->willReturn(false);
128130
$this->injectBaseHelpers();
129131
$factory = new ZendViewRendererFactory();
130132
$view = $factory($this->container->reveal());
@@ -154,6 +156,7 @@ public function testConfiguresLayout()
154156
$this->container->has('config')->willReturn(true);
155157
$this->container->get('config')->willReturn($config);
156158
$this->container->has(HelperPluginManager::class)->willReturn(false);
159+
$this->container->has(PhpRenderer::class)->willReturn(false);
157160
$this->injectBaseHelpers();
158161
$factory = new ZendViewRendererFactory();
159162
$view = $factory($this->container->reveal());
@@ -175,6 +178,7 @@ public function testConfiguresPaths()
175178
$this->container->has('config')->willReturn(true);
176179
$this->container->get('config')->willReturn($config);
177180
$this->container->has(HelperPluginManager::class)->willReturn(false);
181+
$this->container->has(PhpRenderer::class)->willReturn(false);
178182
$this->injectBaseHelpers();
179183
$factory = new ZendViewRendererFactory();
180184
$view = $factory($this->container->reveal());
@@ -212,6 +216,7 @@ public function testConfiguresTemplateMap()
212216
$this->container->has('config')->willReturn(true);
213217
$this->container->get('config')->willReturn($config);
214218
$this->container->has(HelperPluginManager::class)->willReturn(false);
219+
$this->container->has(PhpRenderer::class)->willReturn(false);
215220
$this->injectBaseHelpers();
216221
$factory = new ZendViewRendererFactory();
217222
$view = $factory($this->container->reveal());
@@ -238,6 +243,7 @@ public function testInjectsCustomHelpersIntoHelperManager()
238243
{
239244
$this->container->has('config')->willReturn(false);
240245
$this->container->has(HelperPluginManager::class)->willReturn(false);
246+
$this->container->has(PhpRenderer::class)->willReturn(false);
241247
$this->injectBaseHelpers();
242248
$factory = new ZendViewRendererFactory();
243249
$view = $factory($this->container->reveal());
@@ -255,6 +261,7 @@ public function testInjectsCustomHelpersIntoHelperManager()
255261
public function testWillUseHelperManagerFromContainer()
256262
{
257263
$this->container->has('config')->willReturn(false);
264+
$this->container->has(PhpRenderer::class)->willReturn(false);
258265
$this->injectBaseHelpers();
259266

260267
$helpers = new HelperPluginManager($this->container->reveal());
@@ -281,4 +288,18 @@ public function testInjectsCustomHelpersIntoHelperManagerFromContainer(HelperPlu
281288
$this->assertInstanceOf(UrlHelper::class, $helpers->get('url'));
282289
$this->assertInstanceOf(ServerUrlHelper::class, $helpers->get('serverurl'));
283290
}
291+
292+
public function testWillUseRendererFromContainer()
293+
{
294+
$engine = new PhpRenderer;
295+
$this->container->has('config')->willReturn(false);
296+
$this->container->has(HelperPluginManager::class)->willReturn(false);
297+
$this->injectContainerService(PhpRenderer::class, $engine);
298+
299+
$factory = new ZendViewRendererFactory();
300+
$view = $factory($this->container->reveal());
301+
302+
$composed = $this->fetchPhpRenderer($view);
303+
$this->assertSame($engine, $composed);
304+
}
284305
}

0 commit comments

Comments
 (0)