0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「Voterは書きすぎ?」Symfony 7.3で変わるアクセス制御の新常識

0
Posted at

この記事はZennに投稿した記事の要約です。詳細は以下のリンクからご覧ください。

詳細記事: 「Voterは書きすぎ?」Symfony 7.3で変わるアクセス制御の新常識


結論:1箇所だけのアクセス制御にVoterは重すぎた

「この商品の編集権限チェック、Voterファイル作るほどじゃないんだよな...」

Symfony開発者なら一度は思ったことがあるはずです。

Symfony 7.3で、この悩みが解消されます。#[IsGranted] 属性にクロージャを直接書けるようになりました。

// Before: Voter + Controller で2ファイル必要
// After: Controllerに数行追加するだけ
#[IsGranted(static function (IsGrantedContext $context, mixed $subject): bool {
    return $subject->getCreator() === $context->user;
}, subject: 'product')]
public function edit(Product $product): Response { }

「で、いつ使うの?」という方のために、EC-CUBEでの実践例を紹介します。

前提条件

  • PHP 8.5以上(属性内でClosureが使えるバージョン)
  • Symfony 7.3以上
  • EC-CUBE 4.3以上(将来的にSymfony 7.x対応時に利用可能)

続きはZennで

この記事では概要のみを紹介しました。詳細な解説やコード例は、Zennの記事をご覧ください。

「Voterは書きすぎ?」Symfony 7.3で変わるアクセス制御の新常識


EC-CUBEのカスタマイズや開発のご相談は、お気軽にお問い合わせください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?