diff --git a/Controller/Annotations/Route.php b/Controller/Annotations/Route.php index b3682e875..8e44f309f 100644 --- a/Controller/Annotations/Route.php +++ b/Controller/Annotations/Route.php @@ -123,7 +123,11 @@ public function __construct( ); } - if (!$this->getMethods()) { + if ($this->isMethodsPropertyPublic()) { + if (!$this->methods) { + $this->methods = (array) $this->getMethod(); + } + } elseif (!$this->getMethods()) { $this->setMethods((array) $this->getMethod()); } } @@ -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(); + } } diff --git a/Tests/Controller/Annotations/RouteTest.php b/Tests/Controller/Annotations/RouteTest.php index 394e72c1e..86b228b77 100644 --- a/Tests/Controller/Annotations/RouteTest.php +++ b/Tests/Controller/Annotations/RouteTest.php @@ -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()); } }