Skip to content

Commit

Permalink
remove annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
michnovka committed Jan 3, 2024
1 parent 4533928 commit cdda179
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 13 deletions.
6 changes: 6 additions & 0 deletions tests/Fixtures/Integration/Symfony/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ services:
App\Controller\QueryBodyBackedEnumValueResolverController:
autoconfigure: true
autowire: true
App\ControllerAnnotation\BackedEnumValueResolverController:
autoconfigure: true
autowire: true
App\ControllerAnnotation\QueryBodyBackedEnumValueResolverController:
autoconfigure: true
autowire: true

logger:
class: Psr\Log\NullLogger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
controllers:
resource: ../src/Controller/
resource: ../src/ControllerAnnotation/
type: annotation
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use App\Enum\Suit;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

Expand All @@ -30,19 +30,19 @@ public function __construct()
}

#[Route(path: '/from-attributes/{suit}')]
public function fromAttributes(Suit $suit)
public function fromAttributes(Suit $suit): Response
{
return new Response($this->getDump($suit));
}

#[Route(path: '/from-attributes-nullable/{suit}')]
public function fromAttributesNullable(?Suit $suit = null)
public function fromAttributesNullable(?Suit $suit = null): Response
{
return new Response($this->getDump($suit));
}

#[Route(path: '/from-attributes-with-default')]
public function fromAttributesWithDefault(Suit $suit = Suit::Spades)
public function fromAttributesWithDefault(Suit $suit = Suit::Spades): Response
{
return new Response($this->getDump($suit));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\Attributes\BackedEnumFromQuery;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

Expand All @@ -35,55 +35,55 @@ public function __construct()
public function fromQuery(
#[BackedEnumFromQuery]
Suit $suit
) {
): Response {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-nullable')]
public function fromQueryNullable(
#[BackedEnumFromQuery]
?Suit $suit
) {
): Response {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-with-default')]
public function fromQueryWithDefault(
#[BackedEnumFromQuery]
?Suit $suit = Suit::Hearts
) {
): Response {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-with-default-non-nullable')]
public function fromQueryWithDefaultNonNullable(
#[BackedEnumFromQuery]
Suit $suit = Suit::Hearts
) {
): Response {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-variadics')]
public function fromQueryVariadics(
#[BackedEnumFromQuery]
Suit ...$suit
) {
): Response {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-body', methods: 'POST')]
public function fromBody(
#[BackedEnumFromBody]
Suit $suit
) {
): Response {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-body-variadics', methods: 'POST')]
public function fromBodyVariadics(
#[BackedEnumFromBody]
Suit ...$suit
) {
): Response {
return new Response($this->getDump($suit));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "elao/enum" package.
*
* Copyright (C) Elao
*
* @author Elao <contact@elao.com>
*/

namespace App\ControllerAnnotation;

use App\Enum\Suit;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

#[Route(path: '/resolver', name: 'from-attributes')]
class BackedEnumValueResolverController extends AbstractController
{
use VarDumperTestTrait;

public function __construct()
{
$this->setUpVarDumper([], CliDumper::DUMP_LIGHT_ARRAY);
}

#[Route(path: '/from-attributes/{suit}')]
public function fromAttributes(Suit $suit): Response
{
return new Response($this->getDump($suit));
}

#[Route(path: '/from-attributes-nullable/{suit}')]
public function fromAttributesNullable(?Suit $suit = null): Response
{
return new Response($this->getDump($suit));
}

#[Route(path: '/from-attributes-with-default')]
public function fromAttributesWithDefault(Suit $suit = Suit::Spades): Response
{
return new Response($this->getDump($suit));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "elao/enum" package.
*
* Copyright (C) Elao
*
* @author Elao <contact@elao.com>
*/

namespace App\Controller;

use App\Enum\Suit;
use Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\Attributes\BackedEnumFromBody;
use Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\Attributes\BackedEnumFromQuery;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

#[Route(path: '/resolver', name: 'from-query-body')]
class QueryBodyBackedEnumValueResolverController extends AbstractController
{
use VarDumperTestTrait;

public function __construct()
{
$this->setUpVarDumper([], CliDumper::DUMP_LIGHT_ARRAY);
}

#[Route(path: '/from-query')]
public function fromQuery(
#[BackedEnumFromQuery]
Suit $suit
) {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-nullable')]
public function fromQueryNullable(
#[BackedEnumFromQuery]
?Suit $suit
) {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-with-default')]
public function fromQueryWithDefault(
#[BackedEnumFromQuery]
?Suit $suit = Suit::Hearts
) {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-with-default-non-nullable')]
public function fromQueryWithDefaultNonNullable(
#[BackedEnumFromQuery]
Suit $suit = Suit::Hearts
) {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-query-variadics')]
public function fromQueryVariadics(
#[BackedEnumFromQuery]
Suit ...$suit
) {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-body', methods: 'POST')]
public function fromBody(
#[BackedEnumFromBody]
Suit $suit
) {
return new Response($this->getDump($suit));
}

#[Route(path: '/from-body-variadics', methods: 'POST')]
public function fromBodyVariadics(
#[BackedEnumFromBody]
Suit ...$suit
) {
return new Response($this->getDump($suit));
}
}

0 comments on commit cdda179

Please sign in to comment.