Пример #1
0
 public function createService(ServiceLocatorInterface $services)
 {
     $config = $services->get(ConfigServiceFactory::SERVICE)->get('access');
     if ($config->offsetExists('type')) {
         $key = strtolower($config->get('type'));
         $class = array_key_exists($key, $this->types) ? $this->types[$key] : $config->get('type');
         if (!class_exists($class)) {
             throw new \Exception(sprintf("Invalid Access Service type (%s)", $class));
         }
         $access = new $class();
         if (!$access instanceof AbstractAccess) {
             throw new \Exception("Access Service must implement SporkTools\\Core\\Access\\AbstractAccess");
         }
     } else {
         $access = new DenyAccess();
     }
     $access->setServices($services);
     foreach ($config as $name => $value) {
         $method = 'set' . $name;
         if (method_exists($access, $method)) {
             if ($value instanceof Config) {
                 $value = $value->toArray();
             }
             call_user_func_array(array($access, $method), (array) $value);
         }
     }
     return $access;
 }
Пример #2
0
 public function testAuthorizeNegativeRedirectRoute()
 {
     $listener = new AccessListener();
     $access = new DenyAccess();
     $access->setAuthorizeRedirect('foo', true);
     $application = $this->getMockApplication(true, $access);
     $redirect = $application->getServiceManager()->get('controllerPluginManager')->get('redirect');
     $redirect->expects($this->once())->method('toRoute');
     $event = new MvcEvent();
     $event->setApplication($application);
     $event->setResponse(new Response());
     $response = $listener->authorize($event);
     $this->assertInstanceOf('Zend\\Http\\Response', $response);
     $this->assertEquals(302, $response->getStatusCode());
 }
Пример #3
0
 public function testIsAuthorized()
 {
     $deny = new DenyAccess();
     $this->assertFalse($deny->isAuthorized());
 }