class MockRouteProvider in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Routing/MockRouteProvider.php \Drupal\system\Tests\Routing\MockRouteProvider
Easily configurable mock route provider.
Hierarchy
- class \Drupal\system\Tests\Routing\MockRouteProvider implements RouteProviderInterface
Expanded class hierarchy of MockRouteProvider
1 file declares its use of MockRouteProvider
- SystemMenuBlockTest.php in core/
modules/ system/ src/ Tests/ Block/ SystemMenuBlockTest.php - Contains \Drupal\system\Tests\Block\SystemMenuBlockTest.
File
- core/
modules/ system/ src/ Tests/ Routing/ MockRouteProvider.php, line 18 - Contains \Drupal\system\Tests\Routing\MockRouteProvider.
Namespace
Drupal\system\Tests\RoutingView source
class MockRouteProvider implements RouteProviderInterface {
/**
* A collection of routes for this route provider.
*
* @var RouteCollection
*/
protected $routes;
/**
* Constructs a new MockRouteProvider.
*
* @param \Symfony\Component\Routing\RouteCollection $routes
* The route collection to use for this provider.
*/
public function __construct(RouteCollection $routes) {
$this->routes = $routes;
}
/**
* Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRouteCollectionForRequest().
*
* Simply return all routes to prevent
* \Symfony\Component\Routing\Exception\ResourceNotFoundException.
*/
public function getRouteCollectionForRequest(Request $request) {
return $this->routes;
}
/**
* {@inheritdoc}
*/
public function getRouteByName($name) {
$routes = $this
->getRoutesByNames(array(
$name,
));
if (empty($routes)) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
return reset($routes);
}
/**
* {@inheritdoc}
*/
public function preLoadRoutes($names) {
// Nothing to do.
}
/**
* {@inheritdoc}
*/
public function getRoutesByNames($names) {
$routes = array();
foreach ($names as $name) {
$routes[] = $this->routes
->get($name);
}
return $routes;
}
/**
* {@inheritdoc}
*/
public function getRoutesByPattern($pattern) {
return new RouteCollection();
}
/**
* {@inheritdoc}
*/
public function getAllRoutes() {
return $this->routes
->all();
}
/**
* {@inheritdoc}
*/
public function reset() {
$this->routes = array();
}
}