Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ All notable changes to this project will be documented in this file, in reverse

### Changed

- Nothing.
- [#67](https://github.com/zendframework/zend-expressive-zendviewrenderer/pull/67)
changes configuration option for default template suffix used by NamespacedPathStackResolver
to `$config['templates']['extension']` to match other template renderers provided
by framework. Default value is `phtml`

### Deprecated

- Nothing.
- [#67](https://github.com/zendframework/zend-expressive-zendviewrenderer/pull/67)
deprecates configuration option `$config['templates']['default_suffix']`
Copy link
Member

Choose a reason for hiding this comment

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

What about adding E_USER_DEPRECATED when default_suffix is used? It should help with migration.

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 think it would be a bad idea to do for 'config' service. And I did a release just couple days ago. Missed that inconsistency during review.


### Removed

Expand Down
4 changes: 2 additions & 2 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
* @copyright Copyright (c) 2017-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
*/

Expand Down Expand Up @@ -38,7 +38,7 @@ public function getDependencies() : array
public function getTemplates() : array
{
return [
'default_suffix' => 'phtml',
'extension' => 'phtml',
'layout' => 'layout::default',
'paths' => [],
];
Expand Down
6 changes: 4 additions & 2 deletions src/ZendViewRendererFactory.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
* @copyright Copyright (c) 2015-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
*/

Expand Down Expand Up @@ -60,6 +60,7 @@ public function __invoke(ContainerInterface $container) : ZendViewRenderer
$config = $container->has('config') ? $container->get('config') : [];
$config = $config['templates'] ?? [];


// Configuration
$resolver = new Resolver\AggregateResolver();
$resolver->attach(
Expand All @@ -76,8 +77,9 @@ public function __invoke(ContainerInterface $container) : ZendViewRenderer
// Inject helpers
$this->injectHelpers($renderer, $container);

$defaultSuffix = $config['extension'] ?? $config['default_suffix'] ?? null;
// Inject renderer
$view = new ZendViewRenderer($renderer, $config['layout'] ?? null, $config['default_suffix'] ?? null);
$view = new ZendViewRenderer($renderer, $config['layout'] ?? null, $defaultSuffix);

// Add template paths
$allPaths = isset($config['paths']) && is_array($config['paths']) ? $config['paths'] : [];
Expand Down
30 changes: 29 additions & 1 deletion test/ZendViewRendererFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
* @copyright Copyright (c) 2015-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
*/

Expand Down Expand Up @@ -253,6 +253,34 @@ public function testConfiguresTemplateMap()
}

public function testConfiguresCustomDefaultSuffix()
{
$config = [
'templates' => [
'extension' => 'php',
],
];

$this->container->has('config')->willReturn(true);
$this->container->get('config')->willReturn($config);
$this->container->has(HelperPluginManager::class)->willReturn(false);
$this->container->has(PhpRenderer::class)->willReturn(false);

$factory = new ZendViewRendererFactory();
$view = $factory($this->container->reveal());

$r = new ReflectionProperty($view, 'resolver');
$r->setAccessible(true);
$resolver = $r->getValue($view);

$this->assertInstanceOf(
NamespacedPathStackResolver::class,
$resolver,
'Expected NamespacedPathStackResolver not found!'
);
$this->assertEquals('php', $resolver->getDefaultSuffix());
}

public function testConfiguresDeprecatedDefaultSuffix()
{
$config = [
'templates' => [
Expand Down