-
Notifications
You must be signed in to change notification settings - Fork 695
Add Symfony 6 support #2340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Symfony 6 support #2340
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dbe2ab2
Add Symfony 6 support
mbabker e8335f1
Use InputBag where able
mbabker 1f76bdf
backward compat symfony 6 type hints
goetas 70686a9
CS
goetas b894a1a
cs
goetas 36df32c
Update Controller/PreSymfony6AbstractFOSRestController.php
mbabker f4f7471
Fix the BC layer of the Route annotation for symfony 6
W0rma 238fe87
Fix return value for symfony 6 compatibility
W0rma 9937330
Remove php-cs-fixer since it is not yet compatible with symfony 6
W0rma 7f21bdb
Ignore type return deprecations
mbabker d0af174
Add no-update flag
mbabker c74bb01
Combine sections
mbabker 322efbb
Base the compat layer on whether the return type is on the controller…
mbabker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSRestBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\RestBundle\Controller; | ||
|
||
use FOS\RestBundle\View\ViewHandlerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class PostSymfony6AbstractFOSRestController extends AbstractController | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedServices(): array | ||
{ | ||
$subscribedServices = parent::getSubscribedServices(); | ||
$subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; | ||
|
||
return $subscribedServices; | ||
} | ||
} |
This file contains hidden or 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,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSRestBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\RestBundle\Controller; | ||
|
||
use FOS\RestBundle\View\ViewHandlerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class PreSymfony6AbstractFOSRestController extends AbstractController | ||
{ | ||
use ControllerTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
mbabker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public static function getSubscribedServices() | ||
{ | ||
$subscribedServices = parent::getSubscribedServices(); | ||
$subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; | ||
|
||
return $subscribedServices; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
Tests/Functional/Bundle/TestBundle/Security/ApiToken53Authenticator.php
This file contains hidden or 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,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSRestBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Security; | ||
|
||
use FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Entity\User; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
use Symfony\Component\Security\Core\Exception\BadCredentialsException; | ||
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; | ||
|
||
class ApiToken53Authenticator extends AbstractAuthenticator | ||
{ | ||
protected $headerName = 'x-foo'; | ||
protected $tokenValue = 'FOOBAR'; | ||
|
||
public function authenticate(Request $request): PassportInterface | ||
{ | ||
$credentials = $request->headers->get($this->headerName); | ||
|
||
if (!$credentials || $credentials !== $this->tokenValue) { | ||
throw new BadCredentialsException(); | ||
} | ||
|
||
$userBadge = new UserBadge($this->tokenValue, function () { | ||
$user = new User(); | ||
$user->username = 'foo'; | ||
$user->roles[] = 'ROLE_API'; | ||
|
||
return $user; | ||
}); | ||
|
||
return new SelfValidatingPassport($userBadge); | ||
} | ||
|
||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response | ||
{ | ||
return null; | ||
} | ||
|
||
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response | ||
{ | ||
return new JsonResponse(null, 401); | ||
} | ||
|
||
public function supports(Request $request): ?bool | ||
{ | ||
if (!$request->headers->has($this->headerName)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.