diff --git a/UPGRADING.md b/UPGRADING.md index 9775baf..8a474f2 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,5 +1,10 @@ # Upgrading Notes for webfactory/object-routing +# Version 2.0.0 + +* The `\JMS\ObjectRouting\Metadata\Driver\AnnotationDriver` and `\JMS\ObjectRouting\Annotation\ObjectRoute` classes have been removed. +* The `\JMS\ObjectRouting\Attribute\ObjectRoute` class is now `final`. + # Version 1.7.0 * Using the `\JMS\ObjectRouting\Annotation\ObjectRoute` class to configure object routes either through annotations or as an attribute has been deprecated. Use the `\JMS\ObjectRouting\Attribute\ObjectRoute` attribute instead. Also, the `\JMS\ObjectRouting\Metadata\Driver\AnnotationDriver` has been deprecated. diff --git a/composer.json b/composer.json index 733362c..b55c14f 100644 --- a/composer.json +++ b/composer.json @@ -9,10 +9,8 @@ "require": { "php": ">= 8.1", - "doctrine/annotations": "^1.12", "jms/metadata": "^2.6.1", - "symfony/property-access": "^3.4|^4.0|^5.0|^6.0|^7.0", - "symfony/deprecation-contracts": "^3.4" + "symfony/property-access": "^3.4|^4.0|^5.0|^6.0|^7.0" }, "require-dev": { diff --git a/src/JMS/ObjectRouting/Annotation/ObjectRoute.php b/src/JMS/ObjectRouting/Annotation/ObjectRoute.php deleted file mode 100644 index 7c86ae5..0000000 --- a/src/JMS/ObjectRouting/Annotation/ObjectRoute.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace JMS\ObjectRouting\Annotation; - -/** - * @deprecated - * @Annotation - * @NamedArgumentConstructor - * @Target("CLASS") - */ -final class ObjectRoute extends \JMS\ObjectRouting\Attribute\ObjectRoute -{ - public function __construct(string $type, string $name, array $params = []) - { - trigger_deprecation('webfactory/object-routing', '1.7.0', 'Using annotations to configure object routes is deprecated. Use the %s attribute instead', \JMS\ObjectRouting\Attribute\ObjectRoute::class); - parent::__construct($type, $name, $params); - } -} diff --git a/src/JMS/ObjectRouting/Attribute/ObjectRoute.php b/src/JMS/ObjectRouting/Attribute/ObjectRoute.php index 433c5cb..01458a4 100644 --- a/src/JMS/ObjectRouting/Attribute/ObjectRoute.php +++ b/src/JMS/ObjectRouting/Attribute/ObjectRoute.php @@ -18,9 +18,8 @@ namespace JMS\ObjectRouting\Attribute; -/** @final */ #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS)] -class ObjectRoute +final class ObjectRoute { /** @var string @Required */ public $type; diff --git a/src/JMS/ObjectRouting/Metadata/Driver/AnnotationDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/AnnotationDriver.php deleted file mode 100644 index 803e501..0000000 --- a/src/JMS/ObjectRouting/Metadata/Driver/AnnotationDriver.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace JMS\ObjectRouting\Metadata\Driver; - -use Doctrine\Common\Annotations\Reader; -use JMS\ObjectRouting\Annotation\ObjectRoute; -use JMS\ObjectRouting\Metadata\ClassMetadata; -use Metadata\Driver\DriverInterface; - -/** - * @deprecated - */ -class AnnotationDriver implements DriverInterface -{ - private $reader; - - public function __construct(Reader $reader) - { - trigger_deprecation('webfactory/object-routing', '1.7.0', 'The %s driver is deprecated. Use another configuration mechanism, or switch from annotations to PHP 8 attributes.', self::class); - $this->reader = $reader; - } - - public function loadMetadataForClass(\ReflectionClass $class): ?ClassMetadata - { - $metadata = new ClassMetadata($class->name); - - $hasMetadata = false; - foreach (array_merge($this->reader->getClassAnnotations($class), $this->buildAnnotations($class)) as $annot) { - if ($annot instanceof ObjectRoute) { - $hasMetadata = true; - $metadata->addRoute($annot->type, $annot->name, $annot->params); - } - } - - return $hasMetadata ? $metadata : null; - } - - private function buildAnnotations(\ReflectionClass $class): array - { - $annots = []; - - foreach ($class->getAttributes() as $attr) { - if (str_starts_with($attr->getName(), 'JMS\\ObjectRouting\\Annotation\\')) { - $annots[] = $attr->newInstance(); - } - } - - if ($annots) { - trigger_deprecation('webfactory/object-routing', '1.7.0', 'Discovering object route attributes through the %s driver is deprecated. Make sure the %s driver is used with a higher priority.', self::class, AttributeDriver::class); - } - - return $annots; - } -} diff --git a/src/JMS/ObjectRouting/ObjectRouter.php b/src/JMS/ObjectRouting/ObjectRouter.php index e776bef..19bddf7 100644 --- a/src/JMS/ObjectRouting/ObjectRouter.php +++ b/src/JMS/ObjectRouting/ObjectRouter.php @@ -18,9 +18,7 @@ namespace JMS\ObjectRouting; -use Doctrine\Common\Annotations\AnnotationReader; use JMS\ObjectRouting\Metadata\ClassMetadata; -use JMS\ObjectRouting\Metadata\Driver\AnnotationDriver; use JMS\ObjectRouting\Metadata\Driver\AttributeDriver; use Metadata\Driver\DriverChain; use Metadata\MetadataFactory; @@ -39,7 +37,6 @@ public static function create(RouterInterface $router) $router, new MetadataFactory(new DriverChain([ new AttributeDriver(), - new AnnotationDriver(new AnnotationReader()), ])) ); } diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/AnnotationDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/AnnotationDriverTest.php deleted file mode 100644 index 80c2432..0000000 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/AnnotationDriverTest.php +++ /dev/null @@ -1,36 +0,0 @@ -driver->loadMetadataForClass(new \ReflectionClass(BlogPost::class)); - $this->assertCount(2, $metadata->routes); - - $routes = array( - 'view' => array('name' => 'blog_post_view', 'params' => array('slug' => 'slug')), - 'edit' => array('name' => 'blog_post_edit', 'params' => array('slug' => 'slug')), - ); - $this->assertEquals($routes, $metadata->routes); - } - - public function testLoadReturnsNullWhenNoRoutes() - { - $this->assertNull($this->driver->loadMetadataForClass(new \ReflectionClass('stdClass'))); - } - - protected function setUp(): void - { - $this->driver = new AnnotationDriver(new AnnotationReader()); - } -}