fer-projekt/laravel-proxy
Composer 安装命令:
composer require fer-projekt/laravel-proxy
包简介
Laravel proxy trait to resolve the currently bound values of the given contract.
README 文档
README
Laravel proxy trait to resolve the currently bound values of the given contract.
Installation
You can install the package via composer:
composer require fer-projekt/laravel-proxy
Usage
Easily swap container bindings without touching anything else in the codebase.
namespace App\Models; use Ecommerce\Models\Product as BaseProduct; class Product extends BaseProduct { // }
After you created your customizable model, you can swap the container binding for the product contract. You might do that in one of your service provider's register method:
use App\Models\Product; use Ecommerce\Contracts\Product as Contract; public function register() { $this->app->bind(Contract::class, Product::class); }
Note, you should extend the base model then bind it to the interface.
Proxies
Proxies are representing the classes that are currently bound to the container. You usually won't use these a lot, but in some cases – like when you develop a package or extension – proxies can be convenient.
use Ecommerce\Models\Product; // Available proxy methods Product::proxy(); Product::getProxiedClass(); Product::getProxiedContract(); // Proxied calls to the bound instance Product::proxy()->newQuery()->where(...); Product::proxy()->variation(...); // Dynamic usage of bound classes public function product() { $this->belongsTo(Product::getProxiedClass()); }
Laravel Proxy provides the InteractsWithProxy trait, that makes the desired class proxyable. The trait comes with an abstract methods to be able to resolve the proxies class from the container automatically:
namespace App\Models; use App\Contracts\Models\Addon as Contract; use FerProjekt\LaravelProxy\InteractsWithProxy; use Illuminate\Databse\Eloquent\Model; class Addon extends Model implements Contract { use InteractsWithProxy; /** * Get the proxied interface. * * @return string */ public static function getProxiedInterface(): string { return Contract::class; } }
Also, we need to bind the contract to the container in a service provider:
public function register(): void { $this->app->bind(\App\Contracts\Models\Addon::class, \App\Models\Addon::class); }
From this point, our Addon model is proxyable, which means if we swap the binding in the container, the proxied class will be the currently bound value and not the original one. This adds more flexibility when extending our application or using packages.
// Use the Addon proxy Addon::proxy()->newQuery();
Development
Clone the package from the github:
git clone https://github.com/fer-projekt/laravel-proxy.git
cd laravel-proxy
Starting & stopping docker
docker-compose up -d
docker-compose down
Install dependencies via composer and testing:
docker-compose exec app bash
composer update
phpunit
Credits
License
The MIT License (MIT). Please see License File for more information.
fer-projekt/laravel-proxy 适用场景与选型建议
fer-projekt/laravel-proxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.09k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「proxy」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fer-projekt/laravel-proxy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fer-projekt/laravel-proxy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fer-projekt/laravel-proxy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lazy loading for middleware and request handlers
Get working public proxy list for free by PubProxy (No API key required).
Alfabank REST API integration
Standalone proxy server in PHP sockets, I am using Guzzle to route the requests. Idea was if I can make HTTP Proxy Server in php to get more control over proxy and custom logic. Currently it only supports http requests you can choose port of your own choice plus if you want to make it public or priv
A ServiceProvider for setting trusted proxies in Laravel applications
Load files from a directory like vendor (Composer) that may be inaccessible by the browser
统计信息
- 总下载量: 2.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-23