当前位置: 首页>>代码示例>>PHP>>正文


PHP RouteCollection::remove方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\RouteCollection::remove方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteCollection::remove方法的具体用法?PHP RouteCollection::remove怎么用?PHP RouteCollection::remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\RouteCollection的用法示例。


在下文中一共展示了RouteCollection::remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: alterRoutes

 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($collection as $name => $route) {
         if ($route->hasRequirement('_module_dependencies')) {
             $modules = $route->getRequirement('_module_dependencies');
             $explode_and = $this->explodeString($modules, '+');
             if (count($explode_and) > 1) {
                 foreach ($explode_and as $module) {
                     // If any moduleExists() call returns FALSE, remove the route and
                     // move on to the next.
                     if (!$this->moduleHandler->moduleExists($module)) {
                         $collection->remove($name);
                         continue 2;
                     }
                 }
             } else {
                 // OR condition, exploding on ',' character.
                 foreach ($this->explodeString($modules, ',') as $module) {
                     if ($this->moduleHandler->moduleExists($module)) {
                         continue 2;
                     }
                 }
                 // If no modules are found, and we get this far, remove the route.
                 $collection->remove($name);
             }
         }
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:31,代码来源:ModuleRouteSubscriber.php

示例2: filter

 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     $method = $request->getMethod();
     $all_supported_methods = [];
     foreach ($collection->all() as $name => $route) {
         $supported_methods = $route->getMethods();
         // A route not restricted to specific methods allows any method. If this
         // is the case, we'll also have at least one route left in the collection,
         // hence we don't need to calculate the set of all supported methods.
         if (empty($supported_methods)) {
             continue;
         }
         // If the GET method is allowed we also need to allow the HEAD method
         // since HEAD is a GET method that doesn't return the body.
         if (in_array('GET', $supported_methods, TRUE)) {
             $supported_methods[] = 'HEAD';
         }
         if (!in_array($method, $supported_methods, TRUE)) {
             $all_supported_methods = array_merge($supported_methods, $all_supported_methods);
             $collection->remove($name);
         }
     }
     if (count($collection)) {
         return $collection;
     }
     throw new MethodNotAllowedException(array_unique($all_supported_methods));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:30,代码来源:MethodFilter.php

示例3: alterRoutes

 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->entityStorage->loadMultiple() as $entity_id => $entity) {
         /** @var $entity \Drupal\page_manager\PageInterface */
         // If the page is disabled skip making a route for it.
         if (!$entity->status() || $entity->isFallbackPage()) {
             continue;
         }
         // Prepare a route name to use if this is a custom page.
         $route_name = "page_manager.page_view_{$entity_id}";
         // Prepare the values that need to be altered for an existing page.
         $path = $entity->getPath();
         $parameters = ['page_manager_page' => ['type' => 'entity:page']];
         // Loop through all existing routes to see if this is overriding a route.
         foreach ($collection->all() as $name => $collection_route) {
             // Find all paths which match the path of the current display.
             $route_path = RouteCompiler::getPathWithoutDefaults($collection_route);
             $route_path = RouteCompiler::getPatternOutline($route_path);
             if ($path == $route_path) {
                 // Adjust the path to translate %placeholders to {slugs}.
                 $path = $collection_route->getPath();
                 // Merge in any route parameter definitions.
                 $parameters += $collection_route->getOption('parameters') ?: [];
                 // Update the route name this will be added to.
                 $route_name = $name;
                 // Remove the existing route.
                 $collection->remove($route_name);
                 break;
             }
         }
         // Construct an add a new route.
         $route = new Route($path, ['_entity_view' => 'page_manager_page', 'page_manager_page' => $entity_id, '_title' => $entity->label()], ['_entity_access' => 'page_manager_page.view'], ['parameters' => $parameters, '_admin_route' => $entity->usesAdminTheme()]);
         $collection->add($route_name, $route);
     }
 }
开发者ID:pulibrary,项目名称:recap,代码行数:38,代码来源:PageManagerRoutes.php

示例4: filter

 /**
  * {@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))));
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:36,代码来源:AcceptHeaderMatcher.php

示例5: filter

 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     // The Content-type header does not make sense on GET requests, because GET
     // requests do not carry any content. Nothing to filter in this case.
     if ($request->isMethod('GET')) {
         return $collection;
     }
     $format = $request->getContentType();
     foreach ($collection as $name => $route) {
         $supported_formats = array_filter(explode('|', $route->getRequirement('_content_type_format')));
         if (empty($supported_formats)) {
             // No restriction on the route, so we move the route to the end of the
             // collection by re-adding it. That way generic routes sink down in the
             // list and exact matching routes stay on top.
             $collection->add($name, $route);
         } elseif (!in_array($format, $supported_formats)) {
             $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 415.
     throw new UnsupportedMediaTypeHttpException('No route found that matches "Content-Type: ' . $request->headers->get('Content-Type') . '"');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:ContentTypeHeaderMatcher.php

示例6: storeRoutes

 protected function storeRoutes(RouteCollection $collection)
 {
     $stored = [];
     foreach ($this->routeManager->getAllRoutes() as $routeName) {
         $stored[$routeName] = $collection->get($routeName);
         $collection->remove($routeName);
     }
     $this->storage->save($stored);
     $this->stored = true;
 }
开发者ID:symedit,项目名称:symedit,代码行数:10,代码来源:Router.php

示例7: addCollection

 public function addCollection(RouteCollection $collection)
 {
     foreach ($collection->all() as $name => $route) {
         $this->add($name, $route);
     }
     // remove all the routes so that we have an empty collection when calling parent method
     // and we are not re-adding the routes again
     $collection->remove(array_keys($collection->all()));
     // call parent method with empty collection to merge the collection's resources
     parent::addCollection($collection);
 }
开发者ID:lschricke,项目名称:symfony-strict-route-collection,代码行数:11,代码来源:SymfonyStrictRouteCollection.php

示例8: load

 /**
  * Loads the i18n routes.
  *
  * @param RouteCollection $routes A RouteCollection instance
  */
 public function load(RouteCollection $routes)
 {
     // dump($routes->all());die;
     foreach ($routes->all() as $name => $route) {
         if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
             continue;
         }
         foreach ($this->pathGenerationStrategy->generateI18nPaths($name, $route) as $path => $locales) {
             foreach ($locales as $locale) {
                 $localeRoute = clone $route;
                 $localeRoute->setPath($path);
                 $localeRoute->setDefault('_locale', $locale);
                 $routes->add(sprintf('%s%s%s', $locale, self::ROUTING_PREFIX, $name), $localeRoute);
             }
             // Removes the default route, we do not need it any more
             $routes->remove($name);
         }
     }
 }
开发者ID:sfblaauw,项目名称:pulsar-i18n-routing,代码行数:24,代码来源:I18nLoader.php

示例9: filter

 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     $format = $request->getRequestFormat('html');
     /** @var \Symfony\Component\Routing\Route $route */
     foreach ($collection as $name => $route) {
         // If the route has no _format specification, we move it to the end. If it
         // does, then no match means the route is removed entirely.
         if ($supported_formats = array_filter(explode('|', $route->getRequirement('_format')))) {
             if (!in_array($format, $supported_formats)) {
                 $collection->remove($name);
             }
         } else {
             $collection->add($name, $route);
         }
     }
     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("No route found for the specified format {$format}.");
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:RequestFormatRouteFilter.php

示例10: filter

 /**
  * {@inheritdoc}
  *
  * Invalid page manager routes will be removed. Routes not controlled by page
  * manager will be moved to the end of the collection. Once a valid page
  * manager route has been found, all other page manager routes will also be
  * removed.
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     // Only proceed if the collection is non-empty.
     if (!$collection->count()) {
         return $collection;
     }
     // Store the unaltered request attributes.
     $original_attributes = $request->attributes->all();
     $page_manager_route_found = FALSE;
     foreach ($collection as $name => $route) {
         $attributes = $this->getRequestAttributes($route, $name, $request);
         // Add the enhanced attributes to the request.
         $request->attributes->add($attributes);
         if ($page_variant_id = $route->getDefault('page_manager_page_variant')) {
             // If a page manager route was already found, remove this one from the
             // collection.
             if ($page_manager_route_found) {
                 $collection->remove($name);
             } elseif ($this->checkPageVariantAccess($page_variant_id)) {
                 // Mark that a valid page manager route was found.
                 $page_manager_route_found = TRUE;
                 // Replace the original attributes with the newly processed attributes.
                 $original_attributes = $request->attributes->all();
             } else {
                 // Remove routes for variants that fail access.
                 $collection->remove($name);
             }
         } else {
             // If this route has no page variant, move it to the end of the list.
             $collection->add($name, $route);
         }
         // Restore the original request attributes.
         $request->attributes->replace($original_attributes);
     }
     return $collection;
 }
开发者ID:AllieRays,项目名称:debugging-drupal-8,代码行数:44,代码来源:VariantRouteFilter.php

示例11: removeMappingSourceRoutes

 /**
  * @param RouteCollection $collection
  *
  * @return RouteCollection
  */
 protected function removeMappingSourceRoutes($collection)
 {
     $appSlugs = $this->findAllApplicationSlugs($this->mappings);
     $trailingRoutesOrdering = 1000;
     foreach ($collection->all() as $name => $route) {
         if ($route->getOption('do_not_remove') || $route->getOption('force_mapping')) {
             continue;
         }
         // Remove the trailing routes and keep it in an array to place it back at the end of the Router
         if ($route->getOption('trailing_route')) {
             if (!($ordering = $route->getOption('ordering'))) {
                 $ordering = $trailingRoutesOrdering;
                 $trailingRoutesOrdering++;
             }
             $this->trailingRoutes[$ordering] = ['name' => $name, 'route' => $route];
             $collection->remove($name);
         }
         if (preg_match('/' . static::ROUTING_PREFIX . 'unifik_|_' . implode('_|_', $appSlugs) . '_/', $name)) {
             $collection->remove($name);
         }
     }
     return $collection;
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:28,代码来源:Loader.php

示例12: testRemove

 public function testRemove()
 {
     $collection = new RouteCollection();
     $collection->add('foo', $foo = new Route('/foo'));
     $collection1 = new RouteCollection();
     $collection1->add('bar', $bar = new Route('/bar'));
     $collection->addCollection($collection1);
     $collection->add('last', $last = new Route('/last'));
     $collection->remove('foo');
     $this->assertSame(array('bar' => $bar, 'last' => $last), $collection->all(), '->remove() can remove a single route');
     $collection->remove(array('bar', 'last'));
     $this->assertSame(array(), $collection->all(), '->remove() accepts an array and can remove multiple routes at once');
 }
开发者ID:mawaha,项目名称:tracker,代码行数:13,代码来源:RouteCollectionTest.php

示例13: removeRoute

 /**
  * @override
  * @inheritDoc
  */
 public function removeRoute($path)
 {
     $this->routes->remove($path);
     return $this;
 }
开发者ID:khelle,项目名称:surume,代码行数:9,代码来源:HttpRouter.php

示例14: removeRoute

 public function removeRoute($name)
 {
     $this->routeCollection->remove($name);
 }
开发者ID:mpoiriert,项目名称:nucleus,代码行数:4,代码来源:Router.php

示例15: alterRoutes

 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     $view_route_names = array();
     $view_path = $this->getPath();
     foreach ($collection->all() as $name => $route) {
         // Find all paths which match the path of the current display..
         $route_path = RouteCompiler::getPathWithoutDefaults($route);
         $route_path = RouteCompiler::getPatternOutline($route_path);
         // Ensure that we don't override a route which is already controlled by
         // views.
         if (!$route->hasDefault('view_id') && '/' . $view_path == $route_path) {
             $parameters = $route->compile()->getPathVariables();
             // @todo Figure out whether we need to merge some settings (like
             // requirements).
             // Replace the existing route with a new one based on views.
             $original_route = $collection->get($name);
             $collection->remove($name);
             $view_id = $this->view->storage->id();
             $display_id = $this->display['id'];
             $route = $this->getRoute($view_id, $display_id);
             $path = $route->getPath();
             // Replace the path with the original parameter names and add a mapping.
             $argument_map = array();
             // We assume that the numeric ids of the parameters match the one from
             // the view argument handlers.
             foreach ($parameters as $position => $parameter_name) {
                 $path = str_replace('{arg_' . $position . '}', '{' . $parameter_name . '}', $path);
                 $argument_map['arg_' . $position] = $parameter_name;
             }
             // Copy the original options from the route, so for example we ensure
             // that parameter conversion options is carried over.
             $route->setOptions($route->getOptions() + $original_route->getOptions());
             // Set the corrected path and the mapping to the route object.
             $route->setOption('_view_argument_map', $argument_map);
             $route->setPath($path);
             $collection->add($name, $route);
             $view_route_names[$view_id . '.' . $display_id] = $name;
         }
     }
     return $view_route_names;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:44,代码来源:PathPluginBase.php


注:本文中的Symfony\Component\Routing\RouteCollection::remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。