class MongodbRouterRouteProvider in MongoDB 8
A Route Provider front-end for all Drupal-stored routes.
Hierarchy
- class \Drupal\Core\Routing\RouteProvider implements \Symfony\Cmf\Component\Routing\PagedRouteProviderInterface, \Symfony\Component\EventDispatcher\EventSubscriberInterface, CacheableRouteProviderInterface, PreloadableRouteProviderInterface
- class \Drupal\mongodb\MongodbRouterRouteProvider
Expanded class hierarchy of MongodbRouterRouteProvider
1 string reference to 'MongodbRouterRouteProvider'
1 service uses MongodbRouterRouteProvider
File
- src/
MongodbRouterRouteProvider.php, line 20 - Contains Drupal\mongodb\MongodbRouterRouteProvider.
Namespace
Drupal\mongodbView source
class MongodbRouterRouteProvider extends RouteProvider {
/**
* The name of the table.
*
* Warning: this is used by SqlRouterProvider::getCandidateOutlines().
*
* @var string
*/
protected $tableName = 'routing';
/**
* @var \Drupal\mongoDb\MongoCollectionFactory $mongo
*/
protected $mongo;
/**
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
* The route builder.
* @param \Drupal\Core\State\State $state
* The state.
* @param string $table
* The table in the database to use for matching.
*/
function __construct(MongoCollectionFactory $mongo, RouteBuilderInterface $route_builder, StateInterface $state, CurrentPathStack $current_path) {
$this->mongo = $mongo;
$this->routeBuilder = $route_builder;
$this->state = $state;
$this->currentPath = $current_path;
}
/**
* {@inheritdoc}
*/
public function getRoutesByNames($names, $parameters = []) {
if (empty($names)) {
throw new \InvalidArgumentException('You must specify the route names to load');
}
$routes_to_load = array_values(array_diff($names, array_keys($this->routes)));
if ($routes_to_load) {
$routes = $this->mongo
->get($this->tableName)
->find(array(
'_id' => array(
'$in' => $routes_to_load,
),
));
foreach ($routes as $name => $route_array) {
$this->routes[$name] = $this
->getRouteFromArray($route_array);
}
}
return array_intersect_key($this->routes, array_flip($names));
}
/**
* {@inheritdoc}
*/
protected function getRoutesByPath($path) {
// Filter out each empty value, though allow '0' and 0, which would be
// filtered out by empty().
$parts = array_values(array_filter(explode('/', $path), function ($value) {
return $value !== NULL && $value !== '';
}));
$ancestors = $this
->getCandidateOutlines($parts);
$routes = $this->mongo
->get($this->tableName)
->find(array(
'pattern_outline' => array(
'$in' => $ancestors,
),
))
->sort(array(
'fit' => -1,
'_id' => 1,
));
$collection = new RouteCollection();
foreach ($routes as $name => $route_array) {
$route = $this
->getRouteFromArray($route_array);
if (preg_match($route
->compile()
->getRegex(), $path, $matches)) {
$collection
->add($name, $route);
}
}
return $collection;
}
/**
* Creates a Route object from an array.
*
* @param array $r
*
* @return \Symfony\Component\Routing\Route
*/
protected function getRouteFromArray(array $r) {
$r += array(
'defaults' => array(),
'requirements' => array(),
'options' => array(),
'host' => '',
'schemes' => array(),
'methods' => array(
'GET',
'POST',
),
'condition' => '',
'path' => $r['pattern_outline'],
);
return new Route($r['path'], $r['defaults'], $r['requirements'], $r['options'], $r['host'], $r['schemes'], $r['methods'], $r['condition']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MongodbRouterRouteProvider:: |
protected | property | ||
MongodbRouterRouteProvider:: |
protected | property |
The name of the table. Overrides RouteProvider:: |
|
MongodbRouterRouteProvider:: |
protected | function | Creates a Route object from an array. | |
MongodbRouterRouteProvider:: |
public | function |
Find many routes by their names using the provided list of names. Overrides RouteProvider:: |
|
MongodbRouterRouteProvider:: |
protected | function |
Get all routes which match a certain pattern. Overrides RouteProvider:: |
|
MongodbRouterRouteProvider:: |
function |
Overrides RouteProvider:: |
||
RouteProvider:: |
protected | property | The cache backend. | |
RouteProvider:: |
protected | property | The cache tag invalidator. | |
RouteProvider:: |
protected | property | The database connection from which to read route information. | |
RouteProvider:: |
protected | property | The current path. | |
RouteProvider:: |
protected | property | An array of cache key parts to be used for the route match cache. | |
RouteProvider:: |
protected | property | The language manager. | |
RouteProvider:: |
protected | property | A path processor manager for resolving the system path. | |
RouteProvider:: |
protected | property | A cache of already-loaded routes, keyed by route name. | |
RouteProvider:: |
protected | property | A cache of already-loaded serialized routes, keyed by route name. | |
RouteProvider:: |
protected | property | The state. | |
RouteProvider:: |
public | function |
Adds a cache key part to be used in the cache ID of the route collection. Overrides CacheableRouteProviderInterface:: |
|
RouteProvider:: |
public | function |
Returns all the routes on the system. Overrides RouteProviderInterface:: |
|
RouteProvider:: |
protected | function | Returns an array of path pattern outlines that could match the path parts. | 1 |
RouteProvider:: |
protected | function | Returns the language identifier for the route collection cache. | |
RouteProvider:: |
public | function | Find the route using the provided route name. | |
RouteProvider:: |
protected | function | Returns the cache ID for the route collection cache. | |
RouteProvider:: |
public | function | Finds routes that may potentially match the request. | |
RouteProvider:: |
public | function |
Get all routes which match a certain pattern. Overrides RouteProviderInterface:: |
|
RouteProvider:: |
public | function | Determines the total amount of routes. | |
RouteProvider:: |
public | function | Find an amount of routes with an offset and possible a limit. | |
RouteProvider:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RouteProvider:: |
public | function |
Pre-load routes by their names using the provided list of names. Overrides PreloadableRouteProviderInterface:: |
|
RouteProvider:: |
public | function |
Resets the route provider object. Overrides RouteProviderInterface:: |
|
RouteProvider:: |
protected | function | Comparison function for usort on routes. | |
RouteProvider:: |
constant | Cache ID prefix used to load routes. |