PHP code example of arnaud-23 / attribute-execution-bundle

1. Go to this page and download the library: Download arnaud-23/attribute-execution-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arnaud-23 / attribute-execution-bundle example snippets


use Arnaud23\AttributeExecutionBundle\Attribute\Security;
use Arnaud23\AttributeExecutionBundle\Attribute\Cache;
use Arnaud23\AttributeExecutionBundle\Attribute\Transactional;

class YourService
{
    #[Security('ROLE_ADMIN')]
    #[Cache(strategy: 'redis', ttl: 3600)]
    #[Transactional('default')]
    public function yourMethod(): mixed
    {
        // Your code here
    }
}

#[Security('ROLE_ADMIN')]  // Method or class level

#[Cache]                    // Uses default strategy (array) with 300s TTL
#[Cache(strategy: 'custom')] // Uses custom strategy
#[Cache(ttl: 3600)]         // Custom TTL in seconds

#[Transactional]            // Uses default connection
#[Transactional('custom')]  // Uses custom connection