Example #1
0
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     $routes = new RouteCollection();
     $contextConfigLoader = $this->contextConfigLoader;
     foreach ($contextConfigLoader->getRouting() as $routing) {
         foreach ($routing as $id => $info) {
             if (array_key_exists('pattern', $info)) {
                 $route = new Route($info['pattern']);
                 // merge options and defaults
                 if (array_key_exists('defaults', $info)) {
                     $route->addDefaults($info['defaults']);
                 }
                 if (array_key_exists('options', $info)) {
                     $route->addOptions($info['options']);
                 }
                 if (array_key_exists('requirements', $info)) {
                     $route->addRequirements($info['requirements']);
                 }
             }
             $routes->add($id, $route);
         }
     }
     return $routes;
 }
 /**
  * Gets the entity revision revert route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getRevisionRevertRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('revision-revert-form')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('revision-revert-form'));
         $route->addDefaults(['_form' => '\\Drupal\\entity\\Form\\RevisionRevertForm', 'title' => 'Revert to earlier revision']);
         $route->addRequirements(['_entity_access_revision' => "{$entity_type_id}.update"]);
         $route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()], $entity_type->id() . '_revision' => ['type' => 'entity_revision:' . $entity_type->id()]]);
         return $route;
     }
 }
 /**
  * Gets the entity revision view route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getRevisionViewRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('revision')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('revision'));
         $route->addDefaults(['_controller' => '\\Drupal\\entity\\Controller\\RevisionController::view', '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title']);
         $route->addRequirements(['_entity_access_revision' => "{$entity_type_id}.view"]);
         $route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()], $entity_type->id() . '_revision' => ['type' => 'entity_revision:' . $entity_type->id()]]);
         return $route;
     }
 }
Example #4
0
 /**
  * Add an endpiont/application to the server
  * @param string             $path The URI the client will connect to
  * @param ComponentInterface $controller Your application to server for the route. If not specified, assumed to be for a WebSocket
  * @param array              $allowedOrigins An array of hosts allowed to connect (same host by default), ['*'] for any
  * @param string             $httpHost Override the $httpHost variable provided in the __construct
  * @return ComponentInterface|WsServer
  */
 public function route($path, ComponentInterface $controller, array $allowedOrigins = array(), $httpHost = null)
 {
     if ($controller instanceof HttpServerInterface || $controller instanceof WsServer) {
         $decorated = $controller;
     } elseif ($controller instanceof WampServerInterface) {
         $decorated = new WsServer(new WampServer($controller));
     } elseif ($controller instanceof MessageComponentInterface) {
         $decorated = new WsServer($controller);
     } else {
         $decorated = $controller;
     }
     if ($httpHost === null) {
         $httpHost = $this->httpHost;
     }
     $allowedOrigins = array_values($allowedOrigins);
     if (0 === count($allowedOrigins)) {
         $allowedOrigins[] = $httpHost;
     }
     if ('*' !== $allowedOrigins[0]) {
         $decorated = new OriginCheck($decorated, $allowedOrigins);
     }
     $route = null;
     if ($path instanceof Route) {
         $route = $path;
         $route->setDefault('_controller', $decorated);
     } else {
         $route = new Route($path, array('_controller' => $decorated));
     }
     if ('*' !== $httpHost) {
         $route->addRequirements(array('Origin' => $httpHost));
         $route->setHost($httpHost);
     }
     $this->routes->add('rr-' . ++$this->_routeCounter, $route);
     return $decorated;
 }
 /**
  * {@inheritdoc}
  */
 public function processRoute(Route $route)
 {
     $route->addRequirements(array('_access' => 'TRUE'));
 }
 /**
  * Adds the locale to the route if prepend_locale is enabled.
  *
  * @param Route $route The route
  */
 private function addLocaleToRoute(Route $route)
 {
     if ($this->prependLocale) {
         $route->setPath('/{_locale}' . $route->getPath());
         $route->addRequirements(['_locale' => '[a-z]{2}(\\-[A-Z]{2})?']);
     } else {
         $route->addDefaults(['_locale' => null]);
     }
 }
Example #7
0
 /**
  * Adds requirements.
  *
  * This method implements a fluent interface.
  *
  * @param array $requirements The requirements
  *
  * @return Route The current Route instance
  */
 public function addRequirements(array $requirements)
 {
     parent::addRequirements($requirements);
     $this->_addHeaderRequirements();
     return $this;
 }