Skip to content

Commit

Permalink
php8-mod: Optimize compiled string definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
partikus committed Jan 13, 2023
1 parent db5bfea commit b206c41
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/CompiledContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function resolveFactory($callable, $entryName, array $extraParameters
* Resolve a placeholder in string definition
* - wrap possible NotFound exception to conform to the one from StringDefinition::resolveExpression.
*/
protected function resolveStringPlaceholder($placeholder, $entryName)
protected function resolveStringPlaceholder(string $placeholder, string $entryName) : mixed
{
try {
return $this->delegateContainer->get($placeholder);
Expand Down
4 changes: 1 addition & 3 deletions src/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ private function compileDefinition(string $entryName, Definition $definition) :
break;
case $definition instanceof StringDefinition:
$expression = $definition->getExpression();
$callback = function (array $matches) use ($definition) {
return '\'.$this->resolveStringPlaceholder(' . $this->compileValue($matches[1]) . ', ' . $this->compileValue($definition->getName()) . ').\'';
};
$callback = fn (array $matches) : string => '\'.$this->resolveStringPlaceholder(' . $this->compileValue($matches[1]) . ', ' . $this->compileValue($definition->getName()) . ').\'';
$value = preg_replace_callback('#\{([^\{\}]+)\}#', $callback, $expression);
$code = 'return \'' . $value . '\';';
break;
Expand Down

0 comments on commit b206c41

Please sign in to comment.