Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Controller/Annotations/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public function __construct(
);
}

if (!$this->getMethods()) {
if ($this->isMethodsPropertyPublic()) {
Copy link
Contributor

@alexander-schranz alexander-schranz Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why not use if (isset($this->methods)) { to handle this bc layer? Reflection looks like overhead.

if (!$this->methods) {
$this->methods = (array) $this->getMethod();
}
} elseif (!$this->getMethods()) {
$this->setMethods((array) $this->getMethod());
}
}
Expand All @@ -135,4 +139,11 @@ public function getMethod()
{
return;
}

private function isMethodsPropertyPublic(): bool
{
static $isPublic;

return $isPublic ??= property_exists($this, 'methods') && (new \ReflectionProperty($this, 'methods'))->isPublic();
}
}
20 changes: 11 additions & 9 deletions Tests/Controller/Annotations/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ public function testCanInstantiate()
$condition
);

$this->assertEquals($path, $route->getPath());
$this->assertEquals($name, $route->getName());
$this->assertEquals($requirements, $route->getRequirements());
$this->assertEquals($options, $route->getOptions());
$this->assertEquals($defaults, $route->getDefaults());
$this->assertEquals($host, $route->getHost());
$this->assertEquals($methods, $route->getMethods());
$this->assertEquals($schemes, $route->getSchemes());
$this->assertEquals($condition, $route->getCondition());
$isPublic = property_exists($route, 'methods') && (new \ReflectionProperty($route, 'methods'))->isPublic();

$this->assertEquals($path, $isPublic ? $route->path : $route->getPath());
$this->assertEquals($name, $isPublic ? $route->name : $route->getName());
$this->assertEquals($requirements, $isPublic ? $route->requirements : $route->getRequirements());
$this->assertEquals($options, $isPublic ? $route->options : $route->getOptions());
$this->assertEquals($defaults, $isPublic ? $route->defaults : $route->getDefaults());
$this->assertEquals($host, $isPublic ? $route->host : $route->getHost());
$this->assertEquals($methods, $isPublic ? $route->methods : $route->getMethods());
$this->assertEquals($schemes, $isPublic ? $route->schemes : $route->getSchemes());
$this->assertEquals($condition, $isPublic ? $route->condition : $route->getCondition());
}
}
Loading