add() public method

Adds a route.
public add ( string $name, Symfony\Component\Routing\Route $route )
$name string The route name
$route Symfony\Component\Routing\Route A Route instance
示例#1
0
 private function createRoutes($entity)
 {
     $prefix = self::DEFAULT_PREFIX;
     $parts = explode('\\', $entity);
     $bundle = str_replace('bundle', '', strtolower($parts[1]));
     $routeKey = strtolower($parts[3]);
     $controller = strtolower($parts[3]);
     // pheetup.controller.bundle.controller
     $controller_service = 'pheetup.controller.' . $bundle . '.' . $controller;
     //create
     $createPattern = $prefix . '/' . $routeKey . '/create/{id}';
     $createDefaults = ['_controller' => $controller_service . ':createAction', 'id' => 0];
     $createRoute = new Route($createPattern, $createDefaults);
     $this->routes->add('pheetup_' . $routeKey . '_create', $createRoute);
     //list
     $listPattern = $prefix . '/' . $routeKey;
     $listDefaults = ['_controller' => $controller_service . ':listAction'];
     $listRoute = new Route($listPattern, $listDefaults);
     $this->routes->add('pheetup_' . $routeKey, $listRoute);
     //delete
     $deletePattern = $prefix . '/' . $routeKey . '/delete/{id}';
     $deleteDefaults = ['_controller' => $controller_service . ':deleteAction'];
     $deleteRoute = new Route($deletePattern, $deleteDefaults, ['id' => '\\d+']);
     $this->routes->add('pheetup_' . $routeKey . '_delete', $deleteRoute);
     //view
     $viewPattern = $prefix . '/' . $routeKey . '/explore/{id}';
     $viewDefaults = ['_controller' => $controller_service . ':viewAction'];
     $viewRoute = new Route($viewPattern, $viewDefaults, ['id' => '\\d+']);
     $this->routes->add('pheetup_' . $routeKey . '_view', $viewRoute);
 }
示例#2
0
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add the "dynamic" loader twice');
     }
     $defaultSite = $this->sm()->getDefaultSite();
     $routes = new RouteCollection();
     $homeRedirectRoute = new Route('/', array('_controller' => 'FrameworkBundle:Redirect:urlRedirect', 'path' => '/' . $defaultSite->getSlug() . '/index.php', 'permanent' => true));
     $routes->add('homeRedirect', $homeRedirectRoute);
     $homeRedirectRoute = new Route('/{siteSlug}/index.php', array('_controller' => 'BWCMSBundle:FrontEnd:home'), array('siteSlug' => '[a-zA-Z0-9-]+'));
     $routes->add('home_page', $homeRedirectRoute);
     //make sure all content types are initialized.
     $this->cm()->init();
     $registerContentTypes = $this->cm()->getAllContentTypes();
     foreach ($registerContentTypes as $contentType) {
         $routeCollection = $contentType->getRouteCollection();
         if (!is_null($routeCollection)) {
             foreach ($routeCollection as $routeName => $routeInfo) {
                 $routes->add($routeName, $routeInfo);
             }
         }
     }
     $routeLoaderEvent = new RouteLoaderEvent();
     $routeLoaderEvent->setRoutes($routes);
     $this->getEventDispatcher()->dispatch('BWCMS.Route.Loader', $routeLoaderEvent);
     $this->loaded = true;
     return $routeLoaderEvent->getRoutes();
 }
示例#3
0
 public function testLoad()
 {
     $importedRouteCollection = new RouteCollection();
     $importedRouteCollection->add('route1', new Route('/example/route1'));
     $importedRouteCollection->add('route2', new Route('/route2'));
     $portal1 = new Portal();
     $portal1->setKey('sulu_lo');
     $portal2 = new Portal();
     $portal2->setKey('sulu_com');
     $portalInformations = [new PortalInformation(null, null, $portal1, null, 'sulu.io/de'), new PortalInformation(null, null, $portal2, null, 'sulu.com')];
     $this->loaderResolver->resolve(Argument::any(), Argument::any())->willReturn($this->loader->reveal());
     $this->loader->load(Argument::any(), Argument::any())->willReturn($importedRouteCollection);
     $this->webspaceManager->getPortalInformations(Argument::any())->willReturn($portalInformations);
     $routeCollection = $this->portalLoader->load('', 'portal');
     $this->assertCount(4, $routeCollection);
     $routes = $routeCollection->getIterator();
     $this->assertArrayHasKey('sulu.io/de.route1', $routes);
     $this->assertArrayHasKey('sulu.io/de.route2', $routes);
     $this->assertArrayHasKey('sulu.com.route1', $routes);
     $this->assertArrayHasKey('sulu.com.route2', $routes);
     $this->assertEquals('/de/example/route1', $routeCollection->get('sulu.io/de.route1')->getPath());
     $this->assertEquals('/de/route2', $routeCollection->get('sulu.io/de.route2')->getPath());
     $this->assertEquals('/example/route1', $routeCollection->get('sulu.com.route1')->getPath());
     $this->assertEquals('/route2', $routeCollection->get('sulu.com.route2')->getPath());
 }
 public function test()
 {
     $coll = new RouteCollection();
     $coll->add('foo', new Route('/foo', array(), array('_method' => 'POST')));
     $coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\\d+')));
     $coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\\w+', '_method' => 'POST')));
     $coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
     $coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
     $context = new RequestContext();
     $context->setHost('baz');
     $matcher = new TraceableUrlMatcher($coll, $context);
     $traces = $matcher->getTraces('/babar');
     $this->assertEquals(array(0, 0, 0, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo');
     $this->assertEquals(array(1, 0, 0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/12');
     $this->assertEquals(array(0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertEquals(array(0, 1, 1, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo1');
     $this->assertEquals(array(0, 0, 0, 0, 2), $this->getLevels($traces));
     $context->setMethod('POST');
     $traces = $matcher->getTraces('/foo');
     $this->assertEquals(array(2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertEquals(array(0, 1, 2), $this->getLevels($traces));
 }
示例#5
0
 public function testAbsoluteSecureUrlWithNonStandardPort()
 {
     $this->routeCollection->add('test', new Route('/testing'));
     $this->generator->setContext(array('base_url' => '/app.php', 'method' => 'GET', 'host' => 'localhost', 'port' => 8080, 'is_secure' => true));
     $url = $this->generator->generate('test', array(), true);
     $this->assertEquals('https://localhost:8080/app.php/testing', $url);
 }
 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     // Generates a list of Symfony formats matching the acceptable MIME types.
     // @todo replace by proper content negotiation library.
     $acceptable_mime_types = $request->getAcceptableContentTypes();
     $acceptable_formats = array_filter(array_map(array($request, 'getFormat'), $acceptable_mime_types));
     $primary_format = $request->getRequestFormat();
     foreach ($collection as $name => $route) {
         // _format could be a |-delimited list of supported formats.
         $supported_formats = array_filter(explode('|', $route->getRequirement('_format')));
         if (empty($supported_formats)) {
             // No format restriction on the route, so it always matches. Move it to
             // the end of the collection by re-adding it.
             $collection->add($name, $route);
         } elseif (in_array($primary_format, $supported_formats)) {
             // Perfect match, which will get a higher priority by leaving the route
             // on top of the list.
         } elseif (in_array('*/*', $acceptable_mime_types) || array_intersect($acceptable_formats, $supported_formats)) {
             // Move it to the end of the list.
             $collection->add($name, $route);
         } else {
             // Remove the route if it does not match at all.
             $collection->remove($name);
         }
     }
     if (count($collection)) {
         return $collection;
     }
     // We do not throw a
     // \Symfony\Component\Routing\Exception\ResourceNotFoundException here
     // because we don't want to return a 404 status code, but rather a 406.
     throw new NotAcceptableHttpException(SafeMarkup::format('No route found for the specified formats @formats.', array('@formats' => implode(' ', $acceptable_mime_types))));
 }
 /**
  * Tests the onAlterRoutes method.
  *
  * @see \Drupal\views\EventSubscriber\RouteSubscriber::onAlterRoutes()
  */
 public function testOnAlterRoutes()
 {
     $collection = new RouteCollection();
     // The first route will be overridden later.
     $collection->add('test_route', new Route('test_route', array('_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController')));
     $route_2 = new Route('test_route/example', array('_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController'));
     $collection->add('test_route_2', $route_2);
     $route_event = new RouteBuildEvent($collection, 'views');
     list($view, $executable, $display_1, $display_2) = $this->setupMocks();
     // The page_1 display overrides an existing route, so the dynamicRoutes
     // should only call the second display.
     $display_1->expects($this->once())->method('collectRoutes')->willReturnCallback(function () use($collection) {
         $collection->add('views.test_id.page_1', new Route('test_route', ['_content' => 'Drupal\\views\\Routing\\ViewPageController']));
         return ['test_id.page_1' => 'views.test_id.page_1'];
     });
     $display_1->expects($this->once())->method('alterRoutes')->willReturn(['test_id.page_1' => 'test_route']);
     $display_2->expects($this->once())->method('collectRoutes')->willReturnCallback(function () use($collection) {
         $collection->add('views.test_id.page_2', new Route('test_route', ['_content' => 'Drupal\\views\\Routing\\ViewPageController']));
         return ['test_id.page_2' => 'views.test_id.page_2'];
     });
     $display_2->expects($this->once())->method('alterRoutes')->willReturn([]);
     // Ensure that even both the collectRoutes() and alterRoutes() methods
     // are called on the displays, we ensure that the route first defined by
     // views is dropped.
     $this->routeSubscriber->routes();
     $this->assertNull($this->routeSubscriber->onAlterRoutes($route_event));
     $this->state->expects($this->once())->method('set')->with('views.view_route_names', array('test_id.page_1' => 'test_route', 'test_id.page_2' => 'views.test_id.page_2'));
     $collection = $route_event->getRouteCollection();
     $this->assertEquals(['test_route', 'test_route_2', 'views.test_id.page_2'], array_keys($collection->all()));
     $this->routeSubscriber->routeRebuildFinished();
 }
示例#8
0
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     list($prefix, $resource) = explode('.', $resource);
     $pluralResource = Inflector::pluralize($resource);
     $rootPath = '/' . $pluralResource . '/';
     $requirements = array();
     // GET collection request.
     $routeName = sprintf('%s_api_%s_index', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:indexAction', $prefix, $resource));
     $route = new Route($rootPath, $defaults, $requirements, array(), '', array(), array('GET'));
     $routes->add($routeName, $route);
     // GET request.
     $routeName = sprintf('%s_api_%s_show', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:showAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('GET'));
     $routes->add($routeName, $route);
     // POST request.
     $routeName = sprintf('%s_api_%s_create', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:createAction', $prefix, $resource));
     $route = new Route($rootPath, $defaults, $requirements, array(), '', array(), array('POST'));
     $routes->add($routeName, $route);
     // PUT request.
     $routeName = sprintf('%s_api_%s_update', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:updateAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('PUT', 'PATCH'));
     $routes->add($routeName, $route);
     // DELETE request.
     $routeName = sprintf('%s_api_%s_delete', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:deleteAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('DELETE'));
     $routes->add($routeName, $route);
     return $routes;
 }
 /**
  * Given an array of RAML\Resources, this function will add each Resource
  * into the Symfony Route Collection, and set the corresponding method.
  *
  * @param BasicRoute[Resource] $resources
  *  Associative array where the key is the method and full path, and the value contains
  *  the path, method type (GET/POST etc.) and then the Raml\Method object
  *
  * @return array
  */
 public function format(array $resources)
 {
     // Loop over the Resources
     foreach ($resources as $path => $resource) {
         // This is the path from the RAML, with or without a /.
         $path = $resource->getUri() . ($this->addTrailingSlash ? '/' : '');
         // This is the baseUri + path, the complete URL.
         $url = $resource->getBaseUrl() . $path;
         // Now remove the host away, so we have the FULL path to the resource.
         // baseUri may also contain path that has been omitted for brevity in the
         // RAML creation.
         $host = parse_url($url, PHP_URL_HOST);
         $fullPath = substr($url, strpos($url, $host) + strlen($host));
         // Now build our Route class.
         $route = new Route($fullPath);
         $route->setMethods($resource->getMethod()->getType());
         $route->setSchemes($resource->getProtocols());
         // Loop over each of the URI Parameters searching for validation patterns
         // or default values for parameters.
         foreach ($resource->getUriParameters() as $name => $param) {
             $route->setRequirement($name, $param->getValidationPattern());
             if ($default = $param->getDefault()) {
                 $route->setDefault($name, $default);
             }
         }
         $this->routes->add($resource->getType() . ' ' . $path, $route);
     }
     return $resources;
 }
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
         // Try to get the route from the current collection.
         $link_template = $entity_type->getLinkTemplate('canonical');
         if (strpos($link_template, '/') !== FALSE) {
             $base_path = '/' . $link_template;
         } else {
             if (!($entity_route = $collection->get("entity.{$entity_type_id}.canonical"))) {
                 continue;
             }
             $base_path = $entity_route->getPath();
         }
         // Inherit admin route status from edit route, if exists.
         $is_admin = FALSE;
         $route_name = "entity.{$entity_type_id}.edit_form";
         if ($edit_route = $collection->get($route_name)) {
             $is_admin = (bool) $edit_route->getOption('_admin_route');
         }
         $path = $base_path . '/translations';
         $route = new Route($path, array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::overview', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_overview' => $entity_type_id), array('parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $route_name = "entity.{$entity_type_id}.content_translation_overview";
         $collection->add($route_name, $route);
         $route = new Route($path . '/add/{source}/{target}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::add', 'source' => NULL, 'target' => NULL, '_title' => 'Add', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_manage' => 'create'), array('parameters' => array('source' => array('type' => 'language'), 'target' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_add", $route);
         $route = new Route($path . '/edit/{language}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::edit', 'language' => NULL, '_title' => 'Edit', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'update'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_edit", $route);
         $route = new Route($path . '/delete/{language}', array('_entity_form' => $entity_type_id . '.content_translation_deletion', 'language' => NULL, '_title' => 'Delete', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'delete'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_delete", $route);
     }
 }
 public function testDumpWithSchemeRequirement()
 {
     $this->routeCollection->add('Test1', new Route('/testing', array(), array(), array(), '', array('ftp', 'https')));
     $this->routeCollection->add('Test2', new Route('/testing_bc', array(), array('_scheme' => 'https')));
     // BC
     file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'SchemeUrlGenerator')));
     include $this->testTmpFilepath;
     $projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php'));
     $absoluteUrl = $projectUrlGenerator->generate('Test1', array(), true);
     $absoluteUrlBC = $projectUrlGenerator->generate('Test2', array(), true);
     $relativeUrl = $projectUrlGenerator->generate('Test1', array(), false);
     $relativeUrlBC = $projectUrlGenerator->generate('Test2', array(), false);
     $this->assertEquals($absoluteUrl, 'ftp://localhost/app.php/testing');
     $this->assertEquals($absoluteUrlBC, 'https://localhost/app.php/testing_bc');
     $this->assertEquals($relativeUrl, 'ftp://localhost/app.php/testing');
     $this->assertEquals($relativeUrlBC, 'https://localhost/app.php/testing_bc');
     $projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php', 'GET', 'localhost', 'https'));
     $absoluteUrl = $projectUrlGenerator->generate('Test1', array(), true);
     $absoluteUrlBC = $projectUrlGenerator->generate('Test2', array(), true);
     $relativeUrl = $projectUrlGenerator->generate('Test1', array(), false);
     $relativeUrlBC = $projectUrlGenerator->generate('Test2', array(), false);
     $this->assertEquals($absoluteUrl, 'https://localhost/app.php/testing');
     $this->assertEquals($absoluteUrlBC, 'https://localhost/app.php/testing_bc');
     $this->assertEquals($relativeUrl, '/app.php/testing');
     $this->assertEquals($relativeUrlBC, '/app.php/testing_bc');
 }
示例#12
0
 protected function loadRoutes()
 {
     $this->routes->add('dynamic_route_' . ($this->routes->count() + 1), new Route('pup/image/upload/service', $defaults = array('_controller' => 'pupBundle:Process:upload'), $requirements = array()));
     //add another
     //or execute a db query and add multiple routes
     //etc.
 }
示例#13
0
 /**
  * @todo clean this
  */
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     $routes = new RouteCollection();
     $frontPageConfig = $this->container->get('system')->get('system.frontpage', 'blog');
     $frontPageProvider = $this->container->get('drafterbit_system.frontpage_provider');
     $reservedBaseUrl = [$this->container->getParameter('admin')];
     foreach ($frontPageProvider->all() as $prefix => $frontPage) {
         $frontRoutes = $frontPage->getRoutes();
         if ($prefix !== $frontPageConfig) {
             $frontRoutes->addPrefix($frontPage->getRoutePrefix());
             $reservedBaseUrl[] = $prefix;
         }
         $routes->addCollection($frontRoutes);
     }
     $defaults = array('_controller' => 'DrafterbitPageBundle:Frontend:view');
     // check if configured frontpage is not an app
     if (!array_key_exists($frontPageConfig, $frontPageProvider->all())) {
         // its page
         $defaults['slug'] = $frontPageConfig;
         $routes->add('_home', new Route('/', $defaults));
     }
     $reservedBaseUrl = implode('|', $reservedBaseUrl);
     // @link http://stackoverflow.com/questions/25496704/regex-match-slug-except-particular-start-words
     // @prototype  'slug' => "^(?!(?:backend|blog)(?:/|$)).*$"
     $requirements = array('slug' => "^(?!(?:%admin%|" . $reservedBaseUrl . "|)(?:/|\$)).*\$");
     $route2 = new Route('/{slug}', $defaults, $requirements);
     $routes->add('misc', $route2);
     return $routes;
 }
 public function testDump()
 {
     $collection = new RouteCollection();
     // defaults and requirements
     $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'), array('bar' => 'baz|symfony')));
     // method requirement
     $collection->add('bar', new Route('/bar/{foo}', array(), array('_method' => 'GET|head')));
     // method requirement (again)
     $collection->add('baragain', new Route('/baragain/{foo}', array(), array('_method' => 'get|post')));
     // simple
     $collection->add('baz', new Route('/test/baz'));
     // simple with extension
     $collection->add('baz2', new Route('/test/baz.html'));
     // trailing slash
     $collection->add('baz3', new Route('/test/baz3/'));
     // trailing slash with variable
     $collection->add('baz4', new Route('/test/{foo}/'));
     // trailing slash and safe method
     $collection->add('baz5', new Route('/test/{foo}/', array(), array('_method' => 'get')));
     // trailing slash and unsafe method
     $collection->add('baz5unsafe', new Route('/testunsafe/{foo}/', array(), array('_method' => 'post')));
     // complex
     $collection->add('baz6', new Route('/test/baz', array('foo' => 'bar baz')));
     $dumper = new ApacheMatcherDumper($collection);
     $this->assertStringEqualsFile(self::$fixturesPath . '/dumper/url_matcher1.apache', $dumper->dump(), '->dump() dumps basic routes to the correct apache format.');
 }
示例#15
0
 /**
  * Adds a Route to the Route Collection
  * @param type $name
  * @param type $path
  * @param array $controlerAction
  * @param array $defaults
  * @return \Blend\Component\Routing\Route
  */
 public function route($name, $path, array $controlerAction, array $defaults = [])
 {
     $params = array_merge($defaults, [RouteAttribute::CONTROLLER => $controlerAction]);
     $route = new Route($path, $params);
     $this->routes->add($name, $route);
     return $route;
 }
示例#16
0
 /**
  * @param Route $route
  */
 public function addRoute(Route $route)
 {
     $internalRoute = new \Symfony\Component\Routing\Route($route->getPath());
     $internalRoute->setMethods(array($route->getHttpMethod()));
     $internalRoute->setDefaults(array('_controllerName' => $route->getControllerName(), '_methodName' => $route->getMethodName()));
     $this->_routes->add($route->getName(), $internalRoute);
 }
示例#17
0
 public function __construct(Request $request, array $options)
 {
     parent::__construct($request, $options);
     $this->methods = new Map();
     // create routes from db
     $apis = ApiQuery::create()->joinAction()->useActionQuery()->joinModule()->endUse()->find();
     $routes = new RouteCollection();
     /* @var $api Api */
     foreach ($apis as $api) {
         $action = $api->getAction();
         $module = $action->getModule();
         $path = str_replace('//', '/', '/' . $api->getRoute());
         $required = $api->getRequiredParams();
         $required = is_array($required) ? explode(',', $required) : [];
         $name = $module->getName() . ':' . $action->getName() . '@' . $api->getMethod();
         $route = new Route($path, ['path' => $path, 'action' => $action], $required, [], null, [], [$api->getMethod(), 'options']);
         // debug: print routes
         // 			printf("%s: %s -> %s\n", $api->getMethod(), $path, $module->getName() . ':' . $action->getName());
         $routes->add($name, $route);
         // with params
         $paramRoute = clone $route;
         $paramRoute->setPath(sprintf('%s%s{params}', $path, $this->options['param-separator']));
         $paramRoute->setRequirement('params', '.+');
         $paramName = $name . 'WithParam';
         $routes->add($paramName, $paramRoute);
         if (!$this->methods->has($path)) {
             $this->methods->set($path, new ArrayList());
         }
         $this->methods->get($path)->add(strtoupper($api->getMethod()));
     }
     $this->init($routes);
 }
 public function providerTestOnRequestWithOptionsRequest()
 {
     $data = [];
     foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method) {
         $collection = new RouteCollection();
         $collection->add('example.1', new Route('/example', [], [], [], '', [], [$method]));
         $data['one_route_' . $method] = [$collection, $method];
     }
     foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_a) {
         foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_b) {
             if ($method_a != $method_b) {
                 $collection = new RouteCollection();
                 $collection->add('example.1', new Route('/example', [], [], [], '', [], [$method_a, $method_b]));
                 $data['one_route_' . $method_a . '_' . $method_b] = [$collection, $method_a . ', ' . $method_b];
             }
         }
     }
     foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_a) {
         foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_b) {
             foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_c) {
                 $collection = new RouteCollection();
                 $collection->add('example.1', new Route('/example', [], [], [], '', [], [$method_a]));
                 $collection->add('example.2', new Route('/example', [], [], [], '', [], [$method_a, $method_b]));
                 $collection->add('example.3', new Route('/example', [], [], [], '', [], [$method_b, $method_c]));
                 $methods = array_unique([$method_a, $method_b, $method_c]);
                 $data['multiple_routes_' . $method_a . '_' . $method_b . '_' . $method_c] = [$collection, implode(', ', $methods)];
             }
         }
     }
     return $data;
 }
示例#19
0
 /**
  * {@inheritdoc}
  */
 public function routes()
 {
     $route_collection = new RouteCollection();
     // Get all entity types.
     $eck_types = EckEntityType::loadMultiple();
     foreach ($eck_types as $eck_type) {
         // Route for list.
         $route_list = new Route('admin/structure/eck/entity/' . $eck_type->id, array('_entity_list' => $eck_type->id, '_title' => $eck_type->label . 'list'), array('_permission' => 'view eck entity'));
         // Add the route.
         $route_collection->add('eck.entity.' . $eck_type->id . '.list', $route_list);
         // Route for type list.
         $route_type_list = new Route('admin/structure/eck/entity/' . $eck_type->id . '/types', array('_controller' => '\\Drupal\\Core\\Entity\\Controller\\EntityListController::listing', 'entity_type' => $eck_type->id . '_type', '_title' => $eck_type->label . 'types'), array('_permission' => 'administer eck entity bundles'));
         // Add the route.
         $route_collection->add('eck.entity.' . $eck_type->id . '_type.list', $route_type_list);
         // Route for type add.
         $route_type_add = new Route('admin/structure/eck/entity/' . $eck_type->id . '/types/add', array('_entity_form' => $eck_type->id . '_type.add', '_title' => $eck_type->label . 'type'), array('_permission' => 'administer eck entity bundles'));
         // Add the route.
         $route_collection->add('eck.entity.' . $eck_type->id . '_type.add', $route_type_add);
         // Route for type edit.
         $route_type_edit = new Route('admin/structure/eck/entity/' . $eck_type->id . '/types/manage/{' . $eck_type->id . '_type}', array('_entity_form' => $eck_type->id . '_type.edit', '_title' => 'Edit' . $eck_type->label . 'type'), array('_permission' => 'administer eck entity bundles'));
         // Add the route.
         $route_collection->add('entity.' . $eck_type->id . '_type.edit_form', $route_type_edit);
         // Route for type delete.
         $route_type_delete = new Route('admin/structure/eck/entity/' . $eck_type->id . '/types/manage/{' . $eck_type->id . '_type}/delete', array('_entity_form' => $eck_type->id . '_type.delete', '_title' => 'Delete' . $eck_type->label . 'type'), array('_permission' => 'administer eck entity bundles'));
         // Add the route.
         $route_collection->add('entity.' . $eck_type->id . '_type.delete_form', $route_type_delete);
     }
     return $route_collection;
 }
  /**
   * Tests altering and finished event.
   *
   * @covers ::onRouteAlter
   * @covers ::onRouteFinished
   */
  public function testSubscribing() {

    // Ensure that onRouteFinished can be called without throwing notices
    // when no path roots got set.
    $this->pathRootsSubscriber->onRouteFinished();

    $route_collection = new RouteCollection();
    $route_collection->add('test_route1', new Route('/test/bar'));
    $route_collection->add('test_route2', new Route('/test/baz'));
    $route_collection->add('test_route3', new Route('/test2/bar/baz'));

    $event = new RouteBuildEvent($route_collection, 'provider');
    $this->pathRootsSubscriber->onRouteAlter($event);

    $route_collection = new RouteCollection();
    $route_collection->add('test_route4', new Route('/test1/bar'));
    $route_collection->add('test_route5', new Route('/test2/baz'));
    $route_collection->add('test_route6', new Route('/test2/bar/baz'));

    $event = new RouteBuildEvent($route_collection, 'provider');
    $this->pathRootsSubscriber->onRouteAlter($event);

    $this->state->expects($this->once())
      ->method('set')
      ->with('router.path_roots', array('test', 'test2', 'test1'));

    $this->pathRootsSubscriber->onRouteFinished();
  }
示例#21
0
 /**
  * Create route for REST action
  *
  * @param RouteCollection $collection
  * @param string $document
  * @param array $endpoint
  * @param string $version
  */
 private function processRestRoute($collection, $document, $endpoint, $version = 'v1')
 {
     $defaults = ['_documentId' => null, '_endpoint' => $endpoint, '_version' => $version, 'repository' => $endpoint['repository']];
     $pattern = $version . '/' . sprintf('%s/{documentId}', strtolower($document));
     if ($endpoint['batch']) {
         foreach ([Request::METHOD_PUT, Request::METHOD_POST, Request::METHOD_DELETE] as $method) {
             $defaults['_controller'] = 'ONGRApiBundle:Batch:' . ucfirst(strtolower($method));
             $batchPattern = $version . '/' . sprintf('%s', strtolower($document)) . '/_batch';
             $name = strtolower(sprintf('ongr_api_%s_%s_%s', $version, $document, $method));
             $collection->add($name . '_batch', new Route($batchPattern, $defaults, [], [], "", [], [$method]));
         }
     }
     $name = strtolower(sprintf('ongr_api_%s_%s_all', $version, $document));
     $defaults['_controller'] = 'ONGRApiBundle:GetAll:getAll';
     $postPattern = $version . '/' . sprintf('%s', strtolower($document)) . '/_all';
     $collection->add($name, new Route($postPattern, $defaults, [], [], "", [], [Request::METHOD_GET]));
     foreach ($endpoint['methods'] as $method) {
         $name = strtolower(sprintf('ongr_api_%s_%s_%s', $version, $document, $method));
         $defaults['_controller'] = sprintf('ONGRApiBundle:Rest:%s', strtolower($method));
         if ($method == Request::METHOD_POST) {
             $postPattern = $version . '/' . sprintf('%s', strtolower($document));
             $collection->add($name . '_wi', new Route($postPattern, $defaults, [], [], "", [], [$method]));
         }
         $collection->add($name, new Route($pattern, $defaults, [], [], "", [], [$method]));
         if ($endpoint['variants']) {
             $defaults['_controller'] = sprintf('ONGRApiBundle:Variant:%s', strtolower($method));
             if ($method == Request::METHOD_POST || $method == Request::METHOD_GET) {
                 $variantPattern = $pattern . '/_variant';
                 $collection->add($name . '_variant_wi', new Route($variantPattern, $defaults, [], [], "", [], [$method]));
             }
             $variantPattern = $pattern . '/_variant/{variantId}';
             $collection->add($name . '_variant', new Route($variantPattern, $defaults, [], [], "", [], [$method]));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getRoutes(EntityTypeInterface $entity_type)
 {
     $routes = new RouteCollection();
     $routes->add('entity.' . $entity_type->id() . '.collection', $this->collectionRoute($entity_type));
     $routes->add('entity.' . $entity_type->id() . '.add_page', $this->addPageRoute($entity_type));
     $routes->add('entity.' . $entity_type->id() . '.add_form', $this->addFormRoute($entity_type));
     return $routes;
 }
示例#23
0
文件: Module.php 项目: khasinski/Iphp
 protected function addRoute($name, $pattern, array $defaults = array(), array $requirements = array(), array $options = array())
 {
     //print '<br>--'.$this->prepareRubricPath($this->rubric->getFullPath()).'_'.$name;
     $route = new Route($pattern, $defaults, $requirements, $options);
     //$name = $name ? $name : $this->suggestRouteName($route);
     $this->routeCollection->add($this->prepareRouteName($name), $route);
     return $this;
 }
 /**
  *
  * @return RouteCollection
  */
 private function generateRoutes()
 {
     $routes = new RouteCollection();
     $routes->add('account-index', new Route('/account'));
     $routes->add('account', new Route('/account/{suffix}', ['suffix' => ''], ['suffix' => '.*']));
     $routes->add('trixionary', new Route('/{suffix}', ['suffix' => ''], ['suffix' => '.*']));
     return $routes;
 }
示例#25
0
 /**
  * @inheritdoc
  */
 public function getRouteCollectionForRequest(Request $request)
 {
     $slugProvider = $this->container->get('harentius_blog.router.category_slug_provider');
     foreach ($slugProvider->getAll() as $categoryId => $fullSlug) {
         $this->routes->add("harentius_blog_category_{$categoryId}", new Route("/category{$fullSlug}", ['_controller' => 'HarentiusBlogBundle:Blog:list', 'filtrationType' => 'category', 'criteria' => $categoryId]));
     }
     return $this->routes;
 }
示例#26
0
 public function testDump()
 {
     $collection = new RouteCollection();
     $collection->add('foo', new Route('/foo/:bar', array('def' => 'test'), array('bar' => 'baz|symfony')));
     $collection->add('bar', new Route('/bar/:foo', array(), array('_method' => 'GET|head')));
     $dumper = new ApacheMatcherDumper($collection);
     $this->assertStringEqualsFile(self::$fixturesPath . '/dumper/url_matcher1.apache', $dumper->dump(), '->dump() dumps basic routes to the correct apache format.');
 }
示例#27
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
         if ($route = $this->getRdfExportRoute($entity_type)) {
             $collection->add("entity.{$entity_type_id}.rdf_export", $route);
             $collection->add("entity.{$entity_type_id}.rdf_export_download", $this->getDownloadRoute($entity_type));
         }
     }
 }
示例#28
0
 /**
  * @param $importedRoute
  * @param $importedRouteName
  */
 private function generatePortalRoutes(Route $importedRoute, $importedRouteName)
 {
     foreach ($this->webspaceManager->getPortalInformations($this->environment) as $portalInformation) {
         $route = clone $importedRoute;
         $route->setHost($portalInformation->getHost());
         $route->setPath($portalInformation->getPrefix() . $route->getPath());
         $this->collection->add($portalInformation->getUrl() . '.' . $importedRouteName, $route);
     }
 }
 public function testDumpForRouteWithDefaults()
 {
     $this->routeCollection->add('Test', new Route('/testing/{foo}', array('foo' => 'bar')));
     file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'DefaultRoutesUrlGenerator')));
     include $this->testTmpFilepath;
     $projectUrlGenerator = new \DefaultRoutesUrlGenerator(new RequestContext());
     $url = $projectUrlGenerator->generate('Test', array());
     $this->assertEquals($url, '/testing');
 }
示例#30
0
 public function testAddPrefix()
 {
     $collection = new RouteCollection();
     $collection->add('foo', $foo = new Route('/foo'));
     $collection->add('bar', $bar = new Route('/bar'));
     $collection->addPrefix('/admin');
     $this->assertEquals('/admin/foo', $collection->get('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
     $this->assertEquals('/admin/bar', $collection->get('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
 }