Merge branch 'kernel' into kernel-ajax

8.0.x
Peter Drake 2012-04-02 06:32:33 -07:00
commit a63f8a1c01
3 changed files with 30 additions and 24 deletions

View File

@ -5,6 +5,9 @@
* API for handling file uploads and server file management. * 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; use Drupal\Core\StreamWrapper\LocalStream;
/** /**
@ -2046,18 +2049,27 @@ function file_download() {
$function = $module . '_file_download'; $function = $module . '_file_download';
$result = $function($uri); $result = $function($uri);
if ($result == -1) { if ($result == -1) {
return drupal_access_denied(); throw new AccessDeniedHttpException();
} }
if (isset($result) && is_array($result)) { if (isset($result) && is_array($result)) {
$headers = array_merge($headers, $result); $headers = array_merge($headers, $result);
} }
} }
if (count($headers)) { 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();
} }

View File

@ -56,29 +56,22 @@ class UrlMatcher extends SymfonyUrlMatcher {
} }
if ($router_item = $this->matchDrupalItem($dpathinfo)) { 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(); // Most legacy controllers (aka page callbacks) are in a separate file,
$routes->add(hash('sha256', $router_item['path']), $this->convertDrupalItem($router_item)); // so we have to include that.
if ($router_item['include_file']) {
if ($ret = $this->matchCollection($pathinfo, $routes)) { require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
//drupal_set_message('<pre>' . var_export('test', TRUE) . '</pre>');
// 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;
} }
return $ret;
} }
throw 0 < count($this->allow) // This matcher doesn't differentiate by method, so don't bother with those
? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow))) // exceptions.
: new ResourceNotFoundException(); throw new ResourceNotFoundException();
} }
/** /**
@ -110,6 +103,7 @@ class UrlMatcher extends SymfonyUrlMatcher {
foreach ($page_arguments as $k => $v) { foreach ($page_arguments as $k => $v) {
$route[$k] = $v; $route[$k] = $v;
} }
return $route;
return new Route($router_item['href'], $route); return new Route($router_item['href'], $route);
} }
} }

View File

@ -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('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 . '/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');
} }
/** /**