1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* Auth Module Bootstrap |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
7
|
|
|
* @license MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Auth; |
11
|
|
|
|
12
|
|
|
use Auth\Listener\SocialProfilesUnconfiguredErrorListener; |
13
|
|
|
use Core\Asset\AssetProviderInterface; |
14
|
|
|
use Core\ModuleManager\ModuleConfigLoader; |
15
|
|
|
use Zend\Mvc\MvcEvent; |
16
|
|
|
use Auth\Listener\TokenListener; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Bootstrap class of the Auth module |
20
|
|
|
*/ |
21
|
|
|
class Module implements AssetProviderInterface |
22
|
|
|
{ |
23
|
|
|
public function init(\Zend\ModuleManager\ModuleManagerInterface $moduleManager) |
24
|
|
|
{ |
25
|
|
|
if (\Zend\Console\Console::isConsole()) { |
26
|
|
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$eventManager = $moduleManager->getEventManager()->getSharedManager(); |
30
|
|
|
$tokenListener = new TokenListener(); |
31
|
|
|
$tokenListener->attachShared($eventManager); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
/** |
34
|
|
|
* Loads module specific configuration. |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function getConfig() |
39
|
|
|
{ |
40
|
|
|
return ModuleConfigLoader::load(__DIR__ . '/../../config'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Loads module specific autoloader configuration. |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public function getAutoloaderConfig() |
49
|
|
|
{ |
50
|
|
|
return array( |
51
|
|
|
'Zend\Loader\ClassMapAutoloader' => array( |
52
|
|
|
// This is an hack due to bad design of Hybridauth |
53
|
|
|
// This ensures the class from "addtional-providers" is loaded. |
54
|
|
|
array( |
55
|
|
|
'Hybrid_Providers_XING' |
56
|
|
|
=> __DIR__ . '/../../vendor/hybridauth/hybridauth/additional-providers/hybridauth-xing/Providers/XING.php', |
57
|
|
|
), |
58
|
|
|
array( |
59
|
|
|
'Hybrid_Providers_Github' |
60
|
|
|
=> __DIR__ . '/../../vendor/hybridauth/hybridauth/additional-providers/hybridauth-github/Providers/GitHub.php', |
61
|
|
|
), |
62
|
|
|
), |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function onBootstrap(MvcEvent $e) |
67
|
|
|
{ |
68
|
|
|
if (\Zend\Console\Console::isConsole()) { |
69
|
|
|
return; |
70
|
|
|
} |
71
|
|
|
$eventManager = $e->getApplication()->getEventManager(); |
72
|
|
|
$services = $e->getApplication()->getServiceManager(); |
73
|
|
|
|
74
|
|
|
$eventManager->attach( |
75
|
|
|
MvcEvent::EVENT_ROUTE, |
76
|
|
|
function (MvcEvent $e) use ($services) { |
77
|
|
|
/* @var $checkPermissionsListener \Acl\Listener\CheckPermissionsListener */ |
78
|
|
|
$checkPermissionsListener = $services->get('Auth/CheckPermissionsListener'); |
79
|
|
|
$checkPermissionsListener->onRoute($e); |
80
|
|
|
}, |
81
|
|
|
-10 |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$eventManager->attach( |
85
|
|
|
MvcEvent::EVENT_DISPATCH, |
86
|
|
|
function (MvcEvent $e) use ($services) { |
87
|
|
|
/** @var CheckPermissionsListener $checkPermissionsListener */ |
88
|
|
|
$checkPermissionsListener = $services->get('Auth/CheckPermissionsListener'); |
89
|
|
|
$checkPermissionsListener->onDispatch($e); |
90
|
|
|
}, |
91
|
|
|
10 |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$unauthorizedAccessListener = $services->get('UnauthorizedAccessListener'); |
95
|
|
|
$unauthorizedAccessListener->attach($eventManager); |
96
|
|
|
|
97
|
|
|
$deactivatedUserListener = $services->get('DeactivatedUserListener'); |
98
|
|
|
$deactivatedUserListener->attach($eventManager); |
99
|
|
|
|
100
|
|
|
$socialProfilesUnconfiguredErrorListener = new SocialProfilesUnconfiguredErrorListener(); |
101
|
|
|
$socialProfilesUnconfiguredErrorListener->attach($eventManager); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getPublicDir() |
105
|
|
|
{ |
106
|
|
|
return realpath(__DIR__.'/../../public'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: