Skip to content

Commit

Permalink
chore: 5.x update PropertyDescriberInterface::supports()
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Nov 12, 2024
1 parent f4b1cfe commit 7acd32c
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 23 deletions.
11 changes: 9 additions & 2 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ This parameter was deprecated since `4.25.2`
+ public function describe(array $types, Schema $property, array $context = []);
```

`$groups` are now passed in `$context` and can be accessed via `$context['groups']`.
`$groups` are passed in `$context` and can be accessed via `$context['groups']`.

`$schema` has been removed with no replacement.
`$schema` has been removed with no replacement.

## BC BREAK: Updated `PropertyDescriberInterface::supports()` signature
Future proofing for potential future changes and keeping it consistent with `describe()`.
```diff
- public function supports(array $types): bool;
+ public function supports(array $types, array $context = []): bool;
```
2 changes: 1 addition & 1 deletion src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private function describeProperty(array $types, Model $model, OA\Schema $propert
if ($this->propertyDescriber instanceof ModelRegistryAwareInterface) {
$this->propertyDescriber->setModelRegistry($this->modelRegistry);
}
if ($this->propertyDescriber->supports($types)) {
if ($this->propertyDescriber->supports($types, $model->getSerializationContext())) {
$this->propertyDescriber->describe($types, $property, $model->getSerializationContext());

return;
Expand Down
4 changes: 2 additions & 2 deletions src/PropertyDescriber/ArrayPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public function describe(array $types, OA\Schema $property, array $context = [])
foreach ($types[0]->getCollectionValueTypes() as $type) {
// Handle list pseudo type
// https://symfony.com/doc/current/components/property_info.html#type-getcollectionkeytypes-type-getcollectionvaluetypes
if ($this->supports([$type]) && [] === $type->getCollectionValueTypes()) {
if ($this->supports([$type], $context) && [] === $type->getCollectionValueTypes()) {
continue;
}

$this->propertyDescriber->describe([$type], $property, $context);
}
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
if (1 !== count($types) || !$types[0]->isCollection()) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/BooleanPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$property->type = 'boolean';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_BOOL === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/CompoundPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
}
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return count($types) >= 2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/DateTimePropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$property->format = 'date-time';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType()
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/DictionaryPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $context);
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& $types[0]->isCollection()
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/FloatPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$property->format = 'float';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_FLOAT === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/IntegerPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$property->type = 'integer';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_INT === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/NullablePropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$this->propertyDescriber->describe($types, $property, $context);
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
foreach ($types as $type) {
if ($type->isNullable()) {
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/ObjectPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$property->ref = $this->modelRegistry->register(new Model($type, serializationContext: $context));
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType();
Expand Down
13 changes: 7 additions & 6 deletions src/PropertyDescriber/PropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
*/
public function describe(array $types, OA\Schema $property, array $context = []): void
{
if (null === $propertyDescriber = $this->getPropertyDescriber($types)) {
if (null === $propertyDescriber = $this->getPropertyDescriber($types, $context)) {
return;
}

Expand All @@ -51,9 +51,9 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$this->called = []; // Reset recursion helper
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return null !== $this->getPropertyDescriber($types);
return null !== $this->getPropertyDescriber($types, $context);
}

/**
Expand All @@ -65,9 +65,10 @@ private function getHash(array $types): string
}

/**
* @param Type[] $types
* @param Type[] $types
* @param array<string, mixed> $context
*/
private function getPropertyDescriber(array $types): ?PropertyDescriberInterface
private function getPropertyDescriber(array $types, array $context): ?PropertyDescriberInterface
{
foreach ($this->propertyDescribers as $propertyDescriber) {
/* BC layer for Symfony < 6.3 @see https://symfony.com/doc/6.3/service_container/tags.html#reference-tagged-services */
Expand All @@ -90,7 +91,7 @@ private function getPropertyDescriber(array $types): ?PropertyDescriberInterface
$propertyDescriber->setPropertyDescriber($this);
}

if ($propertyDescriber->supports($types)) {
if ($propertyDescriber->supports($types, $context)) {
return $propertyDescriber;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/PropertyDescriber/PropertyDescriberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ interface PropertyDescriberInterface
public function describe(array $types, Schema $property, array $context = []);

/**
* @param Type[] $types
* @param Type[] $types
* @param array<string, mixed> $context Context options for describing the property
*/
public function supports(array $types): bool;
public function supports(array $types, array $context = []): bool;
}
2 changes: 1 addition & 1 deletion src/PropertyDescriber/StringPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$property->type = 'string';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_STRING === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/UuidPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function describe(array $types, OA\Schema $property, array $context = [])
$property->format = 'uuid';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType()
Expand Down

0 comments on commit 7acd32c

Please sign in to comment.