Skip to content

Commit

Permalink
feat: [5.x] php minimum to 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Oct 18, 2024
1 parent 9587aa7 commit b8d389a
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 301 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: 7.4
- php-version: 8.1
composer-flags: "--prefer-lowest"
doctrine-annotations: true
- php-version: 7.4
symfony-require: "5.4.*"
doctrine-annotations: true
- php-version: 8.0
symfony-require: "5.4.*"
doctrine-annotations: true
- php-version: 8.1
symfony-require: "5.4.*"
doctrine-annotations: true
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-json": "*",
"phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0",
"phpdocumentor/type-resolver": "^1.8.2",
Expand Down
64 changes: 31 additions & 33 deletions src/DependencyInjection/NelmioApiDocExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,45 +184,43 @@ public function load(array $configs, ContainerBuilder $container): void
->setArgument(1, $config['media_types']);
}

if (PHP_VERSION_ID > 80100) {
// Add autoconfiguration for route argument describer
$container->registerForAutoconfiguration(RouteArgumentDescriberInterface::class)
->addTag('nelmio_api_doc.route_argument_describer');
// Add autoconfiguration for route argument describer
$container->registerForAutoconfiguration(RouteArgumentDescriberInterface::class)
->addTag('nelmio_api_doc.route_argument_describer');

$container->register('nelmio_api_doc.route_describers.route_argument', RouteArgumentDescriber::class)
$container->register('nelmio_api_doc.route_describers.route_argument', RouteArgumentDescriber::class)
->setPublic(false)
->addTag('nelmio_api_doc.route_describer', ['priority' => -225])
->setArguments([
new Reference('argument_metadata_factory'),
new TaggedIteratorArgument('nelmio_api_doc.route_argument_describer'),
])
;

if (class_exists(MapQueryString::class)) {
$container->register('nelmio_api_doc.route_argument_describer.map_query_string', SymfonyMapQueryStringDescriber::class)
->setPublic(false)
->addTag('nelmio_api_doc.route_describer', ['priority' => -225])
->setArguments([
new Reference('argument_metadata_factory'),
new TaggedIteratorArgument('nelmio_api_doc.route_argument_describer'),
])
;

if (class_exists(MapQueryString::class)) {
$container->register('nelmio_api_doc.route_argument_describer.map_query_string', SymfonyMapQueryStringDescriber::class)
->setPublic(false)
->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]);
->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]);

$container->register('nelmio_api_doc.swagger.processor.map_query_string', MapQueryStringProcessor::class)
->setPublic(false)
->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]);
}
$container->register('nelmio_api_doc.swagger.processor.map_query_string', MapQueryStringProcessor::class)
->setPublic(false)
->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]);
}

if (class_exists(MapRequestPayload::class)) {
$container->register('nelmio_api_doc.route_argument_describer.map_request_payload', SymfonyMapRequestPayloadDescriber::class)
->setPublic(false)
->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]);
if (class_exists(MapRequestPayload::class)) {
$container->register('nelmio_api_doc.route_argument_describer.map_request_payload', SymfonyMapRequestPayloadDescriber::class)
->setPublic(false)
->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]);

$container->register('nelmio_api_doc.swagger.processor.map_request_payload', MapRequestPayloadProcessor::class)
->setPublic(false)
->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]);
}
$container->register('nelmio_api_doc.swagger.processor.map_request_payload', MapRequestPayloadProcessor::class)
->setPublic(false)
->addTag('nelmio_api_doc.swagger.processor', ['priority' => 0]);
}

if (class_exists(MapQueryParameter::class)) {
$container->register('nelmio_api_doc.route_argument_describer.map_query_parameter', SymfonyMapQueryParameterDescriber::class)
->setPublic(false)
->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]);
}
if (class_exists(MapQueryParameter::class)) {
$container->register('nelmio_api_doc.route_argument_describer.map_query_parameter', SymfonyMapQueryParameterDescriber::class)
->setPublic(false)
->addTag('nelmio_api_doc.route_argument_describer', ['priority' => 0]);
}

$bundles = $container->getParameter('kernel.bundles');
Expand Down
6 changes: 2 additions & 4 deletions src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ private function getAnnotation(Context $parentContext, $reflection, string $clas
$this->setContextFromReflection($parentContext, $reflection);

try {
if (\PHP_VERSION_ID >= 80100) {
if (null !== $attribute = $reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
return $attribute->newInstance();
}
if (null !== $attribute = $reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
return $attribute->newInstance();
}

if (null !== $this->annotationsReader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private function getAnnotations(Context $parentContext, $reflection, ?array $val
*/
private function locateAnnotations($reflection): \Traversable
{
if (\PHP_VERSION_ID >= 80000 && class_exists(Constraint::class)) {
if (class_exists(Constraint::class)) {
foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
yield $attribute->newInstance();
}
Expand Down
3 changes: 0 additions & 3 deletions src/RouteDescriber/FosRestDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ private function describeCommonSchemaFromAnnotation(OA\Schema $schema, AbstractS
private function getAttributesAsAnnotation(\ReflectionMethod $reflection, string $className): array
{
$annotations = [];
if (\PHP_VERSION_ID < 80100) {
return $annotations;
}

foreach ($reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
$annotations[] = $attribute->newInstance();
Expand Down
12 changes: 3 additions & 9 deletions src/Routing/FilteredRouteCollectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ private function defaultRouteDisabled(Route $route): bool
? $this->annotationReader->getMethodAnnotations($method)
: [];

if (\PHP_VERSION_ID >= 80100) {
$annotations = array_merge($annotations, array_map(function (\ReflectionAttribute $attribute) {
return $attribute->newInstance();
}, $method->getAttributes(AbstractAnnotation::class, \ReflectionAttribute::IS_INSTANCEOF)));
}
$annotations = array_merge($annotations, array_map(function (\ReflectionAttribute $attribute) {
return $attribute->newInstance();
}, $method->getAttributes(AbstractAnnotation::class, \ReflectionAttribute::IS_INSTANCEOF)));

foreach ($annotations as $annotation) {
if (false !== strpos(get_class($annotation), 'Nelmio\\ApiDocBundle\\Annotation')
Expand All @@ -199,10 +197,6 @@ private function defaultRouteDisabled(Route $route): bool
private function getAttributesAsAnnotation($reflection, string $className): array
{
$annotations = [];
if (\PHP_VERSION_ID < 80100) {
return $annotations;
}

foreach ($reflection->getAttributes($className, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
$annotations[] = $attribute->newInstance();
}
Expand Down
24 changes: 9 additions & 15 deletions tests/Functional/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public function testControllers(?array $controller, ?string $fixtureName = null,

public static function provideAttributeTestCases(): \Generator
{
if (PHP_VERSION_ID < 80100) {
return;
}

$type = Kernel::MAJOR_VERSION === 5 ? 'annotation' : 'attribute';

yield 'Promoted properties defaults attributes' => [
Expand Down Expand Up @@ -173,17 +169,15 @@ public static function provideAnnotationTestCases(): \Generator
return;
}

if (PHP_VERSION_ID >= 80000) {
yield 'Promoted properties defaults annotations' => [
[
'name' => 'PromotedPropertiesController80',
'type' => 'annotation',
],
'PromotedPropertiesDefaults',
[],
[__DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml'],
];
}
yield 'Promoted properties defaults annotations' => [
[
'name' => 'PromotedPropertiesController80',
'type' => 'annotation',
],
'PromotedPropertiesDefaults',
[],
[__DIR__.'/Configs/AlternativeNamesPHP80Entities.yaml'],
];
}

/**
Expand Down
33 changes: 8 additions & 25 deletions tests/Functional/Form/FormWithAlternateSchemaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,19 @@

namespace Nelmio\ApiDocBundle\Tests\Functional\Form;

use OpenApi\Annotations as OA;
use OpenApi\Attributes as OAT;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

if (PHP_VERSION_ID < 80100) {
/**
* @OA\Schema(type="string")
*/
class FormWithAlternateSchemaType extends AbstractType
#[OAT\Schema(type: 'string')]
class FormWithAlternateSchemaType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('ignored', TextType::class, [
'required' => false,
]);
}
}
} else {
#[OAT\Schema(type: 'string')]
class FormWithAlternateSchemaType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('ignored', TextType::class, [
'required' => false,
]);
}
$builder
->add('ignored', TextType::class, [
'required' => false,
]);
}
}
33 changes: 8 additions & 25 deletions tests/Functional/Form/FormWithRefType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,19 @@

namespace Nelmio\ApiDocBundle\Tests\Functional\Form;

use OpenApi\Annotations as OA;
use OpenApi\Attributes as OAT;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

if (PHP_VERSION_ID < 80100) {
/**
* @OA\Schema(ref="#/components/schemas/Test")
*/
class FormWithRefType extends AbstractType
#[OAT\Schema(ref: '#/components/schemas/Test')]
class FormWithRefType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('ignored', TextType::class, [
'required' => false,
]);
}
}
} else {
#[OAT\Schema(ref: '#/components/schemas/Test')]
class FormWithRefType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('ignored', TextType::class, [
'required' => false,
]);
}
$builder
->add('ignored', TextType::class, [
'required' => false,
]);
}
}
Loading

0 comments on commit b8d389a

Please sign in to comment.