mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-12 06:45:53 +00:00
Merge branch '3.x' into 4.x
* 3.x: Refactor code Add a test
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user