Skip to content

Commit

Permalink
Merge pull request #3386 from mhsdesign/feature/eel-tracer-for-neos-9…
Browse files Browse the repository at this point in the history
…-deprecations

FEATURE: Introduce EEL tracer for handling Neos9 deprecations
  • Loading branch information
kitsunet authored Sep 12, 2024
2 parents af3481b + 13ccf72 commit ee5d017
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
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

0 comments on commit ee5d017

Please sign in to comment.