Skip to content

Commit 5017792

Browse files
committed
Don't use deprecated #[Route] methods
1 parent d247368 commit 5017792

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Controller/Annotations/Route.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ public function __construct(
123123
);
124124
}
125125

126-
if (!$this->getMethods()) {
126+
if ($this->isMethodsPropertyPublic()) {
127+
if (!$this->methods) {
128+
$this->methods = (array) $this->getMethod();
129+
}
130+
} elseif (!$this->getMethods()) {
127131
$this->setMethods((array) $this->getMethod());
128132
}
129133
}
@@ -135,4 +139,11 @@ public function getMethod()
135139
{
136140
return;
137141
}
142+
143+
private function isMethodsPropertyPublic(): bool
144+
{
145+
static $isPublic;
146+
147+
return $isPublic ??= property_exists($this, 'methods') && (new \ReflectionProperty($this, 'methods'))->isPublic();
148+
}
138149
}

Tests/Controller/Annotations/RouteTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ public function testCanInstantiate()
4141
$condition
4242
);
4343

44-
$this->assertEquals($path, $route->getPath());
45-
$this->assertEquals($name, $route->getName());
46-
$this->assertEquals($requirements, $route->getRequirements());
47-
$this->assertEquals($options, $route->getOptions());
48-
$this->assertEquals($defaults, $route->getDefaults());
49-
$this->assertEquals($host, $route->getHost());
50-
$this->assertEquals($methods, $route->getMethods());
51-
$this->assertEquals($schemes, $route->getSchemes());
52-
$this->assertEquals($condition, $route->getCondition());
44+
$isPublic = property_exists($route, 'methods') && (new \ReflectionProperty($route, 'methods'))->isPublic();
45+
46+
$this->assertEquals($path, $isPublic ? $route->path : $route->getPath());
47+
$this->assertEquals($name, $isPublic ? $route->name : $route->getName());
48+
$this->assertEquals($requirements, $isPublic ? $route->requirements : $route->getRequirements());
49+
$this->assertEquals($options, $isPublic ? $route->options : $route->getOptions());
50+
$this->assertEquals($defaults, $isPublic ? $route->defaults : $route->getDefaults());
51+
$this->assertEquals($host, $isPublic ? $route->host : $route->getHost());
52+
$this->assertEquals($methods, $isPublic ? $route->methods : $route->getMethods());
53+
$this->assertEquals($schemes, $isPublic ? $route->schemes : $route->getSchemes());
54+
$this->assertEquals($condition, $isPublic ? $route->condition : $route->getCondition());
5355
}
5456
}

0 commit comments

Comments
 (0)