diff --git a/Neos.Eel/Classes/Context.php b/Neos.Eel/Classes/Context.php index 8e249d7b11..c4c9cc80e1 100644 --- a/Neos.Eel/Classes/Context.php +++ b/Neos.Eel/Classes/Context.php @@ -26,17 +26,13 @@ */ class Context { - /** - * @var mixed - */ - protected $value; - /** * @param mixed $value */ - public function __construct($value = null) - { - $this->value = $value; + public function __construct( + protected mixed $value = null, + private ?EelInvocationTracerInterface $tracer = null + ) { } /** @@ -62,6 +58,7 @@ public function get($path) if (is_array($this->value)) { return array_key_exists($path, $this->value) ? $this->value[$path] : null; } elseif (is_object($this->value)) { + $this->tracer?->recordPropertyAccess($this->value, $path); try { return ObjectAccess::getProperty($this->value, $path); } catch (PropertyNotAccessibleException $exception) { @@ -115,6 +112,14 @@ public function call($method, array $arguments = []) $arguments[$i] = $arguments[$i]->unwrap(); } } + if ($this->tracer !== null) { + // optional experimental tracing + if (is_object($this->value)) { + $this->tracer->recordMethodCall($this->value, $method, $arguments); + } else { + $this->tracer->recordFunctionCall($callback, $method, $arguments); + } + } return call_user_func_array($callback, $arguments); } @@ -139,7 +144,7 @@ public function callAndWrap($method, array $arguments = []) public function wrap($value) { if (!$value instanceof Context) { - return new static($value); + return new static($value, $this->tracer); } else { return $value; } diff --git a/Neos.Eel/Classes/EelInvocationTracerInterface.php b/Neos.Eel/Classes/EelInvocationTracerInterface.php new file mode 100644 index 0000000000..4ef07b334d --- /dev/null +++ b/Neos.Eel/Classes/EelInvocationTracerInterface.php @@ -0,0 +1,21 @@ + $arguments + */ + public function recordMethodCall(object $object, string $methodName, array $arguments): void; + + /** + * @param array $arguments + */ + public function recordFunctionCall(callable $function, string $functionName, array $arguments): void; +} diff --git a/Neos.Eel/Classes/Utility.php b/Neos.Eel/Classes/Utility.php index 95b0de534b..1b26575abd 100644 --- a/Neos.Eel/Classes/Utility.php +++ b/Neos.Eel/Classes/Utility.php @@ -90,7 +90,7 @@ private static function createClosureFromConfiguration(string $objectConfigurati * @return mixed * @throws Exception */ - public static function evaluateEelExpression($expression, EelEvaluatorInterface $eelEvaluator, array $contextVariables, array $defaultContextConfiguration = []) + public static function evaluateEelExpression($expression, EelEvaluatorInterface $eelEvaluator, array $contextVariables, array $defaultContextConfiguration = [], ?EelInvocationTracerInterface $tracer = null) { $eelExpression = self::parseEelExpression($expression); if ($eelExpression === null) { @@ -100,7 +100,7 @@ public static function evaluateEelExpression($expression, EelEvaluatorInterface $defaultContextVariables = self::getDefaultContextVariables($defaultContextConfiguration); $contextVariables = array_merge($defaultContextVariables, $contextVariables); - $context = new ProtectedContext($contextVariables); + $context = new ProtectedContext($contextVariables, $tracer); $context->allow('q'); // Allow functions on the uppermost context level to allow calling them without