承接 imanghafoori/laravel-smart-facades 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

imanghafoori/laravel-smart-facades

Composer 安装命令:

composer require imanghafoori/laravel-smart-facades

包简介

Adds some features on the top of laravel facades

README 文档

README

🍄 Laravel Smart Facades 🍄

The "Strategy pattern" in Laravel, made easy

by adding some features on top of Laravel facades.

Built with ❤️ for every smart Laravel developer

                                           Quality Score Code Quality Software License Check Imports StyleCI

🔦 Installation:

composer require imanghafoori/laravel-smart-facades

⚡️ No need to have getFacadeAccessor()

Before:

use Illuminate\Support\Facades\Facade;

class MyFacade extends Facade
{
    protected static function getFacadeAccessor() // <--- normal facade
    {
        return 'some_key'; 
    }
}

After:

use Imanghafoori\SmartFacades\Facade;

class MyFacade extends Facade
{
    //                                          <--- smart facade
}

⚡️ Setting the default driver by shouldProxyTo($class):

Instead of binding a string to a concrete class with an IOC container, you can choose the low-level implementation class like this:

public function register()    // <-- in a service provider
{             
    if ($someCondition) {
        MyFacade::shouldProxyTo( SomeDriver::class );
    } else {
        MyFacade::shouldProxyTo( SomeOtherDriver::class );
    }
}

You can proxy to any abstract string (or closure) bound on the IoC container.

Note: If you invoke it twice, it will override:

MyFacade::shouldProxyTo( DriverClass1::class );
MyFacade::shouldProxyTo( DriverClass2::class ); // <--- This wins!

⚡️ Using Non-default Driver:

If you want to change the driver at call site:

MyFacade::withDriver(nonDefaultDriver::class)::myMethod();

⚡️ Method Hooks:

You can introduce some code "Before" and "after" a method call, remotely: (like event listeners on eloquent models)

image

Here we have told the system whenever the MyFacade::findUser($id) method was called in the system, to perform a log.

⚡️ Choosing the driver, based on parameters value:

For example, let's say you want your facade to use an SMS-based driver by default, but if the text is very long (more than 200 chars) it should use an email driver.

You can do it like this:

image

🔧 Automatic method injection when calling a method through a facade.

This the adds ability to enjoy automatic method injection when calling methods on POPOs (Plain Old Php Objects) WITHOUT any performance hit when you do not need it.

🐙 Example:

class Foo { ... }

class Bar
{
    // This has dependencies: "Foo", "LoggerInterface"
    public function m1 (Foo $foo, LoggerInterface $logger, string $msg)
    {
       
    }
}

Calling Bar through a Facade:

Before:

MyFacade::m1(resolve(Foo::class), resolve(LoggerInterface::class), 'hey there !'); 

After:

 // This will work and $foo, $logger would be auto-injected for us.

MyFacade::m1('hey there !');          // normal facade

// or you may want to provide some dependencies yourself:
\Facades\Bar::m1(new Foo('hey man!'), 'hey there !');   //Now only the Logger is injected

🙋 Contributing:

If you find an issue or have a better way to do something, feel free to open an issue or a pull request.

⭐ Your Stars Make Us Do More ⭐

As always if you found this package useful and you want to encourage us to maintain and work on it. Just press the star button to declare your willingness.

More from the author:

Laravel Microscope

💎 Automatically find bugs before they bite.

Laravel Widgetize

💎 A minimal yet powerful package to give a better structure and caching opportunity for your Laravel apps.

It's not I am smarter or something, I just stay with the problems longer.

"Albert Einstein"

imanghafoori/laravel-smart-facades 适用场景与选型建议

imanghafoori/laravel-smart-facades 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 463.98k 次下载、GitHub Stars 达 137, 最近一次更新时间为 2019 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「laravel」 「laravel-package」 「laravel-facades」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 imanghafoori/laravel-smart-facades 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 imanghafoori/laravel-smart-facades 我们能提供哪些服务?
定制开发 / 二次开发

基于 imanghafoori/laravel-smart-facades 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 463.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 137
  • 点击次数: 9
  • 依赖项目数: 9
  • 推荐数: 2

GitHub 信息

  • Stars: 137
  • Watchers: 3
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-21