Skip to content
This repository has been archived by the owner on May 14, 2018. It is now read-only.

Commit

Permalink
CS fixes and cleanup of the service class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Dec 19, 2012
1 parent 1e9fcc5 commit 5749d63
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 148 deletions.
128 changes: 6 additions & 122 deletions Module.php
@@ -1,123 +1,7 @@
<?php

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;

class Module implements
AutoloaderProviderInterface,
BootstrapListenerInterface,
ConfigProviderInterface,
ServiceProviderInterface
{
public function onBootstrap(EventInterface $e)
{
$app = $e->getTarget();
$config = $app->getConfig();
$sm = $app->getServiceManager();
$service = $sm->get('BjyAuthorize\Service\Authorize');
$strategy = $sm->get($config['bjyauthorize']['unauthorized_strategy']);

foreach ($service->getGuards() as $guard) {
$app->getEventManager()->attach($guard);
}

$app->getEventManager()->attach($strategy);
}

public function getServiceConfig()
{
return array(
'initializers' => array(
function ($instance, $sm) {
if ($instance instanceof Service\AuthorizeAwareInterface) {
$instance->setAuthorizeService($sm->get('BjyAuthorize\Service\Authorize'));
}
}
),
'factories' => array(
'BjyAuthorize\Service\Authorize' => 'BjyAuthorize\Service\AuthorizeFactory',

'BjyAuthorize\Provider\Identity\ZfcUserZendDb' => function ($sm) {
$adapter = $sm->get('zfcuser_zend_db_adapter');
$provider = new Provider\Identity\ZfcUserZendDb($adapter);
$provider->setUserService($sm->get('zfcuser_user_service'));
return $provider;
},

'BjyAuthorize\Provider\Identity\ZfcUserDoctrine' => function ($sm) {
$em = $sm->get('doctrine.entitymanager.orm_default');
$provider = new Provider\Identity\ZfcUserDoctrine($em);
$provider->setUserService($sm->get('zfcuser_user_service'));
return $provider;
},

'BjyAuthorize\View\UnauthorizedStrategy' => function ($sm) {
$template = $sm->get('BjyAuthorize\Service\Authorize')->getTemplate();
$strategy = new View\UnauthorizedStrategy;
$strategy->setTemplate($template);
return $strategy;
},

'BjyAuthorize\Provider\Role\ZendDb' => function ($sm) {
$provider = new Provider\Role\ZendDb;
$provider->setAdapter($sm->get('Zend\Db\Adapter\Adapter'));
return $provider;
},

'BjyAuthorize\Provider\Role\Doctrine' => function ($sm) {
$provider = new Provider\Role\Doctrine;
return $provider;
},
),
);
}

public function getViewHelperConfig()
{
return array(
'factories' => array(
'isAllowed' => function($sm) {
$sm = $sm->getServiceLocator(); // get the main SM instance
$helper = new View\Helper\IsAllowed();
$helper->setAuthorizeService($sm->get('BjyAuthorize\Service\Authorize'));
return $helper;
}
),
);
}

public function getControllerPluginConfig()
{
return array(
'factories' => array(
'isAllowed' => function($sm) {
$sm = $sm->getServiceLocator(); // get the main SM instance
$helper = new Controller\Plugin\IsAllowed();
$helper->setAuthorizeService($sm->get('BjyAuthorize\Service\Authorize'));
return $helper;
}
),
);
}

public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}

public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
/**
* This file is placed here for compatibility with ZendFramework 2's ModuleManager.
* It allows usage of this module even without composer.
* The original Module.php is in 'src/BjyAuthorize' in order to respect PSR-0
*/
require_once __DIR__ . '/src/BjyAuthorize/Module.php';
12 changes: 9 additions & 3 deletions config/services.config.php
Expand Up @@ -14,7 +14,10 @@
'initializers' => array(
function ($instance, ServiceLocatorInterface $serviceLocator) {
if ($instance instanceof Service\AuthorizeAwareInterface) {
$instance->setAuthorizeService($serviceLocator->get('BjyAuthorize\Service\Authorize'));
/* @var $authorize \BjyAuthorize\Service\Authorize */
$authorize = $serviceLocator->get('BjyAuthorize\Service\Authorize');

$instance->setAuthorizeService($authorize);
}
}
),
Expand All @@ -32,7 +35,7 @@ function ($instance, ServiceLocatorInterface $serviceLocator) {
},

'BjyAuthorize\Provider\Identity\ZfcUserDoctrine' => function (ServiceLocatorInterface $serviceLocator) {
/* @var $adapter \Doctrine\Common\Persistence\ObjectManager */
/* @var $objectManager \Doctrine\ORM\EntityManager */
$objectManager = $serviceLocator->get('doctrine.entitymanager.orm_default');
/* @var $userService \ZfcUser\Service\User */
$userService = $serviceLocator->get('zfcuser_user_service');
Expand All @@ -57,7 +60,10 @@ function ($instance, ServiceLocatorInterface $serviceLocator) {
},

'BjyAuthorize\Provider\Role\Doctrine' => function (ServiceLocatorInterface $serviceLocator) {
return new Provider\Role\Doctrine(array(), $serviceLocator);
/* @var $objectManager \Doctrine\ORM\EntityManager */
$objectManager = $serviceLocator->get('doctrine.entitymanager.orm_default');

return new Provider\Role\Doctrine(array(), $objectManager);
},
),
);
3 changes: 2 additions & 1 deletion src/BjyAuthorize/Acl/Role.php
Expand Up @@ -28,7 +28,7 @@ class Role implements RoleInterface
protected $parent;

/**
* @param string|null $roleId
* @param string|null $roleId
* @param RoleInterface|string|null $parent
*/
public function __construct($roleId = null, $parent = null)
Expand Down Expand Up @@ -57,6 +57,7 @@ public function getRoleId()
public function setRoleId($roleId)
{
$this->roleId = $roleId;

return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/BjyAuthorize/Guard/Route.php
Expand Up @@ -39,7 +39,7 @@ class Route implements GuardInterface, RuleProviderInterface, ResourceProviderIn
protected $listeners = array();

/**
* @param array $rules
* @param array $rules
* @param ServiceLocatorInterface $serviceLocator
*/
public function __construct(array $rules, ServiceLocatorInterface $serviceLocator)
Expand Down
3 changes: 2 additions & 1 deletion src/BjyAuthorize/Provider/Identity/ZfcUserZendDb.php
Expand Up @@ -9,7 +9,6 @@
namespace BjyAuthorize\Provider\Identity;

use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Sql;
use ZfcUser\Service\User;
Expand Down Expand Up @@ -89,6 +88,7 @@ public function getUserService()
public function setUserService($userService)
{
$this->userService = $userService;

return $this;
}

Expand All @@ -106,6 +106,7 @@ public function getDefaultRole()
public function setDefaultRole($defaultRole)
{
$this->defaultRole = $defaultRole;

return $this;
}
}
1 change: 0 additions & 1 deletion src/BjyAuthorize/Provider/Role/ZendDb.php
Expand Up @@ -9,7 +9,6 @@
namespace BjyAuthorize\Provider\Role;

use BjyAuthorize\Acl\Role;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Select;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand Down

0 comments on commit 5749d63

Please sign in to comment.