Merge branch 'kernel' into kernel-ajax
commit
a63f8a1c01
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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('<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;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue