diff --git a/core/includes/common.inc b/core/includes/common.inc index aea8529..3b87448 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3,6 +3,7 @@ use Drupal\Component\Utility\NestedArray; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Database\Database; use Drupal\Core\Template\Attribute; @@ -697,12 +698,8 @@ function drupal_goto($path = '', array $options = array(), $http_response_code = $url = url($path, $options); - header('Location: ' . $url, TRUE, $http_response_code); - - // The "Location" header sends a redirect status code to the HTTP daemon. In - // some cases this can be wrong, so we make sure none of the code below the - // drupal_goto() call gets executed upon redirection. - drupal_exit($url); + // The "Location" header sends a redirect status code to the HTTP daemon. + return new RedirectResponse($url); } /** diff --git a/core/includes/install.inc b/core/includes/install.inc index efba3c1..2243dac 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -5,6 +5,7 @@ * API functions for installing modules and themes. */ +use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Core\Database\Database; use Drupal\locale\Gettext; @@ -660,10 +661,10 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) { */ function install_goto($path) { global $base_url; - include_once DRUPAL_ROOT . '/core/includes/common.inc'; - header('Location: ' . $base_url . '/' . $path); - header('Cache-Control: no-cache'); // Not a permanent redirect. - drupal_exit(); + $headers = array( + 'Cache-Control' => 'no-cache', // Not a permanent redirect. + ); + return new RedirectResponse($base_url . '/' . $path, 302, $headers); } /** diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 01d2b3b..50efea2 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\Component\Uuid\Uuid; use Drupal\file\File; @@ -725,7 +726,7 @@ function image_style_options($include_empty = TRUE) { function image_style_deliver($style, $scheme) { // Check that the style is defined and the scheme is valid. if (!$style || !file_stream_wrapper_valid_scheme($scheme)) { - drupal_exit(); + throw new NotFoundHttpException(); } $args = func_get_args(); @@ -769,10 +770,8 @@ function image_style_deliver($style, $scheme) { if (!$lock_acquired) { // Tell client to retry again in 3 seconds. Currently no browsers are known // to support Retry-After. - drupal_add_http_header('Status', '503 Service Unavailable'); - drupal_add_http_header('Retry-After', 3); - print t('Image generation in progress. Try again shortly.'); - drupal_exit(); + $headers = array('Retry-After' => 3); + return new Response(t('Image generation in progress. Try again shortly.'), 503, $headers); } } diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 76a5ee1..61174a0 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -248,10 +248,11 @@ function locale_translate_export_form_submit($form, &$form_state) { $writer->writeItems($reader); $writer->close(); - header("Content-Disposition: attachment; filename=$filename"); - header("Content-Type: text/plain; charset=utf-8"); - print file_get_contents($uri); - drupal_exit(); + $headers = array( + 'Content-Disposition' => "attachment; filename=$filename", + 'Content-Type' => 'text/plain; charset=utf-8', + ); + return new Response(file_get_contents($uri), 200, $headers); } else { drupal_set_message('Nothing to export.'); diff --git a/core/modules/openid/openid.inc b/core/modules/openid/openid.inc index 20fffac..290973c 100644 --- a/core/modules/openid/openid.inc +++ b/core/modules/openid/openid.inc @@ -5,6 +5,9 @@ * OpenID utility functions. */ +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Response; + /** * Diffie-Hellman Key Exchange Default Value. * @@ -74,9 +77,7 @@ function openid_redirect_http($url, $message) { } $sep = (strpos($url, '?') === FALSE) ? '?' : '&'; - header('Location: ' . $url . $sep . implode('&', $query), TRUE, 302); - - drupal_exit(); + return new RedirectResponse($url . $sep . implode('&', $query), 302); } /** @@ -97,9 +98,8 @@ function openid_redirect($url, $message) { $output .= '' . "\n"; $output .= "\n"; $output .= "\n"; - print $output; - drupal_exit(); + return new Response($output); } function openid_redirect_form($form, &$form_state, $url, $message) { diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 3ae575c..ce5427f 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -589,8 +589,7 @@ function overlay_page_delivery_callback_alter(&$callback) { */ function overlay_deliver_empty_page() { $empty_page = '' . drupal_get_css() . drupal_get_js() . ''; - print $empty_page; - drupal_exit(); + return new Response($empty_page); } /** diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 429e990..bc76a85 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -2223,8 +2223,11 @@ function system_run_cron() { * Menu callback: return information about PHP. */ function system_php() { + ob_start(); phpinfo(); - drupal_exit(); + $phpinfo = ob_get_contents(); + ob_end_clean(); + return new Response($phpinfo); } /** diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index 3c322a6..85ce218 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -5,6 +5,8 @@ * Helper module for the form API tests. */ +use Symfony\Component\HttpFoundation\JsonResponse; + /** * Implements hook_menu(). */ @@ -313,10 +315,7 @@ function form_test_menu() { * Form submit handler to return form values as JSON. */ function _form_test_submit_values_json($form, &$form_state) { - // This won't have a proper JSON header, but Drupal doesn't check for that - // anyway so this is fine until it's replaced with a JsonResponse. - print drupal_json_encode($form_state['values']); - drupal_exit(); + return new JsonResponse($form_state['values']); } /** diff --git a/core/modules/xmlrpc/xmlrpc.server.inc b/core/modules/xmlrpc/xmlrpc.server.inc index e1c160b..72aec1a 100644 --- a/core/modules/xmlrpc/xmlrpc.server.inc +++ b/core/modules/xmlrpc/xmlrpc.server.inc @@ -5,6 +5,9 @@ * Page callback file for the xmlrpc module. */ +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; + /** * Process an XML-RPC request. */ @@ -71,8 +74,7 @@ function xmlrpc_server($callbacks) { $data = file_get_contents('php://input'); if (!$data) { - print 'XML-RPC server accepts POST requests only.'; - drupal_exit(); + throw new MethodNotAllowedHttpException(array('POST'), 'XML-RPC server accepts POST requests only.'); } $xmlrpc_server->message = xmlrpc_message($data); if (!xmlrpc_message_parse($xmlrpc_server->message)) { @@ -131,10 +133,11 @@ function xmlrpc_server_error($error, $message = FALSE) { */ function xmlrpc_server_output($xml) { $xml = '' . "\n" . $xml; - drupal_add_http_header('Content-Length', strlen($xml)); - drupal_add_http_header('Content-Type', 'text/xml'); - echo $xml; - drupal_exit(); + $headers = array( + 'Content-Length' => strlen($xml), + 'Content-Type' => 'text/xml', + ); + return new Response($xml, 200, $headers); } /**