Skip to content

Commit fed9ffe

Browse files
authored
Psr/container ^2 support (#518)
* psr/container v2 * Implement replacement for Picotainer * Replace Picotainer with LazyContainer in tests and documentation for version >=6 * Fix tests for phpdocumentor/type-resolver minor update * run cs-fix script * Fix some cs-fixer errors manually * fix return type * abandon psr/container ^1 * Test for LazyContainer
1 parent fc9eae6 commit fed9ffe

File tree

145 files changed

+639
-897
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+639
-897
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"composer/package-versions-deprecated": "^1.8",
1717
"phpdocumentor/reflection-docblock": "^4.3 || ^5.0",
1818
"phpdocumentor/type-resolver": "^1.4",
19-
"psr/container": "^1",
19+
"psr/container": "^2",
2020
"psr/http-factory": "^1",
2121
"psr/http-message": "^1.0.1",
2222
"psr/http-server-handler": "^1",
@@ -33,7 +33,6 @@
3333
"doctrine/coding-standard": "^9.0 || ^10.0",
3434
"ecodev/graphql-upload": "^6.1",
3535
"laminas/laminas-diactoros": "^2",
36-
"mouf/picotainer": "^1.1",
3736
"myclabs/php-enum": "^1.6.6",
3837
"php-coveralls/php-coveralls": "^2.1",
3938
"phpstan/extension-installer": "^1.1",

src/AggregateControllerQueryProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ public function __construct(private iterable $controllers, private FieldsBuilder
3333
{
3434
}
3535

36-
/**
37-
* @return array<string,FieldDefinition>
38-
*/
36+
/** @return array<string,FieldDefinition> */
3937
public function getQueries(): array
4038
{
4139
$queryList = [];
@@ -48,9 +46,7 @@ public function getQueries(): array
4846
return $this->flattenList($queryList);
4947
}
5048

51-
/**
52-
* @return array<string, FieldDefinition>
53-
*/
49+
/** @return array<string, FieldDefinition> */
5450
public function getMutations(): array
5551
{
5652
$mutationList = [];

src/AggregateQueryProvider.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ class AggregateQueryProvider implements QueryProviderInterface
1717
/** @var QueryProviderInterface[] */
1818
private array $queryProviders;
1919

20-
/**
21-
* @param QueryProviderInterface[] $queryProviders
22-
*/
20+
/** @param QueryProviderInterface[] $queryProviders */
2321
public function __construct(iterable $queryProviders)
2422
{
2523
$this->queryProviders = is_array($queryProviders) ? $queryProviders : iterator_to_array($queryProviders);
2624
}
2725

28-
/**
29-
* @return QueryField[]
30-
*/
26+
/** @return QueryField[] */
3127
public function getQueries(): array
3228
{
3329
$queriesArray = array_map(static function (QueryProviderInterface $queryProvider) {
@@ -40,9 +36,7 @@ public function getQueries(): array
4036
return array_merge(...$queriesArray);
4137
}
4238

43-
/**
44-
* @return QueryField[]
45-
*/
39+
/** @return QueryField[] */
4640
public function getMutations(): array
4741
{
4842
$mutationsArray = array_map(static function (QueryProviderInterface $queryProvider) {

src/AnnotationReader.php

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AnnotationReader
4949
{
5050
// In this mode, no exceptions will be thrown for incorrect annotations (unless the name of the annotation we are looking for is part of the docblock)
5151
public const LAX_MODE = 'LAX_MODE';
52+
5253
// In this mode, exceptions will be thrown for any incorrect annotations.
5354
public const STRICT_MODE = 'STRICT_MODE';
5455

@@ -86,7 +87,7 @@ public function __construct(private Reader $reader, private string $mode = self:
8687
*
8788
* @template T of object
8889
*/
89-
private function getClassAnnotation(ReflectionClass $refClass, string $annotationClass): ?object
90+
private function getClassAnnotation(ReflectionClass $refClass, string $annotationClass): object|null
9091
{
9192
try {
9293
$attribute = $refClass->getAttributes($annotationClass)[0] ?? null;
@@ -123,7 +124,7 @@ private function getClassAnnotation(ReflectionClass $refClass, string $annotatio
123124
*
124125
* @throws AnnotationException
125126
*/
126-
private function getMethodAnnotation(ReflectionMethod $refMethod, string $annotationClass): ?object
127+
private function getMethodAnnotation(ReflectionMethod $refMethod, string $annotationClass): object|null
127128
{
128129
$cacheKey = $refMethod->getDeclaringClass()->getName() . '::' . $refMethod->getName() . '_' . $annotationClass;
129130
if (array_key_exists($cacheKey, $this->methodAnnotationCache)) {
@@ -200,7 +201,7 @@ static function ($attribute) {
200201
},
201202
array_filter($refClass->getAttributes(), static function ($annotation) use ($annotationClass): bool {
202203
return is_a($annotation->getName(), $annotationClass, true);
203-
})
204+
}),
204205
);
205206

206207
$toAddAnnotations[] = $attributes;
@@ -231,7 +232,7 @@ static function ($attribute) {
231232
*
232233
* @template T of object
233234
*/
234-
public function getTypeAnnotation(ReflectionClass $refClass): ?TypeInterface
235+
public function getTypeAnnotation(ReflectionClass $refClass): TypeInterface|null
235236
{
236237
try {
237238
$type = $this->getClassAnnotation($refClass, Type::class)
@@ -276,7 +277,7 @@ public function getInputAnnotations(ReflectionClass $refClass): array
276277
*
277278
* @template T of object
278279
*/
279-
public function getExtendTypeAnnotation(ReflectionClass $refClass): ?ExtendType
280+
public function getExtendTypeAnnotation(ReflectionClass $refClass): ExtendType|null
280281
{
281282
try {
282283
$extendType = $this->getClassAnnotation($refClass, ExtendType::class);
@@ -287,15 +288,13 @@ public function getExtendTypeAnnotation(ReflectionClass $refClass): ?ExtendType
287288
return $extendType;
288289
}
289290

290-
public function getEnumTypeAnnotation(ReflectionClass $refClass): ?EnumType
291+
public function getEnumTypeAnnotation(ReflectionClass $refClass): EnumType|null
291292
{
292293
return $this->getClassAnnotation($refClass, EnumType::class);
293294
}
294295

295-
/**
296-
* @param class-string<AbstractRequest> $annotationClass
297-
*/
298-
public function getRequestAnnotation(ReflectionMethod $refMethod, string $annotationClass): ?AbstractRequest
296+
/** @param class-string<AbstractRequest> $annotationClass */
297+
public function getRequestAnnotation(ReflectionMethod $refMethod, string $annotationClass): AbstractRequest|null
299298
{
300299
$queryAnnotation = $this->getMethodAnnotation($refMethod, $annotationClass);
301300
assert($queryAnnotation instanceof AbstractRequest || $queryAnnotation === null);
@@ -318,15 +317,15 @@ public function getSourceFields(ReflectionClass $refClass): array
318317
return $sourceFields;
319318
}
320319

321-
public function getFactoryAnnotation(ReflectionMethod $refMethod): ?Factory
320+
public function getFactoryAnnotation(ReflectionMethod $refMethod): Factory|null
322321
{
323322
$factoryAnnotation = $this->getMethodAnnotation($refMethod, Factory::class);
324323
assert($factoryAnnotation instanceof Factory || $factoryAnnotation === null);
325324

326325
return $factoryAnnotation;
327326
}
328327

329-
public function getDecorateAnnotation(ReflectionMethod $refMethod): ?Decorate
328+
public function getDecorateAnnotation(ReflectionMethod $refMethod): Decorate|null
330329
{
331330
$decorateAnnotation = $this->getMethodAnnotation($refMethod, Decorate::class);
332331
assert($decorateAnnotation instanceof Decorate || $decorateAnnotation === null);
@@ -376,9 +375,7 @@ public function getParameterAnnotationsPerParameter(array $refParameters): array
376375
/** @var ParameterAnnotationInterface[] $parameterAnnotations */
377376
$parameterAnnotations = $this->getMethodAnnotations($method, ParameterAnnotationInterface::class);
378377

379-
/**
380-
* @var array<string, array<int,ParameterAnnotations>> $parameterAnnotationsPerParameter
381-
*/
378+
/** @var array<string, array<int,ParameterAnnotations>> $parameterAnnotationsPerParameter */
382379
$parameterAnnotationsPerParameter = [];
383380
foreach ($parameterAnnotations as $parameterAnnotation) {
384381
$parameterAnnotationsPerParameter[$parameterAnnotation->getTarget()][] = $parameterAnnotation;
@@ -406,25 +403,21 @@ static function ($attribute) {
406403
},
407404
array_filter($attributes, static function ($annotation): bool {
408405
return is_a($annotation->getName(), ParameterAnnotationInterface::class, true);
409-
})
406+
}),
410407
),
411408
];
412409
}
413410

414411
return array_map(
415412
static function (array $parameterAnnotations): ParameterAnnotations {
416-
/**
417-
* @var ParameterAnnotationInterface[] $parameterAnnotations
418-
*/
413+
/** @var ParameterAnnotationInterface[] $parameterAnnotations */
419414
return new ParameterAnnotations($parameterAnnotations);
420415
},
421-
$parameterAnnotationsPerParameter
416+
$parameterAnnotationsPerParameter,
422417
);
423418
}
424419

425-
/**
426-
* @throws AnnotationException
427-
*/
420+
/** @throws AnnotationException */
428421
public function getMiddlewareAnnotations(ReflectionMethod|ReflectionProperty $reflection): MiddlewareAnnotations
429422
{
430423
if ($reflection instanceof ReflectionMethod) {
@@ -469,7 +462,7 @@ static function ($attribute) {
469462
},
470463
array_filter($attributes, static function ($annotation) use ($annotationClass): bool {
471464
return is_a($annotation->getName(), $annotationClass, true);
472-
})
465+
}),
473466
),
474467
];
475468
} catch (AnnotationException $e) {
@@ -525,7 +518,7 @@ static function ($attribute) {
525518
},
526519
array_filter($attributes, static function ($annotation) use ($annotationClass): bool {
527520
return is_a($annotation->getName(), $annotationClass, true);
528-
})
521+
}),
529522
),
530523
];
531524
} catch (AnnotationException $e) {

src/Annotations/AbstractRequest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66

77
abstract class AbstractRequest
88
{
9-
private ?string $outputType;
9+
private string|null $outputType;
1010

11-
private ?string $name;
11+
private string|null $name;
1212

13-
/**
14-
* @param mixed[] $attributes
15-
*/
16-
public function __construct(array $attributes = [], ?string $name = null, ?string $outputType = null)
13+
/** @param mixed[] $attributes */
14+
public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null)
1715
{
1816
$this->outputType = $outputType ?? $attributes['outputType'] ?? null;
1917
$this->name = $name ?? $attributes['name'] ?? null;
@@ -23,7 +21,7 @@ public function __construct(array $attributes = [], ?string $name = null, ?strin
2321
* Returns the GraphQL return type of the request (as a string).
2422
* The string can represent the FQCN of the type or an entry in the container resolving to the GraphQL type.
2523
*/
26-
public function getOutputType(): ?string
24+
public function getOutputType(): string|null
2725
{
2826
return $this->outputType;
2927
}
@@ -32,7 +30,7 @@ public function getOutputType(): ?string
3230
* Returns the name of the GraphQL query/mutation/field.
3331
* If not specified, the name of the method should be used instead.
3432
*/
35-
public function getName(): ?string
33+
public function getName(): string|null
3634
{
3735
return $this->name;
3836
}

src/Annotations/Autowire.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class Autowire implements ParameterAnnotationInterface
2828
/** @var string|null */
2929
private $identifier;
3030

31-
/**
32-
* @param array<string, mixed>|string $identifier
33-
*/
31+
/** @param array<string, mixed>|string $identifier */
3432
public function __construct(array|string $identifier = [])
3533
{
3634
$values = $identifier;
@@ -52,7 +50,7 @@ public function getTarget(): string
5250
return $this->for;
5351
}
5452

55-
public function getIdentifier(): ?string
53+
public function getIdentifier(): string|null
5654
{
5755
return $this->identifier;
5856
}

src/Annotations/EnumType.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ class EnumType
2626
/** @var bool */
2727
private $useValues;
2828

29-
/**
30-
* @param mixed[] $attributes
31-
*/
32-
public function __construct(array $attributes = [], ?string $name = null, ?bool $useValues = null)
29+
/** @param mixed[] $attributes */
30+
public function __construct(array $attributes = [], string|null $name = null, bool|null $useValues = null)
3331
{
3432
$this->name = $name ?? $attributes['name'] ?? null;
3533
$this->useValues = $useValues ?? $attributes['useValues'] ?? false;
@@ -38,7 +36,7 @@ public function __construct(array $attributes = [], ?string $name = null, ?bool
3836
/**
3937
* Returns the GraphQL name for this type.
4038
*/
41-
public function getName(): ?string
39+
public function getName(): string|null
4240
{
4341
return $this->name;
4442
}

src/Annotations/ExtendType.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ class ExtendType
3030
/** @var string|null */
3131
private $name;
3232

33-
/**
34-
* @param mixed[] $attributes
35-
*/
36-
public function __construct(array $attributes = [], ?string $class = null, ?string $name = null)
33+
/** @param mixed[] $attributes */
34+
public function __construct(array $attributes = [], string|null $class = null, string|null $name = null)
3735
{
3836
$className = isset($attributes['class']) ? ltrim($attributes['class'], '\\') : null;
3937
$className = $className ?? $class;
@@ -53,12 +51,12 @@ public function __construct(array $attributes = [], ?string $class = null, ?stri
5351
*
5452
* @return class-string<object>|null
5553
*/
56-
public function getClass(): ?string
54+
public function getClass(): string|null
5755
{
5856
return $this->class;
5957
}
6058

61-
public function getName(): ?string
59+
public function getName(): string|null
6260
{
6361
return $this->name;
6462
}

src/Annotations/Factory.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ class Factory
2525
/** @var bool */
2626
private $default;
2727

28-
/**
29-
* @param mixed[] $attributes
30-
*/
31-
public function __construct(array $attributes = [], ?string $name = null, ?bool $default = null)
28+
/** @param mixed[] $attributes */
29+
public function __construct(array $attributes = [], string|null $name = null, bool|null $default = null)
3230
{
3331
$this->name = $name ?? $attributes['name'] ?? null;
3432
// This IS the default if no name is set and no "default" attribute is passed.
@@ -43,7 +41,7 @@ public function __construct(array $attributes = [], ?string $name = null, ?bool
4341
* Returns the name of the GraphQL input type.
4442
* If not specified, the name of the method should be used instead.
4543
*/
46-
public function getName(): ?string
44+
public function getName(): string|null
4745
{
4846
return $this->name;
4947
}

src/Annotations/FailWith.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class FailWith implements MiddlewareAnnotationInterface
2828
*/
2929
private $value;
3030

31-
/**
32-
* @throws BadMethodCallException
33-
*/
31+
/** @throws BadMethodCallException */
3432
public function __construct(mixed $values = [], mixed $value = '__fail__with__magic__key__')
3533
{
3634
if ($value !== '__fail__with__magic__key__') {

src/Annotations/Field.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Field extends AbstractRequest
4141
* @param mixed[] $attributes
4242
* @param string|string[] $for
4343
*/
44-
public function __construct(array $attributes = [], ?string $name = null, ?string $outputType = null, ?string $prefetchMethod = null, string|array|null $for = null, ?string $description = null, ?string $inputType = null)
44+
public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null, string|null $prefetchMethod = null, string|array|null $for = null, string|null $description = null, string|null $inputType = null)
4545
{
4646
parent::__construct($attributes, $name, $outputType);
4747
$this->prefetchMethod = $prefetchMethod ?? $attributes['prefetchMethod'] ?? null;
@@ -59,25 +59,23 @@ public function __construct(array $attributes = [], ?string $name = null, ?strin
5959
/**
6060
* Returns the prefetch method name (the method that will be called to fetch many records at once)
6161
*/
62-
public function getPrefetchMethod(): ?string
62+
public function getPrefetchMethod(): string|null
6363
{
6464
return $this->prefetchMethod;
6565
}
6666

67-
/**
68-
* @return string[]|null
69-
*/
70-
public function getFor(): ?array
67+
/** @return string[]|null */
68+
public function getFor(): array|null
7169
{
7270
return $this->for;
7371
}
7472

75-
public function getDescription(): ?string
73+
public function getDescription(): string|null
7674
{
7775
return $this->description;
7876
}
7977

80-
public function getInputType(): ?string
78+
public function getInputType(): string|null
8179
{
8280
return $this->inputType;
8381
}

0 commit comments

Comments
 (0)