Skip to content

Commit 2518b64

Browse files
committed
Set editorUrl from xdebug configuration
The configuration files will override the xdebug configuration.
1 parent efdd51e commit 2518b64

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/DependencyInjection/ContainerFactory.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@
3939
use function count;
4040
use function dirname;
4141
use function extension_loaded;
42+
use function get_cfg_var;
4243
use function getenv;
4344
use function ini_get;
4445
use function is_array;
4546
use function is_file;
4647
use function is_readable;
48+
use function is_string;
4749
use function spl_object_id;
4850
use function sprintf;
4951
use function str_ends_with;
52+
use function strtr;
5053
use function substr;
5154

5255
/**
@@ -149,6 +152,12 @@ public function create(
149152

150153
$configurator->setAllConfigFiles($allConfigFiles);
151154

155+
if (!array_key_exists('editorUrl', $projectConfig['parameters'])) {
156+
$configurator->addParameters([
157+
'editorUrl' => $this->getEditorUrlFromPhpIni(),
158+
]);
159+
}
160+
152161
$container = $configurator->createContainer()->getByType(Container::class);
153162
$this->validateParameters($container->getParameters(), $projectConfig['parametersSchema']);
154163
self::postInitializeContainer($container);
@@ -391,4 +400,23 @@ private function processArgument($argument, bool $required = true)
391400
return $argument;
392401
}
393402

403+
/**
404+
* Try to fetch an editor URL from php.ini by reading xdebug configuration.
405+
*
406+
* This works even if the xdebug extension is not loaded.
407+
*/
408+
private function getEditorUrlFromPhpIni(): ?string
409+
{
410+
$xdebugFileLinkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
411+
412+
if (is_string($xdebugFileLinkFormat) && $xdebugFileLinkFormat !== '') {
413+
return strtr($xdebugFileLinkFormat, [
414+
'%f' => '%file%',
415+
'%l' => '%line%',
416+
]);
417+
}
418+
419+
return null;
420+
}
421+
394422
}

0 commit comments

Comments
 (0)