/
AbstractFusionObject.php
138 lines (124 loc) · 3.12 KB
/
AbstractFusionObject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace Neos\Fusion\FusionObjects;
/*
* This file is part of the Neos.Fusion package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Fusion\Core\Runtime;
/**
* Base class for all Fusion objects
*/
abstract class AbstractFusionObject implements \ArrayAccess
{
/**
* @var Runtime
*/
protected $runtime;
/**
* The Fusion path currently being rendered
*
* @var string
*/
protected $path;
/**
* Name of this Fusion object, like Neos.Neos:Text
*
* @var string
*/
protected $fusionObjectName;
/**
* @var array
*/
protected $fusionValueCache = [];
/**
* Constructor
*
* @param Runtime $runtime
* @param string $path
* @param string $fusionObjectName
*/
public function __construct(Runtime $runtime, $path, $fusionObjectName)
{
$this->runtime = $runtime;
$this->path = $path;
$this->fusionObjectName = $fusionObjectName;
}
/**
* Evaluate this Fusion object and return the result
*
* @return mixed
*/
abstract public function evaluate();
/**
* Get the Fusion runtime this object was created in.
*
* @return Runtime
*/
public function getRuntime()
{
return $this->runtime;
}
/**
* Return the Fusion value relative to this Fusion object (with processors etc applied).
*
* Note that subsequent calls of fusionValue() with the same Fusion path will return the same values since the
* first evaluated value will be cached in memory.
*
* @param string $path
* @return mixed
*/
protected function fusionValue($path)
{
$fullPath = $this->path . '/' . $path;
if (!isset($this->fusionValueCache[$fullPath])) {
$this->fusionValueCache[$fullPath] = $this->runtime->evaluate($fullPath, $this);
}
return $this->fusionValueCache[$fullPath];
}
/**
* Dummy implementation of ArrayAccess to allow this.XXX access in processors.
*
* @param mixed $offset
* @return boolean
*/
public function offsetExists($offset): bool
{
return ($this->fusionValue($offset) !== null);
}
/**
* Dummy implementation of ArrayAccess to allow this.XXX access in processors.
*
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset): mixed
{
return $this->fusionValue($offset);
}
/**
* Dummy implementation of ArrayAccess to allow this.XXX access in processors.
*
* @param mixed $offset
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value): void
{
// no op
}
/**
* Dummy implementation of ArrayAccess to allow this.XXX access in processors.
*
* @param mixed $offset
* @return void
*/
public function offsetUnset($offset): void
{
// no op
}
}