Eccube\Application::initPluginEventDispatcher PHP Méthode

initPluginEventDispatcher() public méthode

    public function initPluginEventDispatcher()
    {
        // EventDispatcher
        $this['eccube.event.dispatcher'] = $this->share(function () {
            return new EventDispatcher();
        });
        $app = $this;
        // hook point
        $this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $hookpoint = 'eccube.event.app.before';
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
        }, self::EARLY_EVENT);
        $this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $route = $event->getRequest()->attributes->get('_route');
            $hookpoint = "eccube.event.controller.{$route}.before";
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
        });
        $this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $route = $event->getRequest()->attributes->get('_route');
            $hookpoint = "eccube.event.controller.{$route}.after";
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
        });
        $this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $hookpoint = 'eccube.event.app.after';
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
        }, self::LATE_EVENT);
        $this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use($app) {
            $route = $event->getRequest()->attributes->get('_route');
            $hookpoint = "eccube.event.controller.{$route}.finish";
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
        });
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function (\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $route = $event->getRequest()->attributes->get('_route');
            $app['eccube.event.dispatcher']->dispatch('eccube.event.render.' . $route . '.before', $event);
        });
        // Request Event
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::REQUEST, function (\Symfony\Component\HttpKernel\Event\GetResponseEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $route = $event->getRequest()->attributes->get('_route');
            if (is_null($route)) {
                return;
            }
            $app['monolog']->debug('KernelEvents::REQUEST ' . $route);
            // 全体
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.request', $event);
            if (strpos($route, 'admin') === 0) {
                // 管理画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.request', $event);
            } else {
                // フロント画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.request', $event);
            }
            // ルーティング単位
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.request", $event);
        }, 30);
        // Routing(32)が解決しし, 認証判定(8)が実行される前のタイミング.
        // Controller Event
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function (\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $route = $event->getRequest()->attributes->get('_route');
            if (is_null($route)) {
                return;
            }
            $app['monolog']->debug('KernelEvents::CONTROLLER ' . $route);
            // 全体
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.controller', $event);
            if (strpos($route, 'admin') === 0) {
                // 管理画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.controller', $event);
            } else {
                // フロント画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.controller', $event);
            }
            // ルーティング単位
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.controller", $event);
        });
        // Response Event
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function (\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $route = $event->getRequest()->attributes->get('_route');
            if (is_null($route)) {
                return;
            }
            $app['monolog']->debug('KernelEvents::RESPONSE ' . $route);
            // ルーティング単位
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.response", $event);
            if (strpos($route, 'admin') === 0) {
                // 管理画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.response', $event);
            } else {
                // フロント画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.response', $event);
            }
            // 全体
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.response', $event);
        });
        // Exception Event
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::EXCEPTION, function (\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event) use($app) {
            if (!$event->isMasterRequest()) {
                return;
            }
            $route = $event->getRequest()->attributes->get('_route');
            if (is_null($route)) {
                return;
            }
            $app['monolog']->debug('KernelEvents::EXCEPTION ' . $route);
            // ルーティング単位
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.exception", $event);
            if (strpos($route, 'admin') === 0) {
                // 管理画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.exception', $event);
            } else {
                // フロント画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.exception', $event);
            }
            // 全体
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.exception', $event);
        });
        // Terminate Event
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::TERMINATE, function (\Symfony\Component\HttpKernel\Event\PostResponseEvent $event) use($app) {
            $route = $event->getRequest()->attributes->get('_route');
            if (is_null($route)) {
                return;
            }
            $app['monolog']->debug('KernelEvents::TERMINATE ' . $route);
            // ルーティング単位
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.terminate", $event);
            if (strpos($route, 'admin') === 0) {
                // 管理画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.terminate', $event);
            } else {
                // フロント画面
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.terminate', $event);
            }
            // 全体
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.terminate', $event);
        });
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function createApplication()
 {
     $app = new Application();
     $app->initialize();
     $app->initPluginEventDispatcher();
     $app['session.test'] = true;
     $app['exception_handler']->disable();
     $app->boot();
     return $app;
 }
All Usage Examples Of Eccube\Application::initPluginEventDispatcher