Skip to content

Commit b206c41

Browse files
committed
php8-mod: Optimize compiled string definitions
1 parent db5bfea commit b206c41

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/CompiledContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function resolveFactory($callable, $entryName, array $extraParameters
131131
* Resolve a placeholder in string definition
132132
* - wrap possible NotFound exception to conform to the one from StringDefinition::resolveExpression.
133133
*/
134-
protected function resolveStringPlaceholder($placeholder, $entryName)
134+
protected function resolveStringPlaceholder(string $placeholder, string $entryName) : mixed
135135
{
136136
try {
137137
return $this->delegateContainer->get($placeholder);

src/Compiler/Compiler.php

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

0 commit comments

Comments
 (0)