Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Add support for closures in theIsGranted attribute#20669

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletionssecurity/expressions.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,6 +201,41 @@
``args``
An array of controller arguments that are passed to the controller.

Additionally to expressions, the ``#[IsGranted]`` attribute also accepts
closures that return a boolean value. The subject can also be a closure that
returns an array of values that will be injected into the closure::

// src/Controller/MyController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Security\Http\Attribute\IsGrantedContext;

Check failure on line 214 in security/expressions.rst

View workflow job for this annotation

GitHub Actions/ Code Blocks

[Missing class] Class, interface or trait with name "Symfony\Component\Security\Http\Attribute\IsGrantedContext" does not exist

class MyController extends AbstractController
{
#[IsGranted(static function (
IsGrantedContext $context,
mixed $subject,
) {
return $context->user === $subject['post']->getAuthor();
}, subject: static function (array $args) {
return [
'post' => $args['post'],
];
})]
public function index($post): Response
{
// ...
}
}

.. versionadded:: 7.3

The support for closures in the ``#[IsGranted]`` attribute was introduced
in Symfony 7.3 and requires PHP 8.5.

Learn more
----------

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp