arnaud-23/attribute-execution-bundle
Generic attribute execution system for Symfony.
composer require arnaud-23/attribute-execution-bundle
The bundle will be automatically registered in your Symfony application. No additional configuration is required to start using the attributes.
Services using the bundle's attributes are automatically configured with the attribute proxy. You don't need to add any additional tags or configuration.
# config/services.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: false
# Your services will be automatically configured when using attributes
App\Service\YourService: ~
If you're using the cache attribute, you can configure the cache strategies in your configuration:
# config/packages/attribute_execution.yaml
attribute_execution:
cache:
strategies:
array: ~ # Uses Symfony's ArrayAdapter
redis: # Uses Redis
dsn: 'redis://localhost:6379'
options:
prefix: 'app_cache_'
The security attribute requires the Symfony Security component to be installed:
composer require symfony/security-bundle
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
# Install dependencies
composer install
# Run tests
make test
# Run tests with coverage
make coverage
# Generate HTML coverage report
make coverage-html
# Run static analysis
make phpstan
We welcome contributions! Please see our Contributing Guide for details.
If you discover any security-related issues, please email arnaud.h.lefevre@gmail.com instead of using the issue tracker. See our Security Policy for more details.
See CHANGELOG.md for a list of changes.
This bundle is licensed under the MIT License. See the LICENSE file for details.
How can I help you explore Laravel packages today?