Skip to content

Commit 06160fd

Browse files
committed
resolve static class properties in variables
1 parent 9578313 commit 06160fd

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/Render/RenderContext.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public function internalContextLookup(mixed $scope, int|string $key): mixed
199199
$scope instanceof Drop => $scope->{$key},
200200
is_array($scope) && array_key_exists($key, $scope) => $scope[$key],
201201
is_object($scope) && $this->objectHasProperty($scope, (string) $key) => $scope->{$key},
202+
is_object($scope) && $this->objectHasStaticProperty($scope, (string) $key) => $scope::$$key,
202203
default => new MissingValue,
203204
};
204205
} catch (UndefinedDropMethodException) {
@@ -227,6 +228,14 @@ protected function objectHasProperty(object $object, string $property): bool
227228
}
228229
}
229230

231+
protected function objectHasStaticProperty(object $object, string $property): bool
232+
{
233+
$className = get_class($object);
234+
$staticProperties = get_class_vars($className);
235+
236+
return array_key_exists($property, $staticProperties);
237+
}
238+
230239
public function normalizeValue(mixed $value): mixed
231240
{
232241
if (is_object($value) && isset($this->sharedState->computedObjectsCache[$value])) {

tests/Integration/ContextTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ function () use (&$global) {
700700

701701
expect($context->get('object.simpleProperty'))->toBe('foo');
702702
expect($context->get('object.nullProperty'))->toBe(null);
703+
expect($context->get('object.staticProperty'))->toBe('foo');
704+
expect($context->get('object.staticNullProperty'))->toBe(null);
703705

704706
if ($strict) {
705707
expect($context->get('object.protectedProperty'))->toBeInstanceOf(UndefinedVariable::class);

tests/Stubs/SimpleClass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class SimpleClass
1010

1111
protected string $protectedProperty = 'foo';
1212

13+
public static string $staticProperty = 'foo';
14+
15+
public static ?string $staticNullProperty = null;
16+
1317
public function simpleMethod(): string
1418
{
1519
return 'foo';

0 commit comments

Comments
 (0)