class Runtime (View source)

internal  The Fusion Runtime is considered internal. For interacting with Fusion from the outside a FusionView should be used. But custom Fusion object implementations might rely on manipulating/calling the Runtime directly, if the abstractions in the AbstractFusionObject doesn't suffice. TODO For that use case we should implement a more powerful and clean abstraction: https://github.com/neos/neos-development-collection/issues/4910
 

Fusion Runtime

Fusion Rendering Process

During rendering, all Fusion objects form a tree.

When a Fusion object at a certain $fusionPath is invoked, it has access to all variables stored in the $context (which is an array).

The Fusion object can then add or replace variables to this context using pushContext() or pushContextArray(), before rendering sub-Fusion objects. After rendering these, it must call popContext() to reset the context to the last state.

Traits

StreamFactoryTrait

Constants

BEHAVIOR_EXCEPTION

Internal constants defining how evaluate should work in case of an error

BEHAVIOR_RETURNNULL

EVALUATION_EXECUTED

Internal constants defining a status of how evaluate was evaluated

EVALUATION_SKIPPED

Properties

protected CompilingEvaluator $eelEvaluator
protected ObjectManagerInterface $objectManager
protected array $contextStack

Stack of evaluated "@context" values

protected array $currentContext

Reference to the current context

protected array $currentApplyValues

Reference to the current apply value

FusionGlobals $fusionGlobals

Fusion global variables like EEL helper definitions {FusionGlobals}

protected RuntimeConfiguration $runtimeConfiguration
protected array $settings
protected bool $debugMode
protected RuntimeContentCache $runtimeContentCache
protected string $lastEvaluationStatus
protected AbstractRenderingExceptionHandler|null $overriddenExceptionHandler {Runtime::overrideExceptionHandler}

Methods

__construct(FusionConfiguration $fusionConfiguration, FusionGlobals $fusionGlobals)

No description

void
injectSettings(array $settings)

Inject settings of this package

void
addCacheTag(string $tag)

Add a tag to the current cache segment

void
pushContextArray(array $contextArray)

Completely replace the context array with the new $contextArray.

void
pushContext(string $key, mixed $context)

Push a new context object to the rendering stack.

array
popContext()

Remove the topmost context objects and return them

array
getCurrentContext()

Get the current context array.

void
popApplyValues(array $paths)

No description

string
getLastEvaluationStatus()

No description

ResponseInterface|StreamInterface
renderEntryPathWithContext(string $entryFusionPath, array $contextVariables)

Entry point to render a Fusion path with the context.

mixed
render(string $fusionPath)

Render an absolute Fusion path and return the result.

string
handleRenderingException(string $fusionPath, Exception $exception, bool $useInnerExceptionHandler = false)

Handle an Exception thrown while rendering Fusion according to settings specified in Neos.Fusion.rendering.exceptionHandler or {@exceptionHandler}

bool
canRender(string $fusionPath)

Determine if the given Fusion path is renderable, which means it exists and has an implementation.

mixed
evaluate(string $fusionPath, mixed $contextObject = null, string $behaviorIfPathNotFound = self::BEHAVIOR_RETURNNULL)

Evaluate an absolute Fusion path and return the result

mixed
evaluateObjectOrRetrieveFromCache(AbstractFusionObject $fusionObject, string $fusionPath, array $fusionConfiguration, array $cacheContext)

Does the evaluation of a Fusion instance, first checking the cache and if conditions and afterwards applying processors.

mixed
evaluateExpressionOrValueInternal(string $fusionPath, array $fusionConfiguration, AbstractFusionObject $contextObject)

Evaluates an EEL expression or value, checking if conditions first and applying processors.

array
prepareApplyValuesForFusionPath(string $fusionPath, array $fusionConfiguration)

Possibly prepares a new "@apply" context for the current fusionPath and pushes it to the stack.

bool
prepareContextForFusionObject(AbstractFusionObject $fusionObject, string $fusionPath, array $fusionConfiguration, array $cacheContext)

Possibly prepares a new context for the current FusionObject and cache context and pushes it to the stack.

instantiateFusionObject(string $fusionPath, array $fusionConfiguration, array $applyValuePaths)

Instantiates a Fusion object specified by the given path and configuration

bool
shouldAssignPropertiesToFusionObject(AbstractFusionObject $fusionObject)

Is the given object an array like object that should get all properties assigned to iterate or process internally

void
assignPropertiesToFusionObject(AbstractArrayFusionObject $fusionObject, array $fusionConfiguration, array $applyValuePaths)

Assigns paths to the Array-Fusion object

mixed
evaluateEelExpression(string $expression, AbstractFusionObject|null $contextObject = null)

Evaluate an Eel expression

array|null
evaluateApplyValues(array $configurationWithEventualProperties, string $fusionPath)

Evaluate "@apply" for the given fusion key.

mixed
evaluateProcessors(mixed $valueToProcess, array $configurationWithEventualProcessors, string $fusionPath, AbstractFusionObject|null $contextObject = null)

Evaluate processors on given value.

bool
evaluateIfCondition(array $configurationWithEventualIf, string $configurationPath, AbstractFusionObject|null $contextObject = null)

Evaluate eventually existing meta "@if" conditionals inside the given configuration and path.

void
throwExceptionForUnrenderablePathIfNeeded(string $fusionPath, array $fusionConfiguration, string $behaviorIfPathNotFound)

Checks and throws an exception for an unrenderable path.

getControllerContext() deprecated

The concept of the controller context inside Fusion has been deprecated.

void
overrideExceptionHandler(AbstractRenderingExceptionHandler $exceptionHandler)

Configures this runtime to override the default exception handler configured in the settings or via Fusion's \@exceptionHandler {AbstractRenderingExceptionHandler}.

void
setDebugMode(bool $debugMode)

No description

bool
isDebugMode()

No description

void
setEnableContentCache(bool $flag)

If the Fusion content cache should be enabled at all

Details

__construct(FusionConfiguration $fusionConfiguration, FusionGlobals $fusionGlobals)

internal  the {@see \Neos\Fusion\Core\RuntimeFactory} must be used for instantiating, to make the EEL helpers available.
 

No description

Parameters

FusionConfiguration $fusionConfiguration
FusionGlobals $fusionGlobals

void injectSettings(array $settings)

Inject settings of this package

Parameters

array $settings

The settings

Return Value

void

void addCacheTag(string $tag)

Add a tag to the current cache segment

During Fusion rendering the method can be used to add tag dynamicaly for the current cache segment.

Parameters

string $tag

Return Value

void

Exceptions

Exception

void pushContextArray(array $contextArray)

internal  purely internal method, should not be called outside Neos.Fusion.
 

Completely replace the context array with the new $contextArray.

Warning unlike in Fusion's \@context or {\Neos\Fusion\Core\Runtime::pushContext()}, no checks are imposed to prevent overriding Fusion globals like "request". Relying on this behaviour is highly discouraged but leveraged by Neos.Fusion.Form {\Neos\Fusion\Core\FusionGlobals}.

Parameters

array $contextArray

Return Value

void

void pushContext(string $key, mixed $context)

Push a new context object to the rendering stack.

It is disallowed to replace global variables {\Neos\Fusion\Core\FusionGlobals}.

Parameters

string $key

the key inside the context

mixed $context

Return Value

void

array popContext()

Remove the topmost context objects and return them

Return Value

array

the topmost context objects as associative array

array getCurrentContext()

Get the current context array.

This PHP context api unlike Fusion, doesn't include the Fusion globals {\Neos\Fusion\Core\FusionGlobals}. The globals can be accessed via {\Neos\Fusion\Core\Runtime::$fusionGlobals}.

Return Value

array

the array of current context objects

void popApplyValues(array $paths)

No description

Parameters

array $paths

Return Value

void

string getLastEvaluationStatus()

No description

Return Value

string

ResponseInterface|StreamInterface renderEntryPathWithContext(string $entryFusionPath, array $contextVariables)

Entry point to render a Fusion path with the context.

A ResponseInterface will be returned, if a Neos.Fusion:Http.Message was defined in the entry path, or if Neos.Fusion.Form or Neos.Neos:Plugin were used in the path.

In all other simple cases a StreamInterface will be returned.

Parameters

string $entryFusionPath

the absolute fusion path to render (without leading slash)

array $contextVariables

the context variables that will be available during the rendering.

Return Value

ResponseInterface|StreamInterface

Exceptions

IllegalEntryFusionPathValueException

mixed render(string $fusionPath)

Render an absolute Fusion path and return the result.

Compared to $this->evaluate, this adds some more comments helpful for debugging.

Parameters

string $fusionPath

Return Value

mixed

Exceptions

Exception
Exception

string handleRenderingException(string $fusionPath, Exception $exception, bool $useInnerExceptionHandler = false)

Handle an Exception thrown while rendering Fusion according to settings specified in Neos.Fusion.rendering.exceptionHandler or {@exceptionHandler}

Parameters

string $fusionPath
Exception $exception
bool $useInnerExceptionHandler

Return Value

string

Exceptions

Exception
InvalidConfigurationException
Exception
StopActionException

bool canRender(string $fusionPath)

Determine if the given Fusion path is renderable, which means it exists and has an implementation.

Parameters

string $fusionPath

Return Value

bool

Exceptions

Exception

mixed evaluate(string $fusionPath, mixed $contextObject = null, string $behaviorIfPathNotFound = self::BEHAVIOR_RETURNNULL)

Evaluate an absolute Fusion path and return the result

Parameters

string $fusionPath
mixed $contextObject

The object which will be "this" in Eel expressions. ONLY FOR INTERNAL USE!

string $behaviorIfPathNotFound

Return Value

mixed

Exceptions

StopActionException
Exception
Exception
RuntimeException
InvalidConfigurationException

protected mixed evaluateObjectOrRetrieveFromCache(AbstractFusionObject $fusionObject, string $fusionPath, array $fusionConfiguration, array $cacheContext)

Does the evaluation of a Fusion instance, first checking the cache and if conditions and afterwards applying processors.

Parameters

AbstractFusionObject $fusionObject
string $fusionPath
array $fusionConfiguration
array $cacheContext

Return Value

mixed

protected mixed evaluateExpressionOrValueInternal(string $fusionPath, array $fusionConfiguration, AbstractFusionObject $contextObject)

Evaluates an EEL expression or value, checking if conditions first and applying processors.

Parameters

string $fusionPath

the Fusion path up to now

array $fusionConfiguration

Fusion configuration for the expression or value

AbstractFusionObject $contextObject

An optional object for the "this" value inside the context

Return Value

mixed

The result of the evaluation

Exceptions

Exception

protected array prepareApplyValuesForFusionPath(string $fusionPath, array $fusionConfiguration)

Possibly prepares a new "@apply" context for the current fusionPath and pushes it to the stack.

Returns true to express that new properties were pushed and have to be popped during finalizePathEvaluation.

Since "@apply" are not inherited every call of this method leads to a completely new "@apply" context, which is null by default.

Parameters

string $fusionPath
array $fusionConfiguration

Return Value

array

Paths to pop

Exceptions

Exception
RuntimeException
Exception
StopActionException

protected bool prepareContextForFusionObject(AbstractFusionObject $fusionObject, string $fusionPath, array $fusionConfiguration, array $cacheContext)

Possibly prepares a new context for the current FusionObject and cache context and pushes it to the stack.

Returns if a new context was pushed to the stack or not.

Parameters

AbstractFusionObject $fusionObject
string $fusionPath
array $fusionConfiguration
array $cacheContext

Return Value

bool

Exceptions

Exception
RuntimeException
Exception
StopActionException

protected AbstractFusionObject instantiateFusionObject(string $fusionPath, array $fusionConfiguration, array $applyValuePaths)

Instantiates a Fusion object specified by the given path and configuration

Parameters

string $fusionPath

Path to the configuration for this object instance

array $fusionConfiguration

Configuration at the given path

array $applyValuePaths

Apply value paths for this object

Return Value

AbstractFusionObject

Exceptions

Exception

protected bool shouldAssignPropertiesToFusionObject(AbstractFusionObject $fusionObject)

Is the given object an array like object that should get all properties assigned to iterate or process internally

Parameters

AbstractFusionObject $fusionObject

Return Value

bool

protected void assignPropertiesToFusionObject(AbstractArrayFusionObject $fusionObject, array $fusionConfiguration, array $applyValuePaths)

Assigns paths to the Array-Fusion object

Parameters

AbstractArrayFusionObject $fusionObject
array $fusionConfiguration
array $applyValuePaths

Return Value

void

protected mixed evaluateEelExpression(string $expression, AbstractFusionObject|null $contextObject = null)

Evaluate an Eel expression

Parameters

string $expression

The Eel expression to evaluate

AbstractFusionObject|null $contextObject

An optional object for the "this" value inside the context

Return Value

mixed

The result of the evaluated Eel expression

Exceptions

Exception

protected array|null evaluateApplyValues(array $configurationWithEventualProperties, string $fusionPath)

Evaluate "@apply" for the given fusion key.

If apply-definitions are found they are evaluated and the returned keys are combined. The result is returned as array with the following structure:

[ 'fusionPath/key_1' => ['key' => 'key_1', 'value' => 'evaluated value 1'], 'fusionPath/key_2' => ['key' => 'key_2', 'value' => 'evaluated value 2'] ]

If no apply-expression is defined null is returned instead.

Parameters

array $configurationWithEventualProperties
string $fusionPath

Return Value

array|null

protected mixed evaluateProcessors(mixed $valueToProcess, array $configurationWithEventualProcessors, string $fusionPath, AbstractFusionObject|null $contextObject = null)

Evaluate processors on given value.

Parameters

mixed $valueToProcess
array $configurationWithEventualProcessors
string $fusionPath
AbstractFusionObject|null $contextObject

Return Value

mixed

protected bool evaluateIfCondition(array $configurationWithEventualIf, string $configurationPath, AbstractFusionObject|null $contextObject = null)

Evaluate eventually existing meta "@if" conditionals inside the given configuration and path.

Parameters

array $configurationWithEventualIf
string $configurationPath
AbstractFusionObject|null $contextObject

Return Value

bool

protected void throwExceptionForUnrenderablePathIfNeeded(string $fusionPath, array $fusionConfiguration, string $behaviorIfPathNotFound)

Checks and throws an exception for an unrenderable path.

Parameters

string $fusionPath

The Fusion path that cannot be rendered

array $fusionConfiguration
string $behaviorIfPathNotFound

One of the BEHAVIOR_* constants

Return Value

void

Exceptions

MissingFusionImplementationException
MissingFusionObjectException

LegacyFusionControllerContext getControllerContext() deprecated

deprecated with Neos 9.0

internal  
 

The concept of the controller context inside Fusion has been deprecated.

For further information and migration strategies, please look into {\Neos\Fusion\Core\LegacyFusionControllerContext}

WARNING: Invoking this backwards-compatible layer is possibly unsafe, if the rendering was not started in {\Neos\Fusion\Core\self::renderEntryPathWithContext()} or no request global is available. This will raise an exception.

Return Value

LegacyFusionControllerContext

Exceptions

Exception

void overrideExceptionHandler(AbstractRenderingExceptionHandler $exceptionHandler)

Configures this runtime to override the default exception handler configured in the settings or via Fusion's \@exceptionHandler {AbstractRenderingExceptionHandler}.

In combination with the throwing handler {\Neos\Fusion\Core\ExceptionHandlers\ThrowingHandler} this can be used to rethrow all exceptions. This is helpfully for renderings in CLI context or testing.

Parameters

AbstractRenderingExceptionHandler $exceptionHandler

Return Value

void

void setDebugMode(bool $debugMode)

No description

Parameters

bool $debugMode

Return Value

void

bool isDebugMode()

No description

Return Value

bool

void setEnableContentCache(bool $flag)

If the Fusion content cache should be enabled at all

Parameters

bool $flag

Return Value

void