Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Drupal\Core\Routes;
- use Symfony\Component\Routing;
- use Symfony\Component\Routing\RouteCollection;
- use Symfony\Component\Routing\Route;
- class DrupalRoutes {
- protected $routes;
- static protected $shared;
- public function __construct() {
- $this->routes = array();
- foreach (module_implements('menu') as $module) {
- $this->routes[$module] = module_invoke($module, 'menu');
- }
- }
- public function getRoutes() {
- if (isset(self::$shared['routes'])) {
- return self::$shared['routes'];
- }
- $routes = new RouteCollection();
- foreach ($this->routes as $module => $items) {
- foreach ($items as $path => $item) {
- $name = str_replace(array('/', '%', '-'), array('.', '_', ''), $path);
- $path_parts = explode('/', $path);
- $arguments = array(
- 'arguments' => array(),
- );
- foreach ($path_parts as $key => $part) {
- if (substr($part, 0, 1) == '%') {
- $arguments['arguments'] += array($key => substr($part, 1));
- $path_parts[$key] = '{' . substr($part, 1) . '}';
- }
- }
- $path = implode('/', $path_parts);
- if (isset($item['page callback'])) {
- $item += array(
- 'page arguments' => array(),
- 'access callback' => 'user_access',
- 'access arguments' => array(),
- );
- if (isset($item['file']) && !isset($item['file path'])) {
- $item['file path'] = drupal_get_path('module', $module);
- }
- $arguments['menu item'] = $item;
- $routes->add($name, new Route($path, $arguments));
- }
- }
- }
- return self::$shared['routes'] = $routes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment