laravel-proxy-manager maintained by jundayw
Laravel Proxy Manager
Proxy Manager integration for Laravel — a lightweight, type-safe, inheritance-based extension that brings dynamic proxies and aspect-oriented programming (AOP) to Laravel. Define aspects once, and let proxies weave cross-cutting concerns like logging, caching, transactions, and authorization into your services — without touching business logic.
Installation
You can install the package via Composer:
composer require jundayw/laravel-proxy-manager
You can publish the config file with:
php artisan vendor:publish --provider="Jundayw\ProxyManager\ProxyManagerServiceProvider" --tag="config"
Quick Start
Just extend Jundayw\Proxy\Contracts\Proxy and add the Jundayw\Proxy\Attributes\Proxy middleware attribute.
<?php
use Jundayw\Proxy\Attributes\IgnoreProxy;
use Jundayw\Proxy\Attributes\Proxy;
use Jundayw\Proxy\Attributes\ProxyIgnore;
use Jundayw\Proxy\Contracts\Proxy as AOP;
#[Proxy([
new TraceMiddleware(),
new LoggingMiddleware(),
new TimingMiddleware(),
])]
class OrderService implements AOP
{
public function create(
string $orderNo,
int|float $amount,
): ?Order {
// Business logic
}
public function find(
int|string $id,
): ?Order {
// Business logic
}
#[IgnoreProxy]
public function healthCheck(): string
{
return 'ok';
}
#[ProxyIgnore]
public function internalCalculation(
int $amount,
): int {
return $amount * 100;
}
}
Built-in Attributes
#[Proxy]
#[Proxy] enables proxy generation and defines the middleware pipeline.
#[Proxy([
new TraceMiddleware(),
new LoggingMiddleware(),
new TimingMiddleware(),
])]
class OrderService
{
}
Middleware is executed according to the configured pipeline.
#[IgnoreProxy]
Use #[IgnoreProxy] to exclude a method from proxy interception.
#[IgnoreProxy]
public function healthCheck(): string
{
return 'ok';
}
Typical use cases include:
- Health checks
- Internal methods
- Framework callbacks
- Lightweight methods
- Performance-sensitive methods
#[ProxyIgnore]
#[ProxyIgnore] provides method-level proxy exclusion.
#[ProxyIgnore]
public function internalCalculation(
int $amount,
): int {
return $amount * 100;
}
This makes proxy behavior explicit at the method level.
Middleware
Middleware is the primary extension point of Proxy Manager.
For example:
<?php
namespace App\Proxy\Middleware;
use Jundayw\Proxy\Contracts\Middleware;
use Jundayw\Proxy\Invocation;
class TimingMiddleware implements Middleware
{
public function __invoke($request, Closure $next)
{
return $next($request);
}
}
Middleware can be used for:
- Logging
- Tracing
- Metrics
- Authorization
- Transactions
- Caching
- Idempotency
- Auditing
- Performance monitoring
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Contributors
Thanks goes to these wonderful people:
Contributions of any kind are welcome!
License
Distributed under the MIT License (MIT). Please see License File for more information.