Skip to content

Commit e3f5169

Browse files
committed
Use getClass to make it extensible
1 parent 6066103 commit e3f5169

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Extension/AttributeExtension.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ public function getLastModified(): int
7878
{
7979
return max(
8080
filemtime(__FILE__),
81-
is_file($filename = (new \ReflectionClass($this->class))->getFileName()) ? filemtime($filename) : 0,
81+
is_file($filename = (new \ReflectionClass($this->getClass()))->getFileName()) ? filemtime($filename) : 0,
8282
);
8383
}
8484

8585
private function initFromAttributes(): void
8686
{
8787
$filters = $functions = $tests = [];
88-
$reflectionClass = new \ReflectionClass($this->class);
88+
$reflectionClass = new \ReflectionClass($this->getClass());
8989
foreach ($reflectionClass->getMethods() as $method) {
9090
foreach ($method->getAttributes(AsTwigFilter::class) as $reflectionAttribute) {
9191
/** @var AsTwigFilter $attribute */
9292
$attribute = $reflectionAttribute->newInstance();
9393

94-
$callable = new TwigFilter($attribute->name, [$this->class, $method->getName()], [
94+
$callable = new TwigFilter($attribute->name, [$reflectionClass->name, $method->getName()], [
9595
'needs_context' => $attribute->needsContext ?? false,
9696
'needs_environment' => $attribute->needsEnvironment ?? $this->needsEnvironment($method),
9797
'needs_charset' => $attribute->needsCharset ?? false,
@@ -114,7 +114,7 @@ private function initFromAttributes(): void
114114
/** @var AsTwigFunction $attribute */
115115
$attribute = $reflectionAttribute->newInstance();
116116

117-
$callable = new TwigFunction($attribute->name, [$this->class, $method->getName()], [
117+
$callable = new TwigFunction($attribute->name, [$reflectionClass->name, $method->getName()], [
118118
'needs_context' => $attribute->needsContext ?? false,
119119
'needs_environment' => $attribute->needsEnvironment ?? $this->needsEnvironment($method),
120120
'needs_charset' => $attribute->needsCharset ?? false,
@@ -136,7 +136,7 @@ private function initFromAttributes(): void
136136
/** @var AsTwigTest $attribute */
137137
$attribute = $reflectionAttribute->newInstance();
138138

139-
$callable = new TwigTest($attribute->name, [$this->class, $method->getName()], [
139+
$callable = new TwigTest($attribute->name, [$reflectionClass->name, $method->getName()], [
140140
'needs_context' => $attribute->needsContext ?? false,
141141
'needs_environment' => $attribute->needsEnvironment ?? $this->needsEnvironment($method),
142142
'needs_charset' => $attribute->needsCharset ?? false,

0 commit comments

Comments
 (0)