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

Commit

Permalink
Merging develop to master in preparation for 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 12, 2016
2 parents bb8a75c + e8556b6 commit 62fd405
Show file tree
Hide file tree
Showing 28 changed files with 1,854 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
env:
global:
- TESTS_ZEND_CACHE_APC_ENABLED: true
- TESTS_ZEND_CACHE_APCU_ENABLED=true
- TESTS_ZEND_CACHE_MEMCACHED_ENABLED: true
- TESTS_ZEND_CACHE_MEMCACHED_HOST: "127.0.0.1"
- TESTS_ZEND_CACHE_MEMCACHED_PORT: 11211
Expand Down Expand Up @@ -72,6 +73,7 @@ matrix:
- INSTALL_XCACHE=true
- php: 7
env:
- EXECUTE_TEST_COVERALLS=true
- PECL_INSTALL_APCU='apcu'
- PECL_INSTALL_APCU_BC='apcu_bc-beta'
- php: 7
Expand Down
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@

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

## 2.7.0 - TBD

### Added

- [#23](https://github.com/zendframework/zend-cache/issues/23)
[#47](https://github.com/zendframework/zend-cache/issues/47)
Added an Apcu storage adapter as future replacement for Apc
- [#63](https://github.com/zendframework/zend-cache/pull/63)
Implemented ClearByNamespaceInterface in Stoage\Adapter\Redis
- [#94](https://github.com/zendframework/zend-cache/pull/94) adds factories for
each of the `PatternPluginManager`, `AdapterPluginManager`, and storage
`PluginManager`.
- [#94](https://github.com/zendframework/zend-cache/pull/94) exposes the package
as a standalone config-provider / ZF component, by adding:
- `Zend\Cache\ConfigProvider`, which enables the
`StorageCacheAbstractServiceFactory`, and maps factories for all plugin
managers.
- `Zend\Cache\Module`, which does the same, for zend-mvc contexts.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#94](https://github.com/zendframework/zend-cache/pull/94) updates the
`PatternPluginManager` to accept `$options` to `get()` and `build()`, cast
them to a `PatternOptions` instance, and inject them into the generated plugin
instance. This change allows better standalone usage of the plugin manager.
- [#94](https://github.com/zendframework/zend-cache/pull/94) updates the
`StorageCacheFactory` and `StorageCacheAbstractServiceFactory` to seed the
`StorageFactory` with the storage plugin manager and/or adapter plugin manager
as pulled from the provided container, if present. This change enables re-use
of pre-configured plugin managers (e.g., those seeded with custom plugins
and/or adapters).

## 2.6.2 - TBD

### Added
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
"zendframework/zend-serializer": "^2.6",
"zendframework/zend-session": "^2.6.2",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
"phpunit/phpunit": "^4.5"
},
"suggest": {
"zendframework/zend-serializer": "Zend\\Serializer component",
"zendframework/zend-session": "Zend\\Session component",
"ext-apcu": "APCU, to use the APC storage adapter",
"ext-apc": "APC or compatible extension, to use the APC storage adapter",
"ext-apcu": "APCU >= 5.1.0, to use the APCu storage adapter",
"ext-dba": "DBA, to use the DBA storage adapter",
"ext-memcache": "Memcache >= 2.0.0 to use the Memcache storage adapter",
"ext-memcached": "Memcached >= 1.0.0 to use the Memcached storage adapter",
Expand All @@ -43,6 +44,10 @@
"branch-alias": {
"dev-master": "2.6-dev",
"dev-develop": "2.7-dev"
},
"zf": {
"component": "Zend\\Cache",
"config-provider": "Zend\\Cache\\ConfigProvider"
}
},
"autoload-dev": {
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./test/bootstrap.php"
bootstrap="./vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="zend-cache Test Suite">
Expand Down Expand Up @@ -35,6 +35,7 @@
constants appropriate to the component you are migrating. -->

<env name="TESTS_ZEND_CACHE_APC_ENABLED" value="false" />
<env name="TESTS_ZEND_CACHE_APCU_ENABLED" value="false" />
<env name="TESTS_ZEND_CACHE_XCACHE_ENABLED" value="false" />
<env name="TESTS_ZEND_CACHE_XCACHE_ADMIN_AUTH" value="false" />
<env name="TESTS_ZEND_CACHE_XCACHE_ADMIN_USER" value="" />
Expand Down
42 changes: 42 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* @link http://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache;

class ConfigProvider
{
/**
* Return default configuration for zend-cache.
*
* @return array
*/
public function __invoke()
{
return [
'dependencies' => $this->getDependencyConfig(),
];
}

/**
* Return default service mappings for zend-cache.
*
* @return array
*/
public function getDependencyConfig()
{
return [
'abstract_factories' => [
Service\StorageCacheAbstractServiceFactory::class,
],
'factories' => [
PatternPluginManager::class => Service\PatternPluginManagerFactory::class,
Storage\AdapterPluginManager::class => Service\StorageAdapterPluginManagerFactory::class,
Storage\PluginManager::class => Service\StoragePluginManagerFactory::class,
],
];
}
}
24 changes: 24 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @link http://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache;

class Module
{
/**
* Return default zend-cache configuration for zend-mvc context.
*
* @return array
*/
public function getConfig()
{
$provider = new ConfigProvider();
return [
'service_manager' => $provider->getDependencyConfig(),
];
}
}
15 changes: 8 additions & 7 deletions src/PatternFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ abstract class PatternFactory
*/
public static function factory($patternName, $options = [])
{
if ($options instanceof Pattern\PatternOptions) {
$options = $options->toArray();
}

if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (is_array($options)) {
$options = new Pattern\PatternOptions($options);
} elseif (!$options instanceof Pattern\PatternOptions) {

if (! is_array($options)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array, Traversable object, or %s\Pattern\PatternOptions object; received "%s"',
__METHOD__,
Expand All @@ -47,13 +50,11 @@ public static function factory($patternName, $options = [])
}

if ($patternName instanceof Pattern\PatternInterface) {
$patternName->setOptions($options);
$patternName->setOptions(new Pattern\PatternOptions($options));
return $patternName;
}

$pattern = static::getPluginManager()->get($patternName);
$pattern->setOptions($options);
return $pattern;
return static::getPluginManager()->get($patternName, $options);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions src/PatternPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,38 @@ class PatternPluginManager extends AbstractPluginManager
*/
protected $instanceOf = Pattern\PatternInterface::class;

/**
* Override get to inject options as PatternOptions instance.
*
* {@inheritDoc}
*/
public function get($plugin, array $options = [], $usePeeringServiceManagers = true)
{
if (empty($options)) {
return parent::get($plugin, [], $usePeeringServiceManagers);
}

$plugin = parent::get($plugin, [], $usePeeringServiceManagers);
$plugin->setOptions(new Pattern\PatternOptions($options));
return $plugin;
}

/**
* Override build to inject options as PatternOptions instance.
*
* {@inheritDoc}
*/
public function build($plugin, array $options = null)
{
if (empty($options)) {
return parent::build($plugin);
}

$plugin = parent::build($plugin);
$plugin->setOptions(new Pattern\PatternOptions($options));
return $plugin;
}

/**
* Validate the plugin is of the expected type (v3).
*
Expand Down
54 changes: 54 additions & 0 deletions src/Service/PatternPluginManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* @link http://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache\Service;

use Interop\Container\ContainerInterface;
use Zend\Cache\PatternPluginManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class PatternPluginManagerFactory implements FactoryInterface
{
/**
* zend-servicemanager v2 support for invocation options.
*
* @param array
*/
protected $creationOptions;

/**
* {@inheritDoc}
*
* @return PatternPluginManager
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
return new PatternPluginManager($container, $options ?: []);
}

/**
* {@inheritDoc}
*
* @return PatternPluginManager
*/
public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null)
{
return $this($container, $requestedName ?: PatternPluginManager::class, $this->creationOptions);
}

/**
* zend-servicemanager v2 support for invocation options.
*
* @param array $options
* @return void
*/
public function setCreationOptions(array $options)
{
$this->creationOptions = $options;
}
}
62 changes: 62 additions & 0 deletions src/Service/PluginManagerLookupTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @link http://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache\Service;

use Interop\Container\ContainerInterface;
use Zend\Cache\StorageFactory;
use Zend\Cache\Storage\AdapterPluginManager;
use Zend\Cache\Storage\PluginManager;

trait PluginManagerLookupTrait
{
/**
* Prepare the storage factory with the adapter and plugins plugin managers.
*
* @param ContainerInterface $container
* @return void
*/
private function prepareStorageFactory(ContainerInterface $container)
{
StorageFactory::setAdapterPluginManager($this->lookupStorageAdapterPluginManager($container));
StorageFactory::setPluginManager($this->lookupStoragePluginManager($container));
}

/**
* Lookup the storage adapter plugin manager.
*
* Returns the Zend\Cache\Storage\AdapterPluginManager service if present,
* or creates a new instance otherwise.
*
* @param ContainerInterface $container
* @return AdapterPluginManager
*/
private function lookupStorageAdapterPluginManager(ContainerInterface $container)
{
if ($container->has(AdapterPluginManager::class)) {
return $container->get(AdapterPluginManager::class);
}
return new AdapterPluginManager($container);
}

/**
* Lookup the storage plugins plugin manager.
*
* Returns the Zend\Cache\Storage\PluginManager service if present, or
* creates a new instance otherwise.
*
* @param ContainerInterface $container
* @return PluginManager
*/
private function lookupStoragePluginManager(ContainerInterface $container)
{
if ($container->has(PluginManager::class)) {
return $container->get(PluginManager::class);
}
return new PluginManager($container);
}
}
Loading

0 comments on commit 62fd405

Please sign in to comment.