Skip to content

Commit

Permalink
handle BCs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakhar Shokel committed Jun 10, 2024
1 parent 800cf0f commit 748dba8
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/Annotation/RestAnnotationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface RestAnnotationInterface
{
public function isSeveralSupported(): bool;

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void;
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod);
}
30 changes: 21 additions & 9 deletions src/Attribute/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,33 @@ class Body implements RestAttributeInterface
private $optional;

public function __construct(
array $data = [],
array $options = [],
string $parameterName = null,
?string $denormalizationType = null,
?string $denormalizationGroup = null,
?bool $optional = null
) {
$this->setParameterName($data['parameterName'] ?? $parameterName);
$this->setDenormalizationType($data['denormalizationType'] ?? $denormalizationType);
$this->setDenormalizationGroup($data['denormalizationGroup'] ?? $denormalizationGroup);
$this->setOptional($data['optional'] ?? $optional);
$this->setParameterName($options['parameterName'] ?? $parameterName);
$this->setDenormalizationType($options['denormalizationType'] ?? $denormalizationType);
$this->setDenormalizationGroup($options['denormalizationGroup'] ?? $denormalizationGroup);
$this->setOptional($options['optional'] ?? $optional);
}

private function setDenormalizationType(?string $denormalizationType): self
/**
* @param string|null $denormalizationType
* @return $this
*/
private function setDenormalizationType($denormalizationType): self
{
$this->denormalizationType = $denormalizationType;
return $this;
}

public function setDenormalizationGroup(?string $denormalizationGroup): self
/**
* @param string|null $denormalizationGroup
* @return $this
*/
public function setDenormalizationGroup($denormalizationGroup): self
{
$this->denormalizationGroup = $denormalizationGroup;
return $this;
Expand All @@ -63,13 +71,17 @@ private function setParameterName(string $parameterName): self
return $this;
}

private function setOptional(?bool $optional): self
/**
* @param bool|null $optional
* @return $this
*/
private function setOptional($optional): self
{
$this->optional = $optional;
return $this;
}

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
{
$options->setBodyParameterName($this->parameterName);
$options->setBodyDenormalizationType($this->resolveDenormalizationType($reflectionMethod));
Expand Down
8 changes: 4 additions & 4 deletions src/Attribute/BodyContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class BodyContentType implements RestAttributeInterface
private $jsonEncodedBody;

public function __construct(
array $data = [],
array $options = [],
array $supportedContentTypes = null,
bool $jsonEncodedBody = false
) {
$this->setSupportedContentTypes($data['supportedContentTypes'] ?? $supportedContentTypes);
$this->setJsonEncodedBody($data['jsonEncodedBody'] ?? $jsonEncodedBody);
$this->setSupportedContentTypes($options['supportedContentTypes'] ?? $supportedContentTypes);
$this->setJsonEncodedBody($options['jsonEncodedBody'] ?? $jsonEncodedBody);
}

private function setSupportedContentTypes(array $supportedContentTypes): self
Expand All @@ -42,7 +42,7 @@ private function setJsonEncodedBody(bool $jsonEncodedBody): self
return $this;
}

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
{
$options->setSupportedContentTypes($this->supportedContentTypes, $this->jsonEncodedBody);
}
Expand Down
24 changes: 16 additions & 8 deletions src/Attribute/PathAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class PathAttribute implements RestAttributeInterface
private $resolutionMandatory;

public function __construct(
array $data = [],
array $options = [],
string $parameterName = null,
string $pathPartName = null,
?string $resolverType = null,
?bool $resolutionMandatory = null
) {
$this->setParameterName($data['parameterName'] ?? $parameterName);
$this->setPathPartName($data['pathPartName'] ?? $pathPartName);
$this->setResolverType($data['resolverType'] ?? $resolverType);
$this->setResolutionMandatory($data['resolutionMandatory'] ?? $resolutionMandatory);
$this->setParameterName($options['parameterName'] ?? $parameterName);
$this->setPathPartName($options['pathPartName'] ?? $pathPartName);
$this->setResolverType($options['resolverType'] ?? $resolverType);
$this->setResolutionMandatory($options['resolutionMandatory'] ?? $resolutionMandatory);
}

private function setParameterName(string $parameterName): self
Expand All @@ -58,19 +58,27 @@ private function setPathPartName(string $pathPartName): self
return $this;
}

private function setResolverType(?string $resolverType): self
/**
* @param string|null $resolverType
* @return $this
*/
private function setResolverType($resolverType): self
{
$this->resolverType = $resolverType;
return $this;
}

private function setResolutionMandatory(?bool $resolutionMandatory): self
/**
* @param bool|null $resolutionMandatory
* @return $this
*/
private function setResolutionMandatory($resolutionMandatory): self
{
$this->resolutionMandatory = $resolutionMandatory;
return $this;
}

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
{
$options->addPathAttributeResolverOptions(
(new PathAttributeResolverOptions())
Expand Down
32 changes: 22 additions & 10 deletions src/Attribute/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class Query implements RestAttributeInterface
private $validation;

public function __construct(
array $data = [],
array $options = [],
string $parameterName = null,
?string $denormalizationType = null,
?string $denormalizationGroup = null,
?Validation $validation = null
) {
$this->setParameterName($data['parameterName'] ?? $parameterName);
$this->setDenormalizationType($data['denormalizationType'] ?? $denormalizationType);
$this->setDenormalizationGroup($data['denormalizationGroup'] ?? $denormalizationGroup);
$this->setValidation($data['validation'] ?? $validation);
$this->setParameterName($options['parameterName'] ?? $parameterName);
$this->setDenormalizationType($options['denormalizationType'] ?? $denormalizationType);
$this->setDenormalizationGroup($options['denormalizationGroup'] ?? $denormalizationGroup);
$this->setValidation($options['validation'] ?? $validation);
}

private function setParameterName(string $parameterName): self
Expand All @@ -52,25 +52,37 @@ private function setParameterName(string $parameterName): self
return $this;
}

private function setDenormalizationType(?string $denormalizationType): self
/**
* @param string|null $denormalizationType
* @return $this
*/
private function setDenormalizationType($denormalizationType): self
{
$this->denormalizationType = $denormalizationType;
return $this;
}

public function setDenormalizationGroup(?string $denormalizationGroup): self
/**
* @param string|null $denormalizationGroup
* @return $this
*/
public function setDenormalizationGroup($denormalizationGroup): self
{
$this->denormalizationGroup = $denormalizationGroup;
return $this;
}

private function setValidation(?Validation $validation): self
/**
* @param Validation|null $validation
* @return $this
*/
private function setValidation($validation): self
{
$this->validation = $validation;
return $this;
}

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
{
$resolverOptions = (new QueryResolverOptions())
->setParameterName($this->parameterName)
Expand Down Expand Up @@ -104,7 +116,7 @@ private function resolveDenormalizationType(ReflectionMethodWrapper $reflectionM
return $typeName;
}

private function setValidationOptions(ReflectionMethodWrapper $reflectionMethod, QueryResolverOptions $options)
private function setValidationOptions(ReflectionMethodWrapper $reflectionMethod, QueryResolverOptions $options): void
{
if ($this->validation === null) {
return;
Expand Down
6 changes: 3 additions & 3 deletions src/Attribute/RequiredPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class RequiredPermissions implements RestAttributeInterface
private $permissions;

public function __construct(
array $data = [],
array $options = [],
array $permissions = null
) {
$this->setPermissions($data['permissions'] ?? $permissions);
$this->setPermissions($options['permissions'] ?? $permissions);
}

private function setPermissions(array $permissions): self
Expand All @@ -29,7 +29,7 @@ private function setPermissions(array $permissions): self
return $this;
}

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
{
$options->setRequiredPermissions(
array_unique(array_merge($options->getRequiredPermissions(), $this->permissions))
Expand Down
20 changes: 14 additions & 6 deletions src/Attribute/ResponseNormalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,36 @@ class ResponseNormalization implements RestAttributeInterface
private $normalizationGroup;

public function __construct(
array $data = [],
array $options = [],
?string $normalizationType = null,
?string $normalizationGroup = null
)
{
$this->setNormalizationType($data['normalizationType'] ?? $normalizationType);
$this->setNormalizationGroup($data['normalizationGroup'] ?? $normalizationGroup);
$this->setNormalizationType($options['normalizationType'] ?? $normalizationType);
$this->setNormalizationGroup($options['normalizationGroup'] ?? $normalizationGroup);
}

private function setNormalizationType(?string $normalizationType): self
/**
* @param string|null $normalizationType
* @return $this
*/
private function setNormalizationType($normalizationType): self
{
$this->normalizationType = $normalizationType;
return $this;
}

public function setNormalizationGroup(?string $normalizationGroup): self
/**
* @param string|null $normalizationGroup
* @return $this
*/
public function setNormalizationGroup($normalizationGroup): self
{
$this->normalizationGroup = $normalizationGroup;
return $this;
}

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
{
$options->setResponseNormalizationType($this->normalizationType);
$options->setResponseNormalizationGroup($this->normalizationGroup);
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/RestAttributeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

interface RestAttributeInterface
{
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void;
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod);
}
10 changes: 5 additions & 5 deletions src/Attribute/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class Validation implements RestAttributeInterface
private $enabled;

public function __construct(
array $data = [],
array $options = [],
array $groups = [Constraint::DEFAULT_GROUP],
array $violationPathMap = [],
bool $enabled = true
) {
$this->setGroups($data['groups'] ?? $groups);
$this->setViolationPathMap($data['violationPathMap'] ?? $violationPathMap);
$this->setEnabled($data['enabled'] ?? $enabled);
$this->setGroups($options['groups'] ?? $groups);
$this->setViolationPathMap($options['violationPathMap'] ?? $violationPathMap);
$this->setEnabled($options['enabled'] ?? $enabled);
}

private function setGroups(array $groups): self
Expand All @@ -57,7 +57,7 @@ private function setEnabled(bool $enabled): self
return $this;
}

public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod): void
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
{
if (!$this->enabled) {
$options->disableBodyValidation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @internal
*/
class RestRequestAnnotationOptionsBuilder implements RestRequestOptionsBuilderInterface
class RestRequestAnnotationOptionsBuilder
{
/**
* @var RestRequestOptionsValidator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @internal
*/
class RestRequestAttributeOptionsBuilder implements RestRequestOptionsBuilderInterface
class RestRequestAttributeOptionsBuilder
{
/**
* @var RestRequestOptionsValidator
Expand Down
13 changes: 0 additions & 13 deletions src/Service/RoutingLoader/RestRequestOptionsBuilderInterface.php

This file was deleted.

0 comments on commit 748dba8

Please sign in to comment.