Merge branch '3.x' into 4.x

* 3.x:
  Refactor code
  Add a test
This commit is contained in:
Fabien Potencier
2024-08-20 17:21:22 +02:00
9 changed files with 55 additions and 35 deletions
+7 -3
View File
@@ -11,6 +11,8 @@
namespace Twig\Util;
use Twig\TwigCallableInterface;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
@@ -22,8 +24,10 @@ final class ReflectionCallable
private \Closure|string|array|null $callable = null;
private string $name;
public function __construct($callable, string $debugType = 'unknown', string $debugName = 'unknown')
{
public function __construct(
private TwigCallableInterface $twigCallable,
) {
$callable = $twigCallable->getCallable();
if (\is_string($callable) && false !== $pos = strpos($callable, '::')) {
$callable = [substr($callable, 0, $pos), substr($callable, 2 + $pos)];
}
@@ -40,7 +44,7 @@ final class ReflectionCallable
try {
$closure = \Closure::fromCallable($callable);
} catch (\TypeError $e) {
throw new \LogicException(\sprintf('Callback for %s "%s" is not callable in the current scope.', $debugType, $debugName), 0, $e);
throw new \LogicException(\sprintf('Callback for %s "%s" is not callable in the current scope.', $twigCallable->getType(), $twigCallable->getName()), 0, $e);
}
$this->reflector = $r = new \ReflectionFunction($closure);