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\ModuleManager\Feature\DependencyIndicatorInterface; |
27
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
28
|
|
|
use Zend\Mvc\MvcEvent; |
29
|
|
|
use Zend\Session\Container; |
30
|
|
|
use Zend\Stdlib\SplQueue; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @author Abdul Malik Ikhsan <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class Module implements ConfigProviderInterface, DependencyIndicatorInterface |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* Bootstrap Handle FlashMessenger session show. |
39
|
|
|
*/ |
40
|
16 |
|
public function onBootstrap(MvcEvent $e) |
41
|
|
|
{ |
42
|
16 |
|
$manager = Container::getDefaultManager(); |
43
|
16 |
|
if (!$manager->sessionExists()) { |
44
|
2 |
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
14 |
|
$app = $e->getApplication(); |
48
|
14 |
|
$sharedEvm = $app->getEventManager()->getSharedManager(); |
49
|
|
|
|
50
|
14 |
|
$sharedEvm->attach( |
51
|
14 |
|
AbstractActionController::class, |
52
|
14 |
|
'dispatch', |
53
|
14 |
|
[$this, 'flashMessengerHandler'], |
54
|
14 |
|
2 |
55
|
|
|
); |
56
|
14 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Used to duplicate flashMessenger data as it shown and gone. |
60
|
|
|
*/ |
61
|
13 |
|
private function duplicateFlashMessengerSessionData(Container $container) : void |
62
|
|
|
{ |
63
|
13 |
|
$flashToolbarContainer = new Container('SanSessionToolbarFlashMessenger'); |
64
|
13 |
|
foreach ($container->getArrayCopy() as $key => $row) { |
65
|
1 |
|
foreach ($row->toArray() as $keyArray => $rowArray) { |
66
|
1 |
|
if ($keyArray === 0) { |
67
|
1 |
|
$flashToolbarContainer->$key = new SplQueue(); |
68
|
|
|
} |
69
|
1 |
|
$flashToolbarContainer->$key->push($rowArray); |
70
|
|
|
} |
71
|
|
|
} |
72
|
13 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Handle FlashMessenger data to be able to be seen in both "app" and toolbar parts. |
76
|
|
|
*/ |
77
|
14 |
|
public function flashMessengerHandler(EventInterface $e) : void |
78
|
|
|
{ |
79
|
14 |
|
$controller = $e->getTarget(); |
80
|
14 |
|
if (!$controller->getPluginManager()->has('flashMessenger')) { |
81
|
1 |
|
return; |
82
|
|
|
} |
83
|
|
|
|
84
|
13 |
|
$flash = $controller->plugin('flashMessenger'); |
85
|
13 |
|
$container = $flash->getContainer(); |
86
|
13 |
|
$this->duplicateFlashMessengerSessionData($container); |
87
|
13 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
13 |
|
public function getConfig() : array |
93
|
|
|
{ |
94
|
13 |
|
return include __DIR__.'/../config/module.config.php'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
13 |
|
public function getModuleDependencies() : array |
101
|
|
|
{ |
102
|
13 |
|
return ['ZendDeveloperTools']; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|