Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Introduce EEL tracer for handling Neos9 deprecations #3386

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions Neos.Eel/Classes/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down
21 changes: 21 additions & 0 deletions Neos.Eel/Classes/EelInvocationTracerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Neos\Eel;

/**
* @internal experimental tracer for eel. Could be used for example to collect and log deprecations.
*/
interface EelInvocationTracerInterface
{
public function recordPropertyAccess(object $object, string $propertyName): void;

/**
* @param array<int, mixed> $arguments
*/
public function recordMethodCall(object $object, string $methodName, array $arguments): void;

/**
* @param array<int, mixed> $arguments
*/
public function recordFunctionCall(callable $function, string $functionName, array $arguments): void;
}
4 changes: 2 additions & 2 deletions Neos.Eel/Classes/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Loading