arnaud-23 / attribute-execution-bundle
Generic attribute-based execution pipeline for Symfony services.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.2
- symfony/cache: ^6.0 || ^7.0
- symfony/dependency-injection: ^6.0 || ^7.0
- symfony/http-kernel: ^6.0 || ^7.0
Requires (Dev)
- doctrine/orm: ~2.5 || ^3.0
- ergebnis/phpstan-rules: ^1.0
- korbeil/phpstan-generic-rules: ^1.0
- phpstan/phpstan: ^1.9
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.4
- phpstan/phpstan-webmozart-assert: ^1.2
- phpunit/phpunit: ^10.5
- symfony/cache: ^6.0
- symfony/config: ^6.0
- symfony/dependency-injection: ^6.0
- symfony/event-dispatcher: ^6.0
- symfony/http-foundation: ^6.0
- symfony/http-kernel: ^6.0
- symfony/lock: ^6.0
- symfony/messenger: ^6.0
- symfony/security-bundle: ^6.0
- symfony/serializer: ^6.0
- symfony/uid: ^6.0
- symplify/easy-coding-standard: ^11.2
- thecodingmachine/phpstan-strict-rules: ^1.0
README
Generic attribute execution system for Symfony.
Features
- Attribute-based middleware pipeline
- Built-in middleware for:
- Security (role-based access control)
- Cache (with configurable strategies)
- Transaction management
- Extensible architecture for custom middleware
- High test coverage
- Static analysis with PHPStan level 8
- PSR-12 compliant code style
Installation
composer require arnaud-23/attribute-execution-bundle
Setup
The bundle will be automatically registered in your Symfony application. No additional configuration is required to start using the attributes.
Service Configuration
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: ~
Cache Configuration
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_'
Security Configuration
The security attribute requires the Symfony Security component to be installed:
composer require symfony/security-bundle
Usage
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 } }
Available Attributes
Security
#[Security('ROLE_ADMIN')] // Method or class level
Cache
#[Cache] // Uses default strategy (array) with 300s TTL #[Cache(strategy: 'custom')] // Uses custom strategy #[Cache(ttl: 3600)] // Custom TTL in seconds
Transaction
#[Transactional] // Uses default connection #[Transactional('custom')] // Uses custom connection
Development
# 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
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Security
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.
Changelog
See CHANGELOG.md for a list of changes.
License
This bundle is licensed under the MIT License. See the LICENSE file for details.
Credits
- Arnaud Lefevre - Creator and maintainer