diff --git a/core/core.services.yml b/core/core.services.yml index 414f573..e5ad735 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1658,4 +1658,4 @@ services: tags: - { name: event_subscriber } shutdown_registry: - class: Drupal\Core\Utility\ShutDownRegistry + class: Drupal\Core\Utility\ShutdownRegistry diff --git a/core/includes/batch.inc b/core/includes/batch.inc index de17ba4..61d22b4 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -48,7 +48,7 @@ function _batch_page(Request $request) { } // Register database update for the end of processing. - \Drupal::service('shutdown_registry')->registerShutdownCallable('_batch_shutdown', TRUE); + \Drupal::service('shutdown_registry')->registerShutdownCallable('_batch_shutdown'); $build = array(); diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 9c976eb..49de811 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -974,31 +974,30 @@ function drupal_placeholder($text) { * * @see register_shutdown_function() * @ingroup php_wrappers + * @deprecated in Drupal 8.4.0, will be removed before Drupal 9.0.0. + * Use \Drupal\Core\Utility\ShutdownRegistry::registerShutdownCallable() to + * register functions and + * \Drupal\Core\Utility\ShutdownRegistry::getCallbacks() to retrieve + * registered functions. */ function &drupal_register_shutdown_function($callback = NULL) { - // We cannot use drupal_static() here because the static cache is reset during - // batch processing, which breaks batch handling. - static $callbacks = array(); + /** @var \Drupal\Core\Utility\ShutdownRegistry $shutdown_registry */ + $shutdown_registry = \Drupal::service('shutdown_registry'); if (isset($callback)) { - // Only register the internal shutdown function once. - if (empty($callbacks)) { - register_shutdown_function('_drupal_shutdown_function'); - } $args = func_get_args(); // Remove $callback from the arguments. unset($args[0]); - // Save callback and arguments - $callbacks[] = array('callback' => $callback, 'arguments' => $args); + $shutdown_registry->registerShutdownCallable($callback, $args); } - return $callbacks; + return $shutdown_registry->getCallbacks(); } /** * Executes registered shutdown functions. */ function _drupal_shutdown_function() { - $callbacks = &drupal_register_shutdown_function(); + $callbacks = Drupal::service('shutdown_registry')->getCallbacks(); // Set the CWD to DRUPAL_ROOT as it is not guaranteed to be the same as it // was in the normal context of execution. diff --git a/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php b/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php index 2c28117..0f07c37 100644 --- a/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php +++ b/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Render; -use Drupal\Core\Utility\ShutDownRegistry; +use Drupal\Core\Utility\ShutdownRegistry; /** * Default bare HTML page renderer. @@ -26,7 +26,7 @@ class BareHtmlPageRenderer implements BareHtmlPageRendererInterface { /** * The shutdown registry service. * - * @var \Drupal\Core\Utility\ShutDownRegistry + * @var \Drupal\Core\Utility\ShutdownRegistry */ protected $shutdownRegistry; @@ -37,10 +37,10 @@ class BareHtmlPageRenderer implements BareHtmlPageRendererInterface { * The renderer service. * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor * The HTML response attachments processor service. - * @param \Drupal\Core\Utility\ShutDownRegistry $shutdown_registry + * @param \Drupal\Core\Utility\ShutdownRegistry $shutdown_registry * The shutdown registry. */ - public function __construct(RendererInterface $renderer, AttachmentsResponseProcessorInterface $html_response_attachments_processor, ShutDownRegistry $shutdown_registry) { + public function __construct(RendererInterface $renderer, AttachmentsResponseProcessorInterface $html_response_attachments_processor, ShutdownRegistry $shutdown_registry) { $this->renderer = $renderer; $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor; $this->shutdownRegistry = $shutdown_registry; diff --git a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php index 1796c95..735b9e3 100644 --- a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php +++ b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php @@ -15,7 +15,7 @@ use Drupal\Core\Render\RendererInterface; use Drupal\Core\Render\RenderEvents; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Utility\ShutDownRegistry; +use Drupal\Core\Utility\ShutdownRegistry; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; @@ -84,7 +84,7 @@ class HtmlRenderer implements MainContentRendererInterface { /** * The shutdown registry service. * - * @var \Drupal\Core\Utility\ShutDownRegistry + * @var \Drupal\Core\Utility\ShutdownRegistry */ protected $shutdownRegistry; @@ -105,10 +105,10 @@ class HtmlRenderer implements MainContentRendererInterface { * The render cache service. * @param array $renderer_config * The renderer configuration array. - * @param \Drupal\Core\Utility\ShutDownRegistry $shutdown_registry + * @param \Drupal\Core\Utility\ShutdownRegistry $shutdown_registry * The shutdown registry. */ - public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, RendererInterface $renderer, RenderCacheInterface $render_cache, array $renderer_config, ShutDownRegistry $shutdown_registry) { + public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, RendererInterface $renderer, RenderCacheInterface $render_cache, array $renderer_config, ShutdownRegistry $shutdown_registry) { $this->titleResolver = $title_resolver; $this->displayVariantManager = $display_variant_manager; $this->eventDispatcher = $event_dispatcher; diff --git a/core/lib/Drupal/Core/Utility/ShutDownRegistry.php b/core/lib/Drupal/Core/Utility/ShutDownRegistry.php deleted file mode 100644 index 1a7fbda..0000000 --- a/core/lib/Drupal/Core/Utility/ShutDownRegistry.php +++ /dev/null @@ -1,53 +0,0 @@ -prevent_early_flush = TRUE; - } - } - - /** - * Gets whether early flushing of response should be prevented. - * - * @return bool - * TRUE if early flushing should be prevented, FALSE otherwise. - */ - public function preventEarlyFlush() { - return $this->prevent_early_flush; - } - -} diff --git a/core/lib/Drupal/Core/Utility/ShutdownRegistry.php b/core/lib/Drupal/Core/Utility/ShutdownRegistry.php new file mode 100644 index 0000000..d8c001c --- /dev/null +++ b/core/lib/Drupal/Core/Utility/ShutdownRegistry.php @@ -0,0 +1,73 @@ +callbacks)) { + register_shutdown_function('_drupal_shutdown_function'); + } + // Save callback and arguments. + $this->callbacks[] = ['callback' => $callable, 'arguments' => $arguments]; + if ($prevent_early_flush) { + $this->preventEarlyFlush = TRUE; + } + } + + /** + * Gets whether early flushing of response should be prevented. + * + * @return bool + * TRUE if early flushing should be prevented, FALSE otherwise. + */ + public function preventEarlyFlush() { + return $this->preventEarlyFlush; + } + + /** + * Get shutdown callbacks. + * + * @return \callable[] + * The callbacks. + */ + public function &getCallbacks() { + return $this->callbacks; + } + +}