Exemplo n.º 1
0
 /**
  * {@inheritDocs}
  */
 public function match($pathinfo)
 {
     // The 'q' variable is pervasive in Drupal, so it's best to just keep
     // it even though it's very un-Symfony.
     $path = drupal_get_normal_path(substr($pathinfo, 1));
     if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
         menu_rebuild();
     }
     $original_map = arg(NULL, $path);
     $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
     $ancestors = menu_get_ancestors($parts);
     $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();
     if ($router_item) {
         // Allow modules to alter the router item before it is translated and
         // checked for access.
         drupal_alter('menu_get_item', $router_item, $path, $original_map);
         // The requested path is an unalaised Drupal route.
         return array('_drupal' => true, '_controller' => function ($_router_item) {
             $router_item = $_router_item;
             if (!$router_item['access']) {
                 throw new AccessDeniedException();
             }
             if ($router_item['include_file']) {
                 require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
             }
             return call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
         }, '_route' => $router_item['path']);
     }
     throw new ResourceNotFoundException();
 }
 /**
  * Get the non translated menu item.
  *
  * @param string $path
  *   The path to match the router item. Leave it empty to use the current one.
  *
  * @return array
  *   The page arguments.
  *
  * @see menu_get_item()
  */
 protected static function getMenuItem($path = NULL)
 {
     $router_items =& drupal_static(__METHOD__);
     if (!isset($path)) {
         $path = $_GET['q'];
     }
     if (!isset($router_items[$path])) {
         $original_map = arg(NULL, $path);
         $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
         $ancestors = menu_get_ancestors($parts);
         $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();
         if ($router_item) {
             // Allow modules to alter the router item before it is translated and
             // checked for access.
             drupal_alter('menu_get_item', $router_item, $path, $original_map);
             $router_item['original_map'] = $original_map;
             if ($original_map === FALSE) {
                 $router_items[$path] = FALSE;
                 return FALSE;
             }
             $router_item['map'] = $original_map;
             $router_item['page_arguments'] = array_merge(menu_unserialize($router_item['page_arguments'], $original_map), array_slice($original_map, $router_item['number_parts']));
             $router_item['theme_arguments'] = array_merge(menu_unserialize($router_item['theme_arguments'], $original_map), array_slice($original_map, $router_item['number_parts']));
         }
         $router_items[$path] = $router_item;
     }
     return $router_items[$path];
 }
 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app['drupal.bootstrap.class'] = 'Bangpound\\Bridge\\Drupal\\Bootstrap';
     $app['drupal.class'] = 'Druplex';
     $app['legacy.request_matcher'] = $app->share($app->extend('legacy.request_matcher', function (RequestMatcher $matcher, $c) {
         $matcher->matchAttribute('_legacy', 'drupal');
         return $matcher;
     }));
     $app['drupal.listener.header'] = $app->share(function ($c) {
         return new HeaderListener($c['legacy.request_matcher']);
     });
     $app['drupal.bootstrap'] = $app->share(function () use($app) {
         /** @var Bootstrap $bootstrap */
         $bootstrap = new $app['drupal.bootstrap.class']();
         $bootstrap->setEventDispatcher($app['dispatcher']);
         require_once $app['web_dir'] . '/includes/bootstrap.inc';
         drupal_bootstrap(NULL, TRUE, $bootstrap);
         return $bootstrap;
     });
     $app->before(function (Request $request) use($app) {
         $app['drupal.bootstrap'];
         define('DRUPAL_ROOT', getcwd());
         drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
         $pathinfo = $request->getPathInfo();
         // The 'q' variable is pervasive in Drupal, so it's best to just keep
         // it even though it's very un-Symfony.
         $path = drupal_get_normal_path(substr($pathinfo, 1));
         if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
             menu_rebuild();
         }
         $original_map = arg(NULL, $path);
         $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
         $ancestors = menu_get_ancestors($parts);
         $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();
         if ($router_item) {
             // Allow modules to alter the router item before it is translated and
             // checked for access.
             drupal_alter('menu_get_item', $router_item, $path, $original_map);
             // The requested path is an unalaised Drupal route.
             $request->attributes->add(array('_route' => $router_item['path'], '_legacy' => 'drupal'));
         }
     }, 33);
 }