Skip to content

Commit

Permalink
Merge pull request #30 from Ocramius/feature/zf3-compat
Browse files Browse the repository at this point in the history
ZF3 compatibility, dropping PHP 5.x
  • Loading branch information
Ocramius committed Jun 4, 2016
2 parents 22f08af + a1f455b commit 1e1bd07
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 211 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ language: php
sudo: false

php:
- 5.5
- 5.6
- 7.0
- hhvm

Expand All @@ -13,6 +11,10 @@ env:
- DEPENDENCIES=""
- DEPENDENCIES="--prefer-lowest --prefer-stable"

matrix:
allow_failures:
- php: hhvm

before_script:
- composer self-update
- composer update --prefer-source $DEPENDENCIES
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 4.0.0 - 2016-06-04

### Added

- Support for `zendframework/zend-mvc` 3.x

### Deprecated

- Nothing.

### Removed

- Support for PHP 5 has been dropped
- Factories now follow the interfaces suggested by `zendframework/zend-servicemanager` 3.x

### Fixed

- Nothing.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
OcraCachedViewResolver is performance-oriented Zend Framework 2 Module that increases performance
in your application by caching the process of resolving template names to template paths.

In ZF2, the process of resolving template paths causes a lot of stat calls. This module adds
In ZF3, the process of resolving template paths causes a lot of stat calls. This module adds
a cache layer to avoid that.

| Tests | Releases | Downloads | Dependencies |
Expand All @@ -19,8 +19,8 @@ The recommended way to install `ocramius/ocra-cached-view-resolver` is through
php composer.phar require ocramius/ocra-cached-view-resolver:3.0.*
```

If you use legacy/outdated PHP versions, such as `5.3.x` and `5.4.x`, you can use any
[`1.x`](https://github.com/Ocramius/OcraCachedViewResolver/tree/1.1.0) version
If you use legacy/outdated PHP versions, such as `5.5.x` and `5.6.x`, you can use any
[`3.x`](https://github.com/Ocramius/OcraCachedViewResolver/tree/3.0.0) version
of `ocramius/ocra-cached-view-resolver`.

You can then enable the module in your `config/application.config.php` by adding
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
}
],
"require": {
"php": "~5.5|~7.0",
"zendframework/zend-servicemanager": "~2.3",
"zendframework/zend-mvc": "~2.3",
"zendframework/zend-view": "~2.3",
"zendframework/zend-cache": "~2.3",
"zendframework/zend-config": "~2.3"
"php": "~7.0",
"zendframework/zend-servicemanager": "^3.1.0",
"zendframework/zend-mvc": "^3.0",
"zendframework/zend-view": "^2.7",
"zendframework/zend-cache": "^2.7.1",
"zendframework/zend-config": "^2.6"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0",
"zendframework/zendframework": "2.*"
"phpunit/phpunit": "^5.4.2",
"squizlabs/php_codesniffer": "~2.6.1"
},
"autoload": {
"psr-0": {
Expand All @@ -42,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
"dev-master": "4.1.x-dev"
}
}
}
24 changes: 10 additions & 14 deletions src/OcraCachedViewResolver/Compiler/TemplateMapCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ class TemplateMapCompiler
* @param ResolverInterface $resolver
*
* @return array
*
* @throws \Zend\View\Exception\DomainException
*/
public function compileMap(ResolverInterface $resolver)
public function compileMap(ResolverInterface $resolver) : array
{
if ($resolver instanceof AggregateResolver) {
return $this->compileFromAggregateResolver($resolver);
Expand All @@ -64,12 +66,7 @@ public function compileMap(ResolverInterface $resolver)
return [];
}

/**
* @param AggregateResolver $resolver
*
* @return array
*/
protected function compileFromAggregateResolver(AggregateResolver $resolver)
protected function compileFromAggregateResolver(AggregateResolver $resolver) : array
{
$map = [];

Expand All @@ -85,8 +82,10 @@ protected function compileFromAggregateResolver(AggregateResolver $resolver)
* @param TemplatePathStack $resolver
*
* @return array
*
* @throws \Zend\View\Exception\DomainException
*/
protected function compileFromTemplatePathStack(TemplatePathStack $resolver)
protected function compileFromTemplatePathStack(TemplatePathStack $resolver) : array
{
$map = [];

Expand All @@ -105,12 +104,7 @@ protected function compileFromTemplatePathStack(TemplatePathStack $resolver)
return $map;
}

/**
* @param TemplateMapResolver $resolver
*
* @return array
*/
protected function compileFromTemplateMapResolver(TemplateMapResolver $resolver)
protected function compileFromTemplateMapResolver(TemplateMapResolver $resolver) : array
{
return $resolver->getMap();
}
Expand All @@ -124,6 +118,8 @@ protected function compileFromTemplateMapResolver(TemplateMapResolver $resolver)
* @param TemplatePathStack $resolver
*
* @return void
*
* @throws \Zend\View\Exception\DomainException
*/
private function addResolvedPath(SplFileInfo $file, array & $map, $basePath, TemplatePathStack $resolver)
{
Expand Down
17 changes: 12 additions & 5 deletions src/OcraCachedViewResolver/Factory/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

namespace OcraCachedViewResolver\Factory;

use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Interop\Container\Exception\NotFoundException;
use OcraCachedViewResolver\Module;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Cache\Exception\InvalidArgumentException;
use Zend\Cache\Storage\StorageInterface;
use Zend\Cache\StorageFactory;

/**
Expand All @@ -30,14 +33,18 @@
* @author Marco Pivetta <[email protected]>
* @license MIT
*/
final class CacheFactory implements FactoryInterface
final class CacheFactory
{
/**
* {@inheritDoc}
*
* @throws InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container) : StorageInterface
{
$config = $serviceLocator->get('Config');
$config = $container->get('Config');

return StorageFactory::factory($config[Module::CONFIG][Module::CONFIG_CACHE_DEFINITION]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

namespace OcraCachedViewResolver\Factory;

use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Interop\Container\Exception\NotFoundException;
use OcraCachedViewResolver\Module;
use OcraCachedViewResolver\View\Resolver\CachingMapResolver;
use OcraCachedViewResolver\View\Resolver\LazyResolver;
use Zend\ServiceManager\DelegatorFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;
use Zend\View\Resolver\AggregateResolver;
use Zend\View\Resolver\ResolverInterface;

/**
* Factory responsible of building a {@see \Zend\View\Resolver\TemplateMapResolver}
Expand All @@ -38,12 +41,19 @@ final class CompiledMapResolverDelegatorFactory implements DelegatorFactoryInter
* {@inheritDoc}
*
* @return AggregateResolver
*
* @throws ContainerException
* @throws NotFoundException
*/
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
{
$config = $serviceLocator->get('Config')[Module::CONFIG];
public function __invoke(
ContainerInterface $container,
$name,
callable $callback,
array $options = null
) : ResolverInterface {
$config = $container->get('Config')[Module::CONFIG];
/* @var $cache \Zend\Cache\Storage\StorageInterface */
$cache = $serviceLocator->get($config[Module::CONFIG_CACHE_SERVICE]);
$cache = $container->get($config[Module::CONFIG_CACHE_SERVICE]);

$resolver = new AggregateResolver();

Expand Down
2 changes: 1 addition & 1 deletion src/OcraCachedViewResolver/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class Module implements ConfigProviderInterface
/**
* {@inheritDoc}
*/
public function getConfig()
public function getConfig() : array
{
return [
self::CONFIG => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class InvalidResolverInstantiatorException extends InvalidArgumentExceptio
*
* @return self
*/
public static function fromInvalidInstantiator($instantiator)
public static function fromInvalidInstantiator($instantiator) : self
{
return new self(sprintf(
'Invalid instantiator given, expected `callable`, `%s` given.',
Expand All @@ -47,7 +47,7 @@ public static function fromInvalidInstantiator($instantiator)
*
* @return self
*/
public static function fromInvalidResolver($resolver)
public static function fromInvalidResolver($resolver) : self
{
return new self(sprintf(
'Invalid resolver found, expected `' . ResolverInterface::class . '`, `%s` given.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function setUp()
/**
* @covers \OcraCachedViewResolver\Compiler\TemplateMapCompiler::compileMap
* @covers \OcraCachedViewResolver\Compiler\TemplateMapCompiler::compileFromTemplatePathStack
*
* @throws \Zend\View\Exception\InvalidArgumentException
*/
public function testCompileFromTemplatePathStack()
{
Expand All @@ -61,10 +63,10 @@ public function testCompileFromTemplatePathStack()
$template2 = realpath(__DIR__ . '/_files/subdir2/template2.phtml');
$template4 = realpath(__DIR__ . '/_files/subdir1/valid/template4.phtml');

$this->assertInternalType('string', $template2);
$this->assertInternalType('string', $template4);
self::assertInternalType('string', $template2);
self::assertInternalType('string', $template4);

$this->assertSame(
self::assertSame(
[
'template2' => $template2,
'valid/template4' => $template4,
Expand All @@ -76,14 +78,16 @@ public function testCompileFromTemplatePathStack()
/**
* @covers \OcraCachedViewResolver\Compiler\TemplateMapCompiler::compileMap
* @covers \OcraCachedViewResolver\Compiler\TemplateMapCompiler::compileFromTemplatePathStack
*
* @throws \Zend\View\Exception\InvalidArgumentException
*/
public function testCompileFromTemplatePathStackWithDifferentPaths()
{
$template2 = realpath(__DIR__ . '/_files/subdir1/template2.phtml');
$template4 = realpath(__DIR__ . '/_files/subdir1/valid/template4.phtml');

$this->assertInternalType('string', $template2);
$this->assertInternalType('string', $template4);
self::assertInternalType('string', $template2);
self::assertInternalType('string', $template4);

// inverse directory order
$resolver = new TemplatePathStack();
Expand All @@ -92,8 +96,8 @@ public function testCompileFromTemplatePathStackWithDifferentPaths()

$map = $this->compiler->compileMap($resolver);

$this->assertCount(2, $map);
$this->assertSame($template2, $map['template2']);
$this->assertSame($template4, $map['valid/template4']);
self::assertCount(2, $map);
self::assertSame($template2, $map['template2']);
self::assertSame($template4, $map['valid/template4']);
}
}
Loading

0 comments on commit 1e1bd07

Please sign in to comment.