Completed
Push — develop ( 1e35f6...3ea9f1 )
by Mathias
17s
created

Module::getPublicDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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);
0 ignored issues
show
Bug introduced by
It seems like $eventManager defined by $moduleManager->getEvent...r()->getSharedManager() on line 29 can be null; however, Auth\Listener\TokenListener::attachShared() does not accept null, maybe add an additional type check?

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:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
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