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 10, 2024
1 parent 7d72241 commit c18f7c0
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 @@ -118,7 +118,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 @@ -215,9 +215,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 c18f7c0

Please sign in to comment.