From b124f325b7a5fc11ede5b53c39974389de484714 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Sun, 1 Apr 2012 14:51:26 -0500 Subject: [PATCH 1/3] Simplify the UrlMatcher to just deal with Drupal menu items directly. We will likely bypass it and write a wholely new one later for the new routing system, and this better supports existing esoteric routes. --- core/lib/Drupal/Core/UrlMatcher.php | 32 ++++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/core/lib/Drupal/Core/UrlMatcher.php b/core/lib/Drupal/Core/UrlMatcher.php index 34ea187cccd9..2dd9d255c1ce 100644 --- a/core/lib/Drupal/Core/UrlMatcher.php +++ b/core/lib/Drupal/Core/UrlMatcher.php @@ -56,29 +56,22 @@ class UrlMatcher extends SymfonyUrlMatcher { } if ($router_item = $this->matchDrupalItem($dpathinfo)) { + $ret = $this->convertDrupalItem($router_item); + // Stash the router item in the attributes while we're transitioning. + $ret['drupal_menu_item'] = $router_item; - $routes = new RouteCollection(); - $routes->add(hash('sha256', $router_item['path']), $this->convertDrupalItem($router_item)); - - if ($ret = $this->matchCollection($pathinfo, $routes)) { - //drupal_set_message('
' . var_export('test', TRUE) . '
'); - // Stash the router item in the attributes while we're transitioning. - $ret['drupal_menu_item'] = $router_item; - - // Most legacy controllers (aka page callbacks) are in a separate file, - // so we have to include that. - if ($router_item['include_file']) { - require_once DRUPAL_ROOT . '/' . $router_item['include_file']; - } - - - return $ret; + // Most legacy controllers (aka page callbacks) are in a separate file, + // so we have to include that. + if ($router_item['include_file']) { + require_once DRUPAL_ROOT . '/' . $router_item['include_file']; } + + return $ret; } - throw 0 < count($this->allow) - ? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow))) - : new ResourceNotFoundException(); + // This matcher doesn't differentiate by method, so don't bother with those + // exceptions. + throw new ResourceNotFoundException(); } /** @@ -110,6 +103,7 @@ class UrlMatcher extends SymfonyUrlMatcher { foreach ($page_arguments as $k => $v) { $route[$k] = $v; } + return $route; return new Route($router_item['href'], $route); } } From 79d81019081bde8f22c7833c0f0fb05c3cbd1c81 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Sun, 1 Apr 2012 14:51:43 -0500 Subject: [PATCH 2/3] Convert file_download() to use Symfony's StreamedResponse object rather than hacking our own. --- core/includes/file.inc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/core/includes/file.inc b/core/includes/file.inc index eaff634e2778..fa6670de0287 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -5,6 +5,9 @@ * API for handling file uploads and server file management. */ +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpFoundation\StreamedResponse; use Drupal\Core\StreamWrapper\LocalStream; /** @@ -2046,18 +2049,27 @@ function file_download() { $function = $module . '_file_download'; $result = $function($uri); if ($result == -1) { - return drupal_access_denied(); + throw new AccessDeniedHttpException(); } if (isset($result) && is_array($result)) { $headers = array_merge($headers, $result); } } if (count($headers)) { - file_transfer($uri, $headers); + return new StreamedResponse(function() use ($uri) { + $scheme = file_uri_scheme($uri); + // Transfer file in 1024 byte chunks to save memory usage. + if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) { + while (!feof($fd)) { + print fread($fd, 1024); + } + fclose($fd); + } + }, 200, $headers); } - return drupal_access_denied(); + throw new AccessDeniedHttpException(); } - return drupal_not_found(); + throw new NotFoundHttpException(); } From 31b8653f9f57287457c8c979ed715a772d5f03ed Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Sun, 1 Apr 2012 15:37:54 -0500 Subject: [PATCH 3/3] Update unit test for new clean URL format. --- core/modules/simpletest/tests/file.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/simpletest/tests/file.test b/core/modules/simpletest/tests/file.test index c5eced152c1f..00bda2501542 100644 --- a/core/modules/simpletest/tests/file.test +++ b/core/modules/simpletest/tests/file.test @@ -2423,7 +2423,7 @@ class FileDownloadTest extends FileTestCase { $this->checkUrl('public', '', $basename, $base_url . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . $basename_encoded); $this->checkUrl('private', '', $basename, $base_url . '/system/files/' . $basename_encoded); - $this->checkUrl('private', '', $basename, $base_url . '/?q=system/files/' . $basename_encoded, '0'); + $this->checkUrl('private', '', $basename, $base_url . '/index.php/system/files/' . $basename_encoded, '0'); } /**