Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 29, 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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"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",
Expand All @@ -44,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
2 changes: 1 addition & 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
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);
}
}
54 changes: 54 additions & 0 deletions src/Service/StorageAdapterPluginManagerFactory.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\Storage\AdapterPluginManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

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

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

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

/**
* zend-servicemanager v2 support for invocation options.
*
* @param array $options
* @return void
*/
public function setCreationOptions(array $options)
{
$this->creationOptions = $options;
}
}
6 changes: 5 additions & 1 deletion src/Service/StorageCacheAbstractServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@

namespace Zend\Cache\Service;

use Interop\Container\ContainerInterface;
use Zend\Cache\StorageFactory;
use Zend\ServiceManager\AbstractFactoryInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Storage cache factory for multiple caches.
*/
class StorageCacheAbstractServiceFactory implements AbstractFactoryInterface
{
use PluginManagerLookupTrait;

/**
* @var array
*/
Expand Down Expand Up @@ -66,6 +68,8 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$this->prepareStorageFactory($container);

$config = $this->getConfig($container);
return StorageFactory::factory($config[$requestedName]);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Service/StorageCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@

namespace Zend\Cache\Service;

use Interop\Container\ContainerInterface;
use Zend\Cache\Storage\StorageInterface;
use Zend\Cache\StorageFactory;
use Zend\ServiceManager\FactoryInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Storage cache factory.
*/
class StorageCacheFactory implements FactoryInterface
{
use PluginManagerLookupTrait;

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$this->prepareStorageFactory($container);

$config = $container->get('config');
$cacheConfig = isset($config['cache']) ? $config['cache'] : [];
return StorageFactory::factory($cacheConfig);
Expand Down
Loading