Download the PHP package mykemeynell/laravel-decorators without Composer
On this page you can find all versions of the php package mykemeynell/laravel-decorators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mykemeynell/laravel-decorators
More information about mykemeynell/laravel-decorators
Files in mykemeynell/laravel-decorators
Package laravel-decorators
Short Description Attribute-based method decorators (Log, Cache, Retry, …) wired into the Laravel IoC container.
License MIT
Informations about the package laravel-decorators
Laravel Decorators
Python/TypeScript-style method decorators for Laravel services, powered by PHP 8 attributes.
This package provides a clean, attribute-based way to apply cross-cutting concerns (logging, caching, retries, etc.) to your Laravel service methods. It uses a lightweight proxy pattern to intercept method calls and wrap them in a decorator chain.
Requirements
- PHP:
>=8.2 - Laravel:
^11.0,^12.0, or^13.0
Installation
Quick Start
1. Add Attributes to Your Service
2. Resolve the Decorated Service
You can resolve your service through the Decorator facade to ensure it is wrapped in the proxy:
Built-in Decorators
#[Log]
Records method calls, arguments, and execution time to Laravel logs.
level: PSR-compatible log level (default:debug).logArgs: Whether to include raw arguments in the log (default:true).channel: The Laravel log channel to use (default: configlog_channel).
#[Cache]
Caches the method return value based on its identity and arguments.
ttl: Time-to-live in seconds. Use0to cache forever (default:3600).store: The cache store to use (default: configcache_store).tags: Array of cache tags for taggable stores (default:[]).prefix: Key prefix (default: configcache_prefix).
#[Retry]
Transparently retries failed method calls with configurable backoff.
times: Maximum attempts including the first call (default:3).delay: Base delay in milliseconds between retries (default:0).backoff: Multiplier for exponential backoff (default:1.0).catch: Array of exception classes to retry on (default:[], catches allThrowable).log: Whether to log retry attempts (default:true).
#[RateLimit]
Throttles method execution using Laravel's rate limiter.
maxAttempts: Max calls within the window (default:60).decaySeconds: Window duration in seconds (default:60).key: Optional fixed bucket identifier. By default, keys are unique to method + arguments.
#[Transactional]
Wraps the method execution in a database transaction.
connection: Database connection name (default: default connection).attempts: Number of times to retry the transaction on deadlock (default:1).
#[Validate]
Validates method arguments using Laravel's validator before execution.
rules: Array of validation rules. Can be keyed by parameter name or index.
#[Deprecated]
Emits a deprecation warning when the method is called.
message: Custom deprecation message. EmitsE_USER_DEPRECATEDin local/testing environments.
#[DecorateWith]
Delegates decoration behavior to an arbitrary callable. This is useful for ad-hoc decoration without creating a dedicated attribute class.
classOrFunction: A class name (must be invokable), aClass::methodstring, or a global function name.method: Optional method name if providing a class name separately.
The callable must return another callable that performs the actual wrapping:
Configuration
Publish the configuration file:
Auto-Decoration
You can configure certain classes to be automatically decorated when resolved from the Laravel container:
Creating Custom Decorators
Implement the MethodDecorator interface:
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-decorators with dependencies
illuminate/cache Version ^11.0|^12.0|^13.0
illuminate/container Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/log Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0