コード例 #1
0
 public function register(Container $container)
 {
     $container['request'] = function ($c) {
         return Request::createFromGlobals();
     };
     $container['requestStack'] = function ($c) {
         $stack = new RequestStack();
         $stack->push($c['request']);
         return $stack;
     };
     $container['requestContext'] = function ($c) {
         $rc = new RequestContext();
         $rc->fromRequest($c['request']);
         return $rc;
     };
     $container['resolver'] = function ($c) {
         return new ControllerResolver();
     };
     $container['httpKernel'] = function ($c) {
         return new HttpKernel($c['dispatcher'], $c['resolver'], $c['requestStack']);
     };
     $container['urlMatcher'] = function ($c) {
         if (RouteCollectionSubscriber::needToDumpUrlTools()) {
             return new UrlMatcher($c['routeCollection'], $c['requestContext']);
         } else {
             return new MixedUrlMatcher($c['requestContext'], $c['dynamicUrlMatcher'], (bool) $c['config']['install']);
         }
     };
     $container['dynamicUrlMatcher'] = function ($c) {
         return new NodeUrlMatcher($c['requestContext'], $c['em']);
     };
     $container['urlGeneratorClass'] = function ($c) {
         return '\\GlobalUrlGenerator';
     };
     $container['urlGenerator'] = function ($c) {
         if (RouteCollectionSubscriber::needToDumpUrlTools()) {
             return new UrlGenerator($c['routeCollection'], $c['requestContext'], $c['logger']);
         } else {
             $className = $c['urlGeneratorClass'];
             return new $className($c['requestContext']);
         }
     };
     $container['httpUtils'] = function ($c) {
         return new HttpUtils($c['urlGenerator'], $c['urlMatcher']);
     };
     $container['routeListener'] = function ($c) {
         return new RouterListener($c['urlMatcher'], $c['requestContext'], null, $c['requestStack']);
     };
     if (isset($container['config']['install']) && true === $container['config']['install']) {
         /*
          * Get Install routes
          */
         $container['routeCollection'] = function ($c) {
             $installClassname = Kernel::INSTALL_CLASSNAME;
             $feCollection = $installClassname::getRoutes();
             $rCollection = new RouteCollection();
             $rCollection->addCollection($feCollection);
             $installClassname::setupDependencyInjection($c);
             return $rCollection;
         };
     } else {
         /*
          * Get App routes
          */
         $container['routeCollection'] = function ($c) {
             $c['stopwatch']->start('routeCollection');
             $rCollection = new RouteCollection();
             /*
              * Add Assets controller routes
              */
             $rCollection->addCollection(\RZ\Roadiz\CMS\Controllers\AssetsController::getRoutes());
             /*
              * Add Entry points controller routes
              */
             $rCollection->addCollection(\RZ\Roadiz\CMS\Controllers\EntryPointsController::getRoutes());
             /*
              * Add Backend routes
              */
             $beClass = $c['backendClass'];
             $cmsCollection = $beClass::getRoutes();
             if ($cmsCollection !== null) {
                 $rCollection->addCollection($cmsCollection);
             }
             /*
              * Add Frontend routes
              *
              * return 'RZ\Roadiz\CMS\Controllers\FrontendController';
              */
             foreach ($c['frontendThemes'] as $theme) {
                 $feClass = $theme->getClassName();
                 $feCollection = $feClass::getRoutes();
                 $feBackendCollection = $feClass::getBackendRoutes();
                 if ($feCollection !== null) {
                     // set host pattern if defined
                     if ($theme->getHostname() != '*' && $theme->getHostname() != '') {
                         $feCollection->setHost($theme->getHostname());
                     }
                     /*
                      * Add a global prefix on theme static routes
                      */
                     if ($theme->getRoutePrefix() != '') {
                         $feCollection->addPrefix($theme->getRoutePrefix());
                     }
                     $rCollection->addCollection($feCollection);
                 }
                 if ($feBackendCollection !== null) {
                     /*
                      * Do not prefix or hostname admin routes.
                      */
                     $rCollection->addCollection($feBackendCollection);
                 }
             }
             $c['stopwatch']->stop('routeCollection');
             return $rCollection;
         };
     }
     return $container;
 }
コード例 #2
0
ファイル: Kernel.php プロジェクト: vasezhen/roadiz
 /**
  * Prepare backend and frontend routes and logic.
  *
  * @return boolean
  */
 public function initEvents()
 {
     if ($this->isDebug() || RouteCollectionSubscriber::needToDumpUrlTools()) {
         $this->container['dispatcher']->addSubscriber(new RouteCollectionSubscriber($this->container['routeCollection'], $this->container['stopwatch']));
     }
     $this->container['dispatcher']->addSubscriber($this->container['routeListener']);
     /*
      * Events
      */
     $this->container['dispatcher']->addListener(KernelEvents::REQUEST, [$this, 'onKernelRequest']);
     $this->container['dispatcher']->addListener(KernelEvents::REQUEST, [$this->container['firewall'], 'onKernelRequest']);
     $this->container['dispatcher']->addListener(KernelEvents::CONTROLLER, [new \RZ\Roadiz\Core\Events\ControllerMatchedEvent($this, $this->container['stopwatch']), 'onControllerMatched']);
     $this->container['dispatcher']->addSubscriber(new MaintenanceModeSubscriber($this->container));
     /*
      * If debug, alter HTML responses to append Debug panel to view
      */
     if (true === (bool) SettingsBag::get('display_debug_panel')) {
         $this->container['dispatcher']->addSubscriber($this->container['debugPanel']);
     }
 }
コード例 #3
0
 public function register(Container $container)
 {
     $container['request'] = function ($c) {
         return Request::createFromGlobals();
     };
     $container['requestStack'] = function ($c) {
         $stack = new RequestStack();
         $stack->push($c['request']);
         return $stack;
     };
     $container['requestContext'] = function ($c) {
         $rc = new RequestContext();
         $rc->fromRequest($c['request']);
         return $rc;
     };
     $container['resolver'] = function ($c) {
         return new ControllerResolver();
     };
     $container['httpKernel'] = function ($c) {
         return new HttpKernel($c['dispatcher'], $c['resolver'], $c['requestStack']);
     };
     $container['urlMatcher'] = function ($c) {
         if (RouteCollectionSubscriber::needToDumpUrlTools()) {
             return new UrlMatcher($c['routeCollection'], $c['requestContext']);
         } else {
             return new MixedUrlMatcher($c['requestContext'], $c['dynamicUrlMatcher'], (bool) $c['config']['install'], $c['stopwatch']);
         }
     };
     $container['dynamicUrlMatcher'] = function ($c) {
         return new NodeUrlMatcher($c['requestContext'], $c['em'], $c['stopwatch']);
     };
     $container['urlGeneratorClass'] = function ($c) {
         return '\\GlobalUrlGenerator';
     };
     $container['urlGenerator'] = function ($c) {
         if (RouteCollectionSubscriber::needToDumpUrlTools()) {
             return new UrlGenerator($c['routeCollection'], $c['requestContext'], $c['logger']);
         } else {
             $className = $c['urlGeneratorClass'];
             return new $className($c['requestContext']);
         }
     };
     $container['httpUtils'] = function ($c) {
         return new HttpUtils($c['urlGenerator'], $c['urlMatcher']);
     };
     $container['routeListener'] = function ($c) {
         return new TimedRouteListener($c['urlMatcher'], $c['requestContext'], null, $c['requestStack'], $c['stopwatch']);
     };
     if (isset($container['config']['install']) && true === $container['config']['install']) {
         /*
          * Get Install routes
          */
         $container['routeCollection'] = function ($c) {
             $installClassname = Kernel::INSTALL_CLASSNAME;
             $installClassname::setupDependencyInjection($c);
             return new InstallRouteCollection($installClassname);
         };
     } else {
         /*
          * Get App routes
          */
         $container['routeCollection'] = function ($c) {
             $c['stopwatch']->start('routeCollection');
             $rCollection = new RoadizRouteCollection($c['backendClass'], $c['frontendThemes'], SettingsBag::get('static_domain_name'));
             $c['stopwatch']->stop('routeCollection');
             return $rCollection;
         };
     }
     return $container;
 }