From ee1266d4d299389eb792ab6fe28f2096f3a5e34f Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:04:04 +0200 Subject: [PATCH 1/2] FEATURE: Introduce EEL tracer for handling Neos9 deprecations --- Neos.Eel/Classes/Context.php | 16 +++++++--------- .../Classes/EelInvocationTracerInterface.php | 13 +++++++++++++ Neos.Eel/Classes/Utility.php | 4 ++-- 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 Neos.Eel/Classes/EelInvocationTracerInterface.php diff --git a/Neos.Eel/Classes/Context.php b/Neos.Eel/Classes/Context.php index 584ed50b73..ba441e2d69 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) { @@ -97,6 +94,7 @@ public function call($method, array $arguments = []) if ($this->value === null) { return null; } elseif (is_object($this->value)) { + $this->tracer?->recordMethodCall($this->value, $method); $callback = [$this->value, $method]; } elseif (is_array($this->value)) { if (!array_key_exists($method, $this->value)) { @@ -139,7 +137,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..9ad7c93d0b --- /dev/null +++ b/Neos.Eel/Classes/EelInvocationTracerInterface.php @@ -0,0 +1,13 @@ +allow('q'); // Allow functions on the uppermost context level to allow calling them without From 13ccf72d4a81b2b390a7741cf0a962a45dc7aa03 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 19 Aug 2024 13:33:38 +0200 Subject: [PATCH 2/2] TASK: Pass arguments to `EelInvocationTracerInterface` and also trace function calls --- Neos.Eel/Classes/Context.php | 9 ++++++++- Neos.Eel/Classes/EelInvocationTracerInterface.php | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Neos.Eel/Classes/Context.php b/Neos.Eel/Classes/Context.php index ba441e2d69..ead8d97b54 100644 --- a/Neos.Eel/Classes/Context.php +++ b/Neos.Eel/Classes/Context.php @@ -94,7 +94,6 @@ public function call($method, array $arguments = []) if ($this->value === null) { return null; } elseif (is_object($this->value)) { - $this->tracer?->recordMethodCall($this->value, $method); $callback = [$this->value, $method]; } elseif (is_array($this->value)) { if (!array_key_exists($method, $this->value)) { @@ -113,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); } diff --git a/Neos.Eel/Classes/EelInvocationTracerInterface.php b/Neos.Eel/Classes/EelInvocationTracerInterface.php index 9ad7c93d0b..4ef07b334d 100644 --- a/Neos.Eel/Classes/EelInvocationTracerInterface.php +++ b/Neos.Eel/Classes/EelInvocationTracerInterface.php @@ -9,5 +9,13 @@ interface EelInvocationTracerInterface { public function recordPropertyAccess(object $object, string $propertyName): void; - public function recordMethodCall(object $object, string $methodName): void; + /** + * @param array $arguments + */ + public function recordMethodCall(object $object, string $methodName, array $arguments): void; + + /** + * @param array $arguments + */ + public function recordFunctionCall(callable $function, string $functionName, array $arguments): void; }