This repository has been archived by the owner on Dec 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathModule.php
51 lines (42 loc) · 1.46 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
<?php
namespace JwPersistentUser;
use JwPersistentUser\Listener\WriteTokenToCookie;
use JwPersistentUser\Service\CookieAuthenticationService;
use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManager;
use Zend\ModuleManager\Feature;
use Zend\ServiceManager\ServiceManager;
class Module implements
Feature\ConfigProviderInterface,
Feature\BootstrapListenerInterface,
Feature\AutoloaderProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function onBootstrap(EventInterface $e)
{
/** @var EventManager $em */
$em = $e->getApplication()->getEventManager();
/** @var ServiceManager $sm */
$sm = $e->getApplication()->getServiceManager();
$request = $e->getApplication()->getRequest();
$response = $e->getApplication()->getResponse();
// Try to login from Cookie if applicable
$service = new CookieAuthenticationService($sm);
$service->setEventManager(new EventManager($em->getSharedManager()));
$service->loginFrom($request, $response);
(new WriteTokenToCookie($sm))->attachShared($em->getSharedManager());
}
public function getAutoloaderConfig()
{
return [
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
],
],
];
}
}