Skip to content

Commit

Permalink
FEATURE: Fusion eel neos deprecation tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 30, 2024
1 parent 568907e commit 210b5ea
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
96 changes: 96 additions & 0 deletions Neos.Fusion/Classes/Core/EelNeosDeprecationTracer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Neos\Fusion\Core;

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\Eel\EelInvocationTracerInterface;
use Neos\Flow\Annotations as Flow;
use Psr\Log\LoggerInterface;

final class EelNeosDeprecationTracer implements EelInvocationTracerInterface
{
/** @Flow\Inject */
protected LoggerInterface $logger;

/**
* These are the lowercase names of the Neos 8 Node fields that were removed in 9.0.
* Only the fields name, nodeTypeName and properties will continue to exist.
*/
private const LEGACY_NODE_FIELDS = [
'accessrestrictions' => true,
'accessroles' => true,
'accessible' => true,
'autocreated' => true,
'cacheentryidentifier' => true,
'childnodes' => true,
'contentobject' => true,
'context' => true,
'contextpath' => true,
'creationdatetime' => true,
'depth' => true,
'dimensions' => true,
'hidden' => true,
'hiddenafterdatetime' => true,
'hiddenbeforedatetime' => true,
'hiddeninindex' => true,
'identifier' => true,
'index' => true,
'label' => true,
'lastmodificationdatetime' => true,
'lastpublicationdatetime' => true,
'nodeaggregateidentifier' => true,
'nodedata' => true,
'nodename' => true,
'nodetype' => true,
'numberofchildnodes' => true,
'othernodevariants' => true,
'parent' => true,
'parentpath' => true,
'path' => true,
'primarychildnode' => true,
'propertynames' => true,
'removed' => true,
'root' => true,
'tethered' => true,
'visible' => true,
'workspace' => true,
];

public function __construct(
private readonly string $eelExpression,
private readonly bool $throwExceptions,
) {
}

public function recordPropertyAccess(object $object, string $propertyName): void
{
if (
// deliberate cross package reference from Neos.Fusion to simplify the wiring of this temporary migration helper
$object instanceof Node
&& array_key_exists(strtolower($propertyName), self::LEGACY_NODE_FIELDS)
) {
$this->logDeprecationOrThrowException(
sprintf('The node field "%s" is removed in "%s"', $propertyName, $this->eelExpression)
);
}
}

public function recordMethodCall(object $object, string $methodName, array $arguments): void
{
}

public function recordFunctionCall(callable $function, string $functionName, array $arguments): void
{
}

private function logDeprecationOrThrowException(string $message): void
{
if ($this->throwExceptions) {
throw new \RuntimeException($message);
} else {
$this->logger->debug($message);
}
}
}
8 changes: 7 additions & 1 deletion Neos.Fusion/Classes/Core/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,13 @@ protected function evaluateEelExpression($expression, AbstractFusionObject $cont
$this->eelEvaluator->_activateDependency();
}

return EelUtility::evaluateEelExpression($expression, $this->eelEvaluator, $contextVariables);
$tracer = match ($this->settings['deprecationTracer'] ?? null) {
'LOG' => new EelNeosDeprecationTracer($expression, false),
'EXCEPTION' => new EelNeosDeprecationTracer($expression, true),
default => null
};

return EelUtility::evaluateEelExpression($expression, $this->eelEvaluator, $contextVariables, [], $tracer);
}

/**
Expand Down
1 change: 1 addition & 0 deletions Neos.Fusion/Configuration/Development/Settings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Neos:
Fusion:
deprecationTracer: "LOG"
rendering:
exceptionHandler: Neos\Fusion\Core\ExceptionHandlers\HtmlMessageHandler
5 changes: 5 additions & 0 deletions Neos.Fusion/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Neos:
# This option is suited only for development and enabled there by default.
enableParsePartialsCache: true

# Experimental logging for deprecated fusion code at runtime.
# Either disabled or "LOG" or "EXCEPTION" to let the exception handler step in ensuring no deprecated syntax is used.
# Should only be used during development
deprecationTracer: false

# Default context objects that are available in Eel expressions
#
# New variables should be added with a package key prefix. Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ properties:
type: boolean
enableParsePartialsCache:
type: boolean
deprecationTracer:
type: [string, boolean]
defaultContext:
type: dictionary
additionalProperties:
Expand Down

0 comments on commit 210b5ea

Please sign in to comment.