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

Commit

Permalink
Remove cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Dec 2, 2013
1 parent 72b149a commit e747d91
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 287 deletions.
1 change: 0 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

'factories' => [
/* Factories that do not map to a class */
'ZfcRbac\Cache' => 'ZfcRbac\Factory\CacheFactory',
'ZfcRbac\Guards' => 'ZfcRbac\Factory\GuardsFactory',

/* Factories that map to a class */
Expand Down
51 changes: 0 additions & 51 deletions src/ZfcRbac/Factory/CacheFactory.php

This file was deleted.

5 changes: 1 addition & 4 deletions src/ZfcRbac/Factory/PermissionLoaderListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ class PermissionLoaderListenerFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var \Zend\Cache\Storage\StorageInterface $cacheStorage */
$cacheStorage = $serviceLocator->get('ZfcRbac\Cache');

/* @var \ZfcRbac\Permission\PermissionProviderPluginManager $pluginManager */
$pluginManager = $serviceLocator->get('ZfcRbac\Permission\PermissionProviderPluginManager');

/* @var \ZfcRbac\Permission\PermissionProviderChain $permissionProviderChain */
$permissionProviderChain = $pluginManager->get('ZfcRbac\Permission\PermissionProviderChain');

return new PermissionLoaderListener($permissionProviderChain, $cacheStorage);
return new PermissionLoaderListener($permissionProviderChain);
}
}
5 changes: 1 addition & 4 deletions src/ZfcRbac/Factory/RoleLoaderListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ class RoleLoaderListenerFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var \Zend\Cache\Storage\StorageInterface $cacheStorage */
$cacheStorage = $serviceLocator->get('ZfcRbac\Cache');

/* @var \ZfcRbac\Role\RoleProviderPluginManager $pluginManager */
$pluginManager = $serviceLocator->get('ZfcRbac\Role\RoleProviderPluginManager');

/** @var \ZfcRbac\Role\RoleProviderChain $roleProviderChain */
$roleProviderChain = $pluginManager->get('ZfcRbac\Role\RoleProviderChain');

return new RoleLoaderListener($roleProviderChain, $cacheStorage);
return new RoleLoaderListener($roleProviderChain);
}
}
28 changes: 0 additions & 28 deletions src/ZfcRbac/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ class ModuleOptions extends AbstractOptions
*/
protected $redirectStrategy;

/**
* Either a string fetched from service locator, or a StorageFactory compliant config
*
* @var string|array
*/
protected $cache;

/**
* Constructor
*
Expand Down Expand Up @@ -334,25 +327,4 @@ public function getRedirectStrategy()

return $this->redirectStrategy;
}

/**
* Set the cache config of key
*
* @param array|string $cache
* @return void
*/
public function setCache($cache)
{
$this->cache = $cache;
}

/**
* Get the cache config or key
*
* @return array|string
*/
public function getCache()
{
return $this->cache;
}
}
43 changes: 3 additions & 40 deletions src/ZfcRbac/Permission/PermissionLoaderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

namespace ZfcRbac\Permission;

use Zend\Cache\Storage\StorageInterface as CacheInterface;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use ZfcRbac\Service\RbacEvent;
Expand All @@ -33,31 +32,14 @@ class PermissionLoaderListener extends AbstractListenerAggregate
*/
protected $permissionProvider;

/**
* @var CacheInterface
*/
protected $cache;

/**
* @var string
*/
protected $cacheKey;

/**
* Constructor
*
* @param PermissionProviderInterface $permissionProvider
* @param CacheInterface $cache
* @param string $cacheKey
*/
public function __construct(
PermissionProviderInterface $permissionProvider,
CacheInterface $cache,
$cacheKey = 'zfc_rbac_permissions'
) {
public function __construct(PermissionProviderInterface $permissionProvider)
{
$this->permissionProvider = $permissionProvider;
$this->cache = $cache;
$this->cacheKey = (string) $cacheKey;
}

/**
Expand All @@ -77,7 +59,7 @@ public function attach(EventManagerInterface $events)
public function onLoadPermissions(RbacEvent $event)
{
$rbac = $event->getRbac();
$permissions = $this->getPermissions($event);
$permissions = $this->permissionProvider->getPermissions($event);

foreach ($permissions as $key => $value) {
if ($value instanceof PermissionInterface) {
Expand All @@ -97,23 +79,4 @@ public function onLoadPermissions(RbacEvent $event)
}
}
}

/**
* Get the permissions, optionally fetched from cache
*
* @param RbacEvent $event
* @return array|PermissionInterface[]
*/
protected function getPermissions(RbacEvent $event)
{
$success = false;
$result = $this->cache->getItem($this->cacheKey, $success);

if (!$success) {
$result = $this->permissionProvider->getPermissions($event);
$this->cache->setItem($this->cacheKey, $result);
}

return $result;
}
}
43 changes: 3 additions & 40 deletions src/ZfcRbac/Role/RoleLoaderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

namespace ZfcRbac\Role;

use Zend\Cache\Storage\StorageInterface as CacheInterface;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\Permissions\Rbac\RoleInterface;
Expand All @@ -34,31 +33,14 @@ class RoleLoaderListener extends AbstractListenerAggregate
*/
protected $roleProvider;

/**
* @var CacheInterface
*/
protected $cache;

/**
* @var string
*/
protected $cacheKey;

/**
* Constructor
*
* @param RoleProviderInterface $roleProvider
* @param CacheInterface $cache
* @param string $cacheKey
*/
public function __construct(
RoleProviderInterface $roleProvider,
CacheInterface $cache,
$cacheKey = 'zfc_rbac_roles'
) {
public function __construct(RoleProviderInterface $roleProvider)
{
$this->roleProvider = $roleProvider;
$this->cache = $cache;
$this->cacheKey = (string) $cacheKey;
}

/**
Expand All @@ -79,7 +61,7 @@ public function attach(EventManagerInterface $events)
public function onLoadRoles(RbacEvent $event)
{
$rbac = $event->getRbac();
$roles = $this->getRoles($event);
$roles = $this->roleProvider->getRoles($event);

foreach ($roles as $key => $value) {
if ($value instanceof RoleInterface) {
Expand All @@ -91,23 +73,4 @@ public function onLoadRoles(RbacEvent $event)
}
}
}

/**
* Get the roles, optionally fetched from cache
*
* @param RbacEvent $event
* @return string[]|array|RoleInterface[]
*/
protected function getRoles(RbacEvent $event)
{
$success = false;
$result = $this->cache->getItem($this->cacheKey, $success);

if (!$success) {
$result = $this->roleProvider->getRoles($event);
$this->cache->setItem($this->cacheKey, $result);
}

return $result;
}
}
66 changes: 0 additions & 66 deletions tests/ZfcRbacTest/Factory/CacheFactoryTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public function testFactory()

$serviceManager->setService('ZfcRbac\Permission\PermissionProviderPluginManager', $pluginManager);

$serviceManager->setService('ZfcRbac\Cache', $this->getMock('Zend\Cache\Storage\StorageInterface'));

$factory = new PermissionLoaderListenerFactory();
$listener = $factory->createService($serviceManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function testFactory()

$serviceManager = new ServiceManager();
$serviceManager->setService('ZfcRbac\Role\RoleProviderPluginManager', $pluginManager);
$serviceManager->setService('ZfcRbac\Cache', $this->getMock('Zend\Cache\Storage\StorageInterface'));

$factory = new RoleLoaderListenerFactory();
$listener = $factory->createService($serviceManager);
Expand Down
3 changes: 0 additions & 3 deletions tests/ZfcRbacTest/Options/ModuleOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function testAssertModuleDefaultOptions()
$this->assertInternalType('array', $moduleOptions->getPermissionProviders());
$this->assertInstanceOf('ZfcRbac\Options\UnauthorizedStrategyOptions', $moduleOptions->getUnauthorizedStrategy());
$this->assertInstanceOf('ZfcRbac\Options\RedirectStrategyOptions', $moduleOptions->getRedirectStrategy());
$this->assertNull($moduleOptions->getCache());
$this->assertFalse($moduleOptions->getForceReload());
}

Expand All @@ -59,7 +58,6 @@ public function testSettersAndGetters()
'redirect_strategy' => [
'redirect_to_route' => 'login'
],
'cache' => 'my_cache',
'force_reload' => true
]);

Expand All @@ -72,7 +70,6 @@ public function testSettersAndGetters()
$this->assertEquals([], $moduleOptions->getPermissionProviders());
$this->assertInstanceOf('ZfcRbac\Options\UnauthorizedStrategyOptions', $moduleOptions->getUnauthorizedStrategy());
$this->assertInstanceOf('ZfcRbac\Options\RedirectStrategyOptions', $moduleOptions->getRedirectStrategy());
$this->assertEquals('my_cache', $moduleOptions->getCache());
$this->assertTrue($moduleOptions->getForceReload());
}

Expand Down
Loading

0 comments on commit e747d91

Please sign in to comment.