本文整理匯總了PHP中Symfony\Component\Routing\RouteCollection::all方法的典型用法代碼示例。如果您正苦於以下問題:PHP RouteCollection::all方法的具體用法?PHP RouteCollection::all怎麽用?PHP RouteCollection::all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Routing\RouteCollection
的用法示例。
在下文中一共展示了RouteCollection::all方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetRouteCollectionWithRoutes
public function testGetRouteCollectionWithRoutes()
{
$routes = new RouteCollection();
$controllers = new ControllerCollection($routes);
$controllers->add(new Controller(new Route('/foo')));
$controllers->add(new Controller(new Route('/bar')));
$this->assertEquals(0, count($routes->all()));
$controllers->flush();
$this->assertEquals(2, count($routes->all()));
}
示例2: 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);
}
示例3: match
/**
* {@inheritdoc}
*/
public function match($theClass, $theMethod)
{
$routes = $this->routes->all();
foreach ($routes as $name => $route) {
$controller = $route->getDefault('_controller');
if (false !== strpos($controller, "::")) {
list($class, $method) = explode('::', $controller, 2);
if ($class === $theClass && $method === $theMethod) {
return array($name, $route);
return array('name' => $name, 'route' => $route);
}
}
}
throw new ResourceNotFoundException();
}
示例4: 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));
}
示例5: describeRouteCollection
/**
* {@inheritdoc}
*/
protected function describeRouteCollection(RouteCollection $routes, array $options = array())
{
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
$tableHeaders = array('Name', 'Method', 'Scheme', 'Host', 'Path');
if ($showControllers) {
$tableHeaders[] = 'Controller';
}
$tableRows = array();
foreach ($routes->all() as $name => $route) {
$row = array($name, $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', '' !== $route->getHost() ? $route->getHost() : 'ANY', $route->getPath());
if ($showControllers) {
$controller = $route->getDefault('_controller');
if ($controller instanceof \Closure) {
$controller = 'Closure';
} elseif (is_object($controller)) {
$controller = get_class($controller);
}
$row[] = $controller;
}
$tableRows[] = $row;
}
if (isset($options['output'])) {
$options['output']->table($tableHeaders, $tableRows);
} else {
$table = new Table($this->getOutput());
$table->setHeaders($tableHeaders)->setRows($tableRows);
$table->render();
}
}
示例6: describeRouteCollection
/**
* {@inheritdoc}
*/
protected function describeRouteCollection(RouteCollection $routes, array $options = array())
{
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
$headers = array('Name', 'Method', 'Scheme', 'Host', 'Path');
$table = new TableHelper();
$table->setLayout(TableHelper::LAYOUT_COMPACT);
$table->setHeaders($showControllers ? array_merge($headers, array('Controller')) : $headers);
foreach ($routes->all() as $name => $route) {
$row = array(
$name,
$route->getMethods() ? implode('|', $route->getMethods()) : 'ANY',
$route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY',
'' !== $route->getHost() ? $route->getHost() : 'ANY',
$route->getPath(),
);
if ($showControllers) {
$controller = $route->getDefault('_controller');
if ($controller instanceof \Closure) {
$controller = 'Closure';
} elseif (is_object($controller)) {
$controller = get_class($controller);
}
$row[] = $controller;
}
$table->addRow($row);
}
$this->writeText($this->formatSection('router', 'Current routes')."\n", $options);
$this->renderTable($table, !(isset($options['raw_output']) && $options['raw_output']));
}
示例7: getRouteCollection
/**
* {@inheritdoc}
*/
public function getRouteCollection()
{
static $i18nCollection;
if ($i18nCollection instanceof RouteCollection === false) {
if (null === $this->collection) {
$this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
}
$i18nCollection = new RouteCollection();
foreach ($this->collection->getResources() as $resource) {
$i18nCollection->addResource($resource);
}
foreach ($this->collection->all() as $name => $route) {
//do not add i18n routing prefix
if ($this->shouldExcludeRoute($name, $route)) {
$i18nCollection->add($name, $route);
continue;
}
//add i18n routing prefix
foreach ($this->generateI18nPatterns($name, $route) as $pattern => $locales) {
foreach ($locales as $locale) {
$localeRoute = clone $route;
$localeRoute->setPath($pattern);
$localeRoute->setDefault('_locale', $locale);
$i18nCollection->add($locale . self::ROUTING_PREFIX . $name, $localeRoute);
}
}
}
}
return $i18nCollection;
}
示例8: 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);
}
}
示例9: load
public function load(RouteCollection $collection)
{
$i18nCollection = new RouteCollection();
foreach ($collection->getResources() as $resource) {
$i18nCollection->addResource($resource);
}
$this->patternGenerationStrategy->addResources($i18nCollection);
foreach ($collection->all() as $name => $route) {
if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
$i18nCollection->add($name, $route);
continue;
}
foreach ($this->patternGenerationStrategy->generateI18nPatterns($name, $route) as $pattern => $locales) {
// If this pattern is used for more than one locale, we need to keep the original route.
// We still add individual routes for each locale afterwards for faster generation.
if (count($locales) > 1) {
$catchMultipleRoute = clone $route;
$catchMultipleRoute->getPath($pattern);
$catchMultipleRoute->setDefault('_locales', $locales);
$i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchMultipleRoute);
}
foreach ($locales as $locale) {
$localeRoute = clone $route;
$localeRoute->getPath($pattern);
$localeRoute->setDefault('_locale', $locale);
$i18nCollection->add($locale . I18nLoader::ROUTING_PREFIX . $name, $localeRoute);
}
}
}
return $i18nCollection;
}
示例10: testCheck
/**
* Tests \Drupal\Core\Access\AccessManager::check().
*/
public function testCheck()
{
$route_matches = [];
// Construct route match objects.
foreach ($this->routeCollection->all() as $route_name => $route) {
$route_matches[$route_name] = new RouteMatch($route_name, $route, [], []);
}
// Check route access without any access checker defined yet.
foreach ($route_matches as $route_match) {
$this->assertEquals(FALSE, $this->accessManager->check($route_match, $this->account));
$this->assertEquals(AccessResult::neutral(), $this->accessManager->check($route_match, $this->account, NULL, TRUE));
}
$this->setupAccessChecker();
// An access checker got setup, but the routes haven't been setup using
// setChecks.
foreach ($route_matches as $route_match) {
$this->assertEquals(FALSE, $this->accessManager->check($route_match, $this->account));
$this->assertEquals(AccessResult::neutral(), $this->accessManager->check($route_match, $this->account, NULL, TRUE));
}
// Now applicable access checks have been saved on each route object.
$this->checkProvider->setChecks($this->routeCollection);
$this->setupAccessArgumentsResolverFactory();
$this->assertEquals(FALSE, $this->accessManager->check($route_matches['test_route_1'], $this->account));
$this->assertEquals(TRUE, $this->accessManager->check($route_matches['test_route_2'], $this->account));
$this->assertEquals(FALSE, $this->accessManager->check($route_matches['test_route_3'], $this->account));
$this->assertEquals(TRUE, $this->accessManager->check($route_matches['test_route_4'], $this->account));
$this->assertEquals(AccessResult::neutral(), $this->accessManager->check($route_matches['test_route_1'], $this->account, NULL, TRUE));
$this->assertEquals(AccessResult::allowed(), $this->accessManager->check($route_matches['test_route_2'], $this->account, NULL, TRUE));
$this->assertEquals(AccessResult::forbidden(), $this->accessManager->check($route_matches['test_route_3'], $this->account, NULL, TRUE));
$this->assertEquals(AccessResult::allowed(), $this->accessManager->check($route_matches['test_route_4'], $this->account, NULL, TRUE));
}
示例11: describeRouteCollection
/**
* {@inheritdoc}
*/
protected function describeRouteCollection(RouteCollection $routes, array $options = array())
{
$data = array();
foreach ($routes->all() as $name => $route) {
$data[$name] = $this->getRouteData($route);
}
$this->writeData($data, $options);
}
示例12: dump
function dump()
{
$stamp = new \DateTime();
$time = $stamp->format("r");
$result = <<<EOF
<?php
/**
*
* Route Dump
* This is a generated file , do not edit
* <timestamp>{$time}</timestamp>
*/
use Symfony\\Component\\Routing\\RouteCollection;
use Symfony\\Component\\Routing\\Route;
\$routeCollection = new RouteCollection();
EOF;
$fields = array("Defaults", "Host", "Methods", "Options", "Path", "Requirements", "Schemes");
foreach ($this->routeCollection->all() as $name => $route) {
$result .= <<<EOF
/**
*
* route named {$name}
*
*/
EOF;
$route_name = "\$route" . preg_replace("/!\\W/im", "_", $name);
$result .= "\n{$route_name} = new Route(" . var_export($route->getPath(), true) . ");";
/* @var $route Route */
foreach ($fields as $field) {
if ($route->{"get{$field}"}() != null) {
$result .= "\n{$route_name}->set{$field}(" . var_export($route->{"get{$field}"}(), true) . ");";
}
}
// echo $name;
//print_r($route);
$result .= "\n\$routeCollection->add('{$name}',{$route_name});";
}
$result .= "\nreturn \$routeCollection;";
return $result;
}
示例13: alterRoutes
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection)
{
foreach ($collection->all() as $route) {
if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route')) {
$route->setOption('_admin_route', TRUE);
}
}
}
示例14: all
/**
* Returns all routes in this collection.
*
* @return Route[] An array of routes
*/
public function all()
{
$routeCollectionAll = new RouteCollection();
foreach ($this->routeCollections as $routeCollection) {
$routeCollectionAll->addCollection($routeCollection);
}
return $routeCollectionAll->all();
}
示例15: currentRouteName
/**
* Get the current route name.
*
* @return string|null
*/
public function currentRouteName()
{
foreach ($this->routes->all() as $name => $route) {
if ($route === $this->currentRoute) {
return $name;
}
}
}