Skip to content

Commit 960d37b

Browse files
committed
Remove doctrine/annotations dependency, use PHP 8 native attributes only
- Remove doctrine/annotations and koriym/attributes dependencies from composer.json - Create NativeAttributeReader to replace Doctrine's Reader interface - Update DualReaderFactory to use NativeAttributeReader - Remove @annotation, @target, @NamedArgumentConstructor docblock annotations - Replace AnnotationException with InvalidArgumentException - Update SymfonyValidator to use only attribute-based validation - Convert all test fixtures from docblock annotations to PHP 8 attributes - Update phpstan.neon to remove doctrine-related ignores - Update error messages to reference #[Attribute] syntax instead of @annotation This is a breaking change - docblock annotations are no longer supported.
1 parent 403a8c5 commit 960d37b

33 files changed

+137
-261
lines changed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "contributte/apitte",
3-
"description": "An opinionated and enjoyable API framework based on Nette Framework. Supporting content negotiation, debugging, middlewares, attributes, annotations and loving openapi/swagger.",
3+
"description": "An opinionated and enjoyable API framework based on Nette Framework. Supporting content negotiation, debugging, middlewares, attributes and loving openapi/swagger.",
44
"keywords": [
55
"api",
66
"apitte",
77
"http",
88
"rest",
99
"nette",
10-
"annotation"
10+
"attribute"
1111
],
1212
"type": "library",
1313
"license": "MIT",
@@ -25,8 +25,6 @@
2525
"contributte/psr7-http-message": "^0.9.0 || ^0.10.0",
2626
"contributte/middlewares": "^0.11.0 || ^0.12.0",
2727
"contributte/openapi": "^0.1.0",
28-
"doctrine/annotations": "^1.14.3 || ^2.0.0",
29-
"koriym/attributes": "^1.0.5",
3028
"nette/utils": "^4.0.0"
3129
},
3230
"require-dev": {

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,3 @@ parameters:
6262
# Nette changed return typehint
6363
- message: "#^Parameter \\#2 \\$array of function implode expects array\\<string\\>, array\\<int, array\\<string\\>\\|string\\> given\\.$#"
6464
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php
65-
66-
# Support for doctrine/annotations ^1
67-
- message: "#^Call to function method_exists\\(\\) with 'Doctrine\\\\\\\\Common\\\\\\\\Annotations\\\\\\\\AnnotationRegistry' and 'registerUniqueLoader' will always evaluate to false\\.$#"
68-
path: src/Core/DI/LoaderFactory/DualReaderFactory.php

src/Core/Annotation/Controller/Id.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
namespace Apitte\Core\Annotation\Controller;
44

55
use Attribute;
6-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
7-
use Doctrine\Common\Annotations\Annotation\Target;
8-
use Doctrine\Common\Annotations\AnnotationException;
9-
10-
/**
11-
* @Annotation
12-
* @Target({"CLASS","METHOD"})
13-
* @NamedArgumentConstructor()
14-
*/
6+
use InvalidArgumentException;
7+
158
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
169
class Id
1710
{
@@ -21,7 +14,7 @@ class Id
2114
public function __construct(string $name)
2215
{
2316
if ($name === '') {
24-
throw new AnnotationException('Empty @Id given');
17+
throw new InvalidArgumentException('Empty #[Id] given');
2518
}
2619

2720
$this->name = $name;

src/Core/Annotation/Controller/Method.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
namespace Apitte\Core\Annotation\Controller;
44

55
use Attribute;
6-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
7-
use Doctrine\Common\Annotations\Annotation\Target;
8-
use Doctrine\Common\Annotations\AnnotationException;
9-
10-
/**
11-
* @Annotation
12-
* @Target("METHOD")
13-
* @NamedArgumentConstructor()
14-
*/
6+
use InvalidArgumentException;
7+
158
#[Attribute(Attribute::TARGET_METHOD)]
169
class Method
1710
{
@@ -25,7 +18,7 @@ class Method
2518
public function __construct(array|string $methods)
2619
{
2720
if (empty($methods)) {
28-
throw new AnnotationException('Empty @Method given');
21+
throw new InvalidArgumentException('Empty #[Method] given');
2922
}
3023

3124
// Wrap single given method into array

src/Core/Annotation/Controller/Negotiation.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
namespace Apitte\Core\Annotation\Controller;
44

55
use Attribute;
6-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
7-
use Doctrine\Common\Annotations\Annotation\Target;
8-
9-
/**
10-
* @Annotation
11-
* @Target("ANNOTATION")
12-
* @NamedArgumentConstructor()
13-
*/
6+
147
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
158
class Negotiation
169
{

src/Core/Annotation/Controller/Negotiations.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22

33
namespace Apitte\Core\Annotation\Controller;
44

5-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
6-
use Doctrine\Common\Annotations\Annotation\Target;
7-
use Doctrine\Common\Annotations\AnnotationException;
8-
9-
/**
10-
* @Annotation
11-
* @Target("METHOD")
12-
* @NamedArgumentConstructor()
13-
*/
5+
use InvalidArgumentException;
6+
147
class Negotiations
158
{
169

@@ -23,7 +16,7 @@ class Negotiations
2316
public function __construct(array|Negotiation $negotiations)
2417
{
2518
if (empty($negotiations)) {
26-
throw new AnnotationException('Empty @Negotiations given');
19+
throw new InvalidArgumentException('Empty #[Negotiations] given');
2720
}
2821

2922
// Wrap single given request parameter into array

src/Core/Annotation/Controller/OpenApi.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
namespace Apitte\Core\Annotation\Controller;
44

55
use Attribute;
6-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
7-
use Doctrine\Common\Annotations\Annotation\Target;
8-
9-
/**
10-
* @Annotation
11-
* @Target({"CLASS","METHOD"})
12-
* @NamedArgumentConstructor()
13-
*/
6+
147
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
158
class OpenApi
169
{

src/Core/Annotation/Controller/Path.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
namespace Apitte\Core\Annotation\Controller;
44

55
use Attribute;
6-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
7-
use Doctrine\Common\Annotations\Annotation\Target;
8-
use Doctrine\Common\Annotations\AnnotationException;
9-
10-
/**
11-
* @Annotation
12-
* @Target({"CLASS","METHOD"})
13-
* @NamedArgumentConstructor()
14-
*/
6+
use InvalidArgumentException;
7+
158
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
169
class Path
1710
{
@@ -21,7 +14,7 @@ class Path
2114
public function __construct(string $path)
2215
{
2316
if ($path === '') {
24-
throw new AnnotationException('Empty @Path given');
17+
throw new InvalidArgumentException('Empty #[Path] given');
2518
}
2619

2720
$this->path = $path;

src/Core/Annotation/Controller/RequestBody.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
namespace Apitte\Core\Annotation\Controller;
44

55
use Attribute;
6-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
7-
use Doctrine\Common\Annotations\Annotation\Target;
8-
9-
/**
10-
* @Annotation
11-
* @Target("METHOD")
12-
* @NamedArgumentConstructor()
13-
*/
6+
147
#[Attribute(Attribute::TARGET_METHOD)]
158
class RequestBody
169
{

src/Core/Annotation/Controller/RequestParameter.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44

55
use Apitte\Core\Schema\EndpointParameter;
66
use Attribute;
7-
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
8-
use Doctrine\Common\Annotations\Annotation\Target;
9-
use Doctrine\Common\Annotations\AnnotationException;
10-
11-
/**
12-
* @Annotation
13-
* @Target("ANNOTATION")
14-
* @NamedArgumentConstructor()
15-
*/
7+
use InvalidArgumentException;
8+
169
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1710
class RequestParameter
1811
{
@@ -49,15 +42,15 @@ public function __construct(
4942
)
5043
{
5144
if ($name === '') {
52-
throw new AnnotationException('Empty @RequestParameter name given');
45+
throw new InvalidArgumentException('Empty #[RequestParameter] name given');
5346
}
5447

5548
if ($type === '') {
56-
throw new AnnotationException('Empty @RequestParameter type given');
49+
throw new InvalidArgumentException('Empty #[RequestParameter] type given');
5750
}
5851

5952
if (!in_array($in, EndpointParameter::IN, true)) {
60-
throw new AnnotationException('Invalid @RequestParameter in given');
53+
throw new InvalidArgumentException('Invalid #[RequestParameter] in given');
6154
}
6255

6356
$this->name = $name;

0 commit comments

Comments
 (0)