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