Permalink
Browse files

guards are now ListenerAggregateInterfaces

  • Loading branch information...
bjyoungblood committed Sep 17, 2012
1 parent 02614bf commit 36db670e2b0942964ce21fe657e067f5804124be
View
@@ -2,11 +2,11 @@
namespace BjyAuthorize;
+use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
-use Zend\EventManager\EventInterface;
class Module implements
AutoloaderProviderInterface,
@@ -4,15 +4,22 @@
use BjyAuthorize\Provider\Rule\ProviderInterface as RuleProviderInterface;
use BjyAuthorize\Provider\Resource\ProviderInterface as ResourceProviderInterface;
-use Zend\Permissions\Acl\Resource\GenericResource;
+
+use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\MvcEvent;
+use Zend\Permissions\Acl\Resource\GenericResource;
-class Controller implements RuleProviderInterface, ResourceProviderInterface
+class Controller implements GuardInterface, RuleProviderInterface, ResourceProviderInterface
{
protected $securityService;
protected $rules = array();
+ /**
+ * @var \Zend\Stdlib\CallbackHandler[]
+ */
+ protected $listeners = array();
+
public function __construct(array $rules, $security)
{
$this->securityService = $security;
@@ -28,6 +35,20 @@ public function __construct(array $rules, $security)
}
}
+ public function attach(EventManagerInterface $events)
+ {
+ $this->listeners[] = $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute'), -1000);
+ }
+
+ public function detach(EventManagerInterface $events)
+ {
+ foreach ($this->listeners as $index => $listener) {
+ if ($events->detach($listener)) {
+ unset($this->listeners[$index]);
+ }
+ }
+ }
+
public function getResources()
{
$resources = array();
@@ -1,8 +1,15 @@
<?php
-namespace BjyAuthorize\Acl\Guard;
+namespace BjyAuthorize\Guard;
-interface GuardInterface
+use Zend\EventManager\EventManagerInterface;
+use Zend\EventManager\ListenerAggregateInterface;
+
+interface GuardInterface extends ListenerAggregateInterface
{
public function getResources();
+
+ public function attach(EventManagerInterface $events);
+
+ public function detach(EventManagerInterface $events);
}
@@ -4,12 +4,12 @@
use BjyAuthorize\Provider\Rule\ProviderInterface as RuleProviderInterface;
use BjyAuthorize\Provider\Resource\ProviderInterface as ResourceProviderInterface;
-use Zend\Permissions\Acl\Resource\GenericResource;
-use Zend\Mvc\MvcEvent;
+
use Zend\EventManager\EventManagerInterface;
-use Zend\EventManager\ListenerAggregateInterface;
+use Zend\Mvc\MvcEvent;
+use Zend\Permissions\Acl\Resource\GenericResource;
-class Route implements RuleProviderInterface, ResourceProviderInterface, ListenerAggregateInterface
+class Route implements GuardInterface, RuleProviderInterface, ResourceProviderInterface
{
protected $securityService;

0 comments on commit 36db670

Please sign in to comment.