Passed
Push — master ( 59847d...680f54 )
by Abdul Malik
49s queued 11s
created

Module::getModuleDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
10
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
 *
18
 * This software consists of voluntary contributions made by many individuals
19
 * and is licensed under the MIT license.
20
 */
21
22
namespace SanSessionToolbar;
23
24
use Zend\EventManager\EventInterface;
25
use Zend\ModuleManager\Feature\ConfigProviderInterface;
26
use Zend\Mvc\Controller\AbstractActionController;
27
use Zend\Mvc\MvcEvent;
28
use Zend\Session\Container;
29
use Zend\Stdlib\SplQueue;
30
31
/**
32
 * @author Abdul Malik Ikhsan <[email protected]>
33
 */
34
class Module implements ConfigProviderInterface
35
{
36
    /**
37
     * Bootstrap Handle FlashMessenger session show.
38
     */
39
    public function onBootstrap(MvcEvent $e)
40 16
    {
41
        $manager = Container::getDefaultManager();
42 16
        if (!$manager->sessionExists()) {
43 16
            return;
44 2
        }
45
46
        $app = $e->getApplication();
47 14
        /** @var \Zend\EventManager\SharedEventManagerInterface $sharedEvm */
48
        $sharedEvm = $app->getEventManager()->getSharedManager();
49 14
50
        $sharedEvm->attach(
51 14
            AbstractActionController::class,
52 14
            'dispatch',
53 14
            [$this, 'flashMessengerHandler'],
54 14
            2
55 14
        );
56
    }
57 14
58
    /**
59
     * Used to duplicate flashMessenger data as it shown and gone.
60
     */
61
    private function duplicateFlashMessengerSessionData(Container $container) : void
62 13
    {
63
        $flashToolbarContainer = new Container('SanSessionToolbarFlashMessenger');
64 13
        foreach ($container->getArrayCopy() as $key => $row) {
65 13
            foreach ($row->toArray() as $keyArray => $rowArray) {
66 1
                if ($keyArray === 0) {
67 1
                    $flashToolbarContainer->$key = new SplQueue();
68 1
                }
69
                $flashToolbarContainer->$key->push($rowArray);
70 1
            }
71
        }
72
    }
73 13
74
    /**
75
     * Handle FlashMessenger data to be able to be seen in both "app" and toolbar parts.
76
     */
77
    public function flashMessengerHandler(EventInterface $e) : void
78 14
    {
79
        /** @var \Zend\Mvc\Controller\AbstractActionController $controller */
80
        $controller = $e->getTarget();
81 14
        if (!$controller->getPluginManager()->has('flashMessenger')) {
82 14
            return;
83 1
        }
84
85
        $flash = $controller->plugin('flashMessenger');
86 13
        $container = $flash->getContainer();
0 ignored issues
show
Bug introduced by
The method getContainer() does not seem to exist on object<Zend\Stdlib\DispatchableInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87 13
        $this->duplicateFlashMessengerSessionData($container);
88 13
    }
89 13
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getConfig() : array
94 13
    {
95
        return include __DIR__.'/../config/module.config.php';
96 13
    }
97
}
98