Skip to content

Commit c18f7c0

Browse files
committed
php8-mod: Optimize compiled string definitions
1 parent 7d72241 commit c18f7c0

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/CompiledContainer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected function resolveFactory($callable, $entryName, array $extraParameters
118118
* Resolve a placeholder in string definition
119119
* - wrap possible NotFound exception to conform to the one from StringDefinition::resolveExpression.
120120
*/
121-
protected function resolveStringPlaceholder($placeholder, $entryName)
121+
protected function resolveStringPlaceholder(string $placeholder, string $entryName) : mixed
122122
{
123123
try {
124124
return $this->delegateContainer->get($placeholder);

src/Compiler/Compiler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ private function compileDefinition(string $entryName, Definition $definition) :
215215
break;
216216
case $definition instanceof StringDefinition:
217217
$expression = $definition->getExpression();
218-
$callback = function (array $matches) use ($definition) {
219-
return '\'.$this->resolveStringPlaceholder(' . $this->compileValue($matches[1]) . ', ' . $this->compileValue($definition->getName()) . ').\'';
220-
};
218+
$callback = fn (array $matches) : string => '\'.$this->resolveStringPlaceholder(' . $this->compileValue($matches[1]) . ', ' . $this->compileValue($definition->getName()) . ').\'';
221219
$value = preg_replace_callback('#\{([^\{\}]+)\}#', $callback, $expression);
222220
$code = 'return \'' . $value . '\';';
223221
break;

0 commit comments

Comments
 (0)