This repository has been archived by the owner on May 14, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CS fixes and cleanup of the service class
- Loading branch information
Showing
9 changed files
with
165 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.