| 
                    1
                 | 
                                    
                                                     | 
                
                 | 
                <?php  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    2
                 | 
                                    
                                                     | 
                
                 | 
                /**  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    3
                 | 
                                    
                                                     | 
                
                 | 
                 * @package midcom.routing  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    4
                 | 
                                    
                                                     | 
                
                 | 
                 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    5
                 | 
                                    
                                                     | 
                
                 | 
                 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    6
                 | 
                                    
                                                     | 
                
                 | 
                 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    7
                 | 
                                    
                                                     | 
                
                 | 
                 */  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    8
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    9
                 | 
                                    
                                                     | 
                
                 | 
                namespace midcom\httpkernel;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    10
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    11
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\EventDispatcher\EventSubscriberInterface;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    12
                 | 
                                    
                                                     | 
                
                 | 
                use midcom_response_styled;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    13
                 | 
                                    
                                                     | 
                
                 | 
                use midcom_baseclasses_components_handler;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    14
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpKernel\KernelEvents;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    15
                 | 
                                    
                                                     | 
                
                 | 
                use midcom\routing\resolver;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    16
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpFoundation\Request;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    17
                 | 
                                    
                                                     | 
                
                 | 
                use midcom;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    18
                 | 
                                    
                                                     | 
                
                 | 
                use midcom_connection;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    19
                 | 
                                    
                                                     | 
                
                 | 
                use midcom_core_context;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    20
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpKernel\Event\RequestEvent;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    21
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpKernel\Event\ExceptionEvent;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    22
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    23
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpKernel\Event\ViewEvent;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    24
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpKernel\Event\TerminateEvent;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    25
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\HttpKernel\Event\ControllerEvent;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    26
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    27
                 | 
                                    
                                                     | 
                
                 | 
                /**  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    28
                 | 
                                    
                                                     | 
                
                 | 
                 * @package midcom.httpkernel  | 
            
            
                                                                                                            
                                                                
            
                                    
            
            
                | 
                    29
                 | 
                                    
                                                     | 
                
                 | 
                 */  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    30
                 | 
                                    
                                                     | 
                
                 | 
                class subscriber implements EventSubscriberInterface  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    31
                 | 
                                    
                                                     | 
                
                 | 
                { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    32
                 | 
                                    
                                                     | 
                
                 | 
                    private $initialized = false;  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    33
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    34
                 | 
                                    
                                                     | 
                
                 | 
                    public static function getSubscribedEvents()  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    35
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    36
                 | 
                                    
                                                     | 
                
                 | 
                        return [  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    37
                 | 
                                    
                                                     | 
                
                 | 
                            KernelEvents::REQUEST => ['on_request'],  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    38
                 | 
                                    
                                                     | 
                
                 | 
                            KernelEvents::CONTROLLER => ['on_controller'],  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    39
                 | 
                                    
                                                     | 
                
                 | 
                            KernelEvents::CONTROLLER_ARGUMENTS => ['on_arguments'],  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    40
                 | 
                                    
                                                     | 
                
                 | 
                            KernelEvents::VIEW => ['on_view'],  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    41
                 | 
                                    
                                                     | 
                
                 | 
                            KernelEvents::EXCEPTION => ['on_exception'],  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    42
                 | 
                                    
                                                     | 
                
                 | 
                            KernelEvents::TERMINATE => ['on_terminate']  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    43
                 | 
                                    
                                                     | 
                
                 | 
                        ];  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    44
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    45
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    46
                 | 
                                    
                             1                          | 
                
                 | 
                    private function initialize(Request $request)  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    47
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    48
                 | 
                                    
                             1                          | 
                
                 | 
                        $midcom = midcom::get();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    49
                 | 
                                    
                             1                          | 
                
                 | 
                        $midcom->debug->log("Start of MidCOM run " . $request->server->get('REQUEST_URI', '')); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    50
                 | 
                                    
                             1                          | 
                
                 | 
                        $request->setSession($midcom->session);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    51
                 | 
                                    
                             1                          | 
                
                 | 
                        if ($response = $midcom->auth->check_for_login_session($request)) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    52
                 | 
                                    
                                                     | 
                
                 | 
                            return $response;  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    53
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    54
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    55
                 | 
                                    
                                                     | 
                
                 | 
                        // This checks for the unittest case  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    56
                 | 
                                    
                             1                          | 
                
                 | 
                        if (!$request->attributes->has('context')) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    57
                 | 
                                    
                                                     | 
                
                 | 
                            // Initialize Context Storage  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    58
                 | 
                                    
                                                     | 
                
                 | 
                            $context = midcom_core_context::enter(midcom_connection::get_url('uri')); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    59
                 | 
                                    
                                                     | 
                
                 | 
                            $request->attributes->set('context', $context); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    60
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    61
                 | 
                                    
                                                     | 
                
                 | 
                        // Initialize the UI message stack from session  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    62
                 | 
                                    
                             1                          | 
                
                 | 
                        $midcom->uimessages->initialize($request);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    63
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    64
                 | 
                                    
                             1                          | 
                
                 | 
                        $midcom->dispatcher->addListener(KernelEvents::REQUEST, [$midcom->cache->content, 'on_request'], 10);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    65
                 | 
                                    
                             1                          | 
                
                 | 
                        $midcom->dispatcher->addListener(KernelEvents::RESPONSE, [$midcom->cache->content, 'on_response'], -10);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    66
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    67
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    68
                 | 
                                    
                             348                          | 
                
                 | 
                    public function on_request(RequestEvent $event)  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    69
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    70
                 | 
                                    
                             348                          | 
                
                 | 
                        $request = $event->getRequest();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    71
                 | 
                                    
                             348                          | 
                
                 | 
                        if (!$this->initialized) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    72
                 | 
                                    
                             1                          | 
                
                 | 
                            $this->initialized = true;  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    73
                 | 
                                    
                             1                          | 
                
                 | 
                            if ($response = $this->initialize($request)) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    74
                 | 
                                    
                                                     | 
                
                 | 
                                $event->setResponse($response);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    75
                 | 
                                    
                                                     | 
                
                 | 
                                return;  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    76
                 | 
                                    
                                                     | 
                
                 | 
                            }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    77
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    78
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    79
                 | 
                                    
                             348                          | 
                
                 | 
                        $resolver = new resolver($request);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    80
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    81
                 | 
                                    
                             348                          | 
                
                 | 
                        if ($resolver->process_midcom()) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    82
                 | 
                                    
                                                     | 
                
                 | 
                            return;  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    83
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    84
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    85
                 | 
                                    
                             348                          | 
                
                 | 
                        $resolver->process_component();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    86
                 | 
                                    
                             348                          | 
                
                 | 
                        $request->attributes->set('data', '__request_data__'); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    87
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    88
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    89
                 | 
                                    
                             348                          | 
                
                 | 
                    public function on_controller(ControllerEvent $event)  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    90
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    91
                 | 
                                    
                             348                          | 
                
                 | 
                        $request = $event->getRequest();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    92
                 | 
                                    
                             348                          | 
                
                 | 
                        $attributes = $request->attributes->all();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    93
                 | 
                                    
                             348                          | 
                
                 | 
                        if (!empty($attributes['__viewer'])) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    94
                 | 
                                    
                             348                          | 
                
                 | 
                            $controller = $event->getController();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    95
                 | 
                                    
                             348                          | 
                
                 | 
                            $attributes['__viewer']->prepare_handler($controller[0], $attributes);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    96
                 | 
                                    
                             348                          | 
                
                 | 
                            unset($attributes['__viewer']);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    97
                 | 
                                    
                             348                          | 
                
                 | 
                            $request->attributes->set('handler_id', $attributes['_route']); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    98
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    99
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    100
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    101
                 | 
                                    
                             348                          | 
                
                 | 
                    public function on_arguments(ControllerArgumentsEvent $event)  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    102
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    103
                 | 
                                    
                             348                          | 
                
                 | 
                        $arguments = $event->getArguments();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    104
                 | 
                                    
                             348                          | 
                
                 | 
                        $i = array_search('__request_data__', $arguments, true); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    105
                 | 
                                    
                             348                          | 
                
                 | 
                        if ($i !== false) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    106
                 | 
                                    
                             219                          | 
                
                 | 
                            $context = $event->getRequest()->attributes->get('context'); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    107
                 | 
                                    
                             219                          | 
                
                 | 
                            $arguments[$i] =& $context->get_custom_key('request_data'); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    108
                 | 
                                    
                             219                          | 
                
                 | 
                            $event->setArguments($arguments);  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    109
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    110
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    111
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    112
                 | 
                                    
                             59                          | 
                
                 | 
                    public function on_view(ViewEvent $event)  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    113
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    114
                 | 
                                    
                             59                          | 
                
                 | 
                        $attributes = $event->getRequest()->attributes;  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    115
                 | 
                                    
                             59                          | 
                
                 | 
                        $controller = $attributes->get('_controller'); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    116
                 | 
                                    
                             59                          | 
                
                 | 
                        if ($controller[0] instanceof midcom_baseclasses_components_handler) { | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    117
                 | 
                                    
                                                     | 
                
                 | 
                            $controller[0]->populate_breadcrumb_line();  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    118
                 | 
                                    
                                                     | 
                
                 | 
                        }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    119
                 | 
                                    
                             59                          | 
                
                 | 
                        $event->setResponse(new midcom_response_styled($attributes->get('context'))); | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    120
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                            
            
                                    
            
            
                | 
                    121
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    122
                 | 
                                    
                                                     | 
                
                 | 
                    public function on_exception(ExceptionEvent $event)  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    123
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    124
                 | 
                                    
                                                     | 
                
                 | 
                        $event->allowCustomResponseCode();  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    125
                 | 
                                    
                                                     | 
                
                 | 
                        $handler = new \midcom_exception_handler($event->getThrowable());  | 
            
            
                                                                                                            
                                                                
            
                                    
            
            
                | 
                    126
                 | 
                                    
                                                     | 
                
                 | 
                        $event->setResponse($handler->render());  | 
            
            
                                                                        
                                                                
            
                                    
            
            
                | 
                    127
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                                                                
            
                                    
            
            
                | 
                    128
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                        
                                                                
            
                                    
            
            
                | 
                    129
                 | 
                                    
                                                     | 
                
                 | 
                    public function on_terminate(TerminateEvent $event)  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    130
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                                                            
                                                                
            
                                    
            
            
                | 
                    131
                 | 
                                    
                                                     | 
                
                 | 
                        debug_add("End of MidCOM run: " . $event->getRequest()->server->get('REQUEST_URI')); | 
            
            
                                                                        
                                                                
            
                                    
            
            
                | 
                    132
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                        
                                                                
            
                                    
            
            
                | 
                    133
                 | 
                                    
                                                     | 
                
                 | 
                }  |