From 2518b64a3de15fc7e0568d7cb94e4f48fd8f7371 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 3 Feb 2025 17:04:14 +0000 Subject: [PATCH] Set `editorUrl` from xdebug configuration The configuration files will override the xdebug configuration. --- src/DependencyInjection/ContainerFactory.php | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/DependencyInjection/ContainerFactory.php b/src/DependencyInjection/ContainerFactory.php index 75c79d6678..a7ff48df8c 100644 --- a/src/DependencyInjection/ContainerFactory.php +++ b/src/DependencyInjection/ContainerFactory.php @@ -39,14 +39,17 @@ use function count; use function dirname; use function extension_loaded; +use function get_cfg_var; use function getenv; use function ini_get; use function is_array; use function is_file; use function is_readable; +use function is_string; use function spl_object_id; use function sprintf; use function str_ends_with; +use function strtr; use function substr; /** @@ -149,6 +152,12 @@ public function create( $configurator->setAllConfigFiles($allConfigFiles); + if (!array_key_exists('editorUrl', $projectConfig['parameters'])) { + $configurator->addParameters([ + 'editorUrl' => $this->getEditorUrlFromPhpIni(), + ]); + } + $container = $configurator->createContainer()->getByType(Container::class); $this->validateParameters($container->getParameters(), $projectConfig['parametersSchema']); self::postInitializeContainer($container); @@ -391,4 +400,23 @@ private function processArgument($argument, bool $required = true) return $argument; } + /** + * Try to fetch an editor URL from php.ini by reading xdebug configuration. + * + * This works even if the xdebug extension is not loaded. + */ + private function getEditorUrlFromPhpIni(): ?string + { + $xdebugFileLinkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); + + if (is_string($xdebugFileLinkFormat) && $xdebugFileLinkFormat !== '') { + return strtr($xdebugFileLinkFormat, [ + '%f' => '%file%', + '%l' => '%line%', + ]); + } + + return null; + } + }