-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
157 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Fixtures/Integration/Symfony/config/routing-annotation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
controllers: | ||
resource: ../src/Controller/ | ||
resource: ../src/ControllerAnnotation/ | ||
type: annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...xtures/Integration/Symfony/src/ControllerAnnotation/BackedEnumValueResolverController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...tegration/Symfony/src/ControllerAnnotation/QueryBodyBackedEnumValueResolverController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |