/
Module.php
executable file
·108 lines (97 loc) · 4.38 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace BgOauthProvider;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\Mvc\Controller\ControllerManager;
use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceLocatorInterface;
class Module implements AutoloaderProviderInterface, ServiceProviderInterface
{
public function onBootstrap(MvcEvent $event)
{
$app = $event->getApplication();
$events = $app->getEventManager();
$sm = $app->getServiceManager();
$events->attach($sm->get('BgOauthProvider\RouteGuard'));
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'factories' => array(
'BgOauthProvider\Options' => function (ServiceLocatorInterface $serviceLocator) {
$config = $serviceLocator->get('Config');
return new Options\ModuleOptions(isset($config['bgoauthprovider']) ? $config['bgoauthprovider'] : array());
},
'BgOauthProvider\Mapper\AppNonce' => function (ServiceLocatorInterface $serviceLocator) {
return new \BgOauthProvider\Mapper\Doctrine\AppNonce(
$serviceLocator->get('doctrine.entitymanager.orm_default')
);
},
'BgOauthProvider\Mapper\Token' => function (ServiceLocatorInterface $serviceLocator) {
return new \BgOauthProvider\Mapper\Doctrine\Token(
$serviceLocator->get('doctrine.entitymanager.orm_default')
);
},
'BgOauthProvider\Mapper\App' => function (ServiceLocatorInterface $serviceLocator) {
return new \BgOauthProvider\Mapper\Doctrine\App(
$serviceLocator->get('doctrine.entitymanager.orm_default')
);
},
'BgOauthProvider\OauthService' => function (ServiceLocatorInterface $serviceLocator) {
return new \BgOauthProvider\Service\Oauth(
$serviceLocator->get('BgOauthProvider\Mapper\AppNonce'),
$serviceLocator->get('BgOauthProvider\Mapper\Token'),
$serviceLocator->get('BgOauthProvider\Mapper\App')
);
},
'BgOauthProvider\OauthProvider' => function (ServiceLocatorInterface $serviceLocator) {
return new \BgOauthProvider\Oauth\Provider(
$serviceLocator->get('BgOauthProvider\OauthService')
);
},
'BgOauthProvider\Acl' => function (ServiceLocatorInterface $serviceLocator) {
$aclConfig = $serviceLocator->get('BgOauthProvider\Options')->getAclConfig();
return new \BgOauthProvider\Acl($aclConfig);
},
'BgOauthProvider\RouteGuard' => function (ServiceLocatorInterface $serviceLocator) {
return new \BgOauthProvider\Guard\Route(
$serviceLocator->get('BgOauthProvider\Acl'),
$serviceLocator->get('BgOauthProvider\OauthProvider')
);
},
)
);
}
public function getControllerConfig()
{
return array(
'factories' => array(
'BgOauthProvider\Controller\Oauth' => function (ControllerManager $controllerManager) {
$serviceManager = $controllerManager->getServiceLocator();
return new \BgOauthProvider\Controller\OauthController(
$serviceManager->get('BgOauthProvider\OauthService'),
$serviceManager->get('BgOauthProvider\OauthProvider'),
$serviceManager->get('BgOauthProvider\Options')
);
}
),
);
}
}