Skip to content

Commit b0d304d

Browse files
committed
Remove doctrine/annotations dependency, use PHP 8 native attributes only
- Remove doctrine/annotations and koriym/attributes dependencies - Create AttributeLoader to replace DoctrineAnnotationLoader - Inline attribute reading directly into AttributeLoader (no separate reader class) - Remove LoaderFactory directory (DualReaderFactory, 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 - Rename test files to reflect new naming - Require nette/utils ^4.1.0 This is a breaking change - docblock annotations are no longer supported.
1 parent 282d40c commit b0d304d

36 files changed

+205
-379
lines changed

composer.json

Lines changed: 3 additions & 5 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,9 +25,7 @@
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",
30-
"nette/utils": "^4.0.0"
28+
"nette/utils": "^4.1.0"
3129
},
3230
"require-dev": {
3331
"contributte/qa": "^0.4",

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ parameters:
4747
- message: "#^Parameter \\#2 \\$array of function implode expects array\\<string\\>, array\\<int, array\\<string\\>\\|string\\> given\\.$#"
4848
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php
4949

50-
# Support for doctrine/annotations ^1
51-
- message: "#^Call to function method_exists\\(\\) with 'Doctrine\\\\\\\\Common\\\\\\\\Annotations\\\\\\\\AnnotationRegistry' and 'registerUniqueLoader' will always evaluate to false\\.$#"
52-
path: src/Core/DI/LoaderFactory/DualReaderFactory.php
53-
5450
- message: "#^Dead catch - TypeError is never thrown in the try block.$#"
5551
path: src/Core/Mapping/Parameter/DateTimeTypeMapper.php
5652
count: 1

src/Core/Annotation/Controller/Id.php

Lines changed: 2 additions & 9 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;
6+
use InvalidArgumentException;
97

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

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: 2 additions & 9 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;
6+
use InvalidArgumentException;
97

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

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: 4 additions & 11 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;
7+
use InvalidArgumentException;
108

11-
/**
12-
* @Annotation
13-
* @Target("ANNOTATION")
14-
* @NamedArgumentConstructor()
15-
*/
169
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1710
class RequestParameter
1811
{
@@ -32,15 +25,15 @@ public function __construct(
3225
)
3326
{
3427
if ($name === '') {
35-
throw new AnnotationException('Empty @RequestParameter name given');
28+
throw new InvalidArgumentException('Empty #[RequestParameter] name given');
3629
}
3730

3831
if ($type === '') {
39-
throw new AnnotationException('Empty @RequestParameter type given');
32+
throw new InvalidArgumentException('Empty #[RequestParameter] type given');
4033
}
4134

4235
if (!in_array($in, EndpointParameter::IN, true)) {
43-
throw new AnnotationException('Invalid @RequestParameter in given');
36+
throw new InvalidArgumentException('Invalid #[RequestParameter] in given');
4437
}
4538
}
4639

0 commit comments

Comments
 (0)