Search by

kematjaya / security-annotation-bundle

kematjaya0

Package info

github.com/kematjaya0/security-annotation-bundle

pkg:composer/kematjaya/security-annotation-bundle

Statistics

Installs: 1 430

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

7.0 2024-10-25 09:30 UTC

This package is auto-updated.

Last update: 2026-10-02 01:46:41 UTC


README

PHP >= 8.1, Symfony 6.4 dan 7.

Attribute IsGrantedCreate, IsGrantedEdit, IsGrantedView, dan IsGrantedDelete untuk controller. Masing-masing memeriksa hak akses create, update, view, delete lewat voter aplikasi (turunan Kematjaya\SecurityAnnotationBundle\Voter\BaseVoter).

Pemakaian

use Kematjaya\SecurityAnnotationBundle\Configuration\IsGrantedEdit;
use Kematjaya\SecurityAnnotationBundle\Configuration\IsGrantedDelete;

class PostController extends AbstractController
{
    // subject = nama argumen controller yang dikirim ke voter
    #[IsGrantedEdit(subject: 'post')]
    public function edit(Post $post): Response
    {
    }

    #[IsGrantedDelete(subject: 'post', message: 'tidak boleh menghapus', statusCode: 404)]
    public function delete(Post $post): Response
    {
    }
}

Attribute juga boleh dipasang di class (berlaku untuk semua action). Tanpa statusCode, akses yang ditolak melempar AccessDeniedException (403, atau diarahkan ke login bila belum login).

Pengecekan dijalankan oleh IsGrantedListener milik bundle ini dan membutuhkan symfony/security-bundle.

Pindah dari versi 1.x

Annotation docblock @IsGrantedEdit(subject="post") (lewat sensio/framework-extra-bundle) tidak lagi dibaca. Ganti dengan attribute #[IsGrantedEdit(subject: 'post')].

Test

sh ../test.sh security-annotation-bundle all        # PHP 8.1 & 8.3 + Symfony 6.4
sh ../test.sh security-annotation-bundle 8.3 7.4    # PHP 8.3 + Symfony 7.4