mrubiosan/facade 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mrubiosan/facade

最新稳定版本:2.0.1

Composer 安装命令:

composer require mrubiosan/facade

包简介

Facade pattern ready to use

README 文档

README

Facade pattern for PHP

Build Status Maintainability Test Coverage

As seen in the Laravel framework. You can call a method statically, and it will fetch an object from the container and call its method.

It's very useful for unbounded services like Logging. You can call it statically but change the underlying implementation(i.e: for testing).

Also a good compromise when refactoring code that uses static class access.

Usage example

//First declare your facade class
namespace MyDummyNameSpace;

class Foo extends \Mrubiosan\Facade\FacadeAccessor
{
    public static function getServiceName()
    {
       return 'foo'; //This is the name of the service in your container
    }
}
//Then initialize the facade system
$exampleContainer = new \ArrayObject([
    'foo' => new \DateTime(),
]);
$psrAdaptedContainer = new \Mrubiosan\Facade\ServiceLocatorAdapter\ArrayAccessAdapter($exampleContainer);
\Mrubiosan\Facade\FacadeLoader::init($psrAdaptedContainer, ['FooAlias' => 'MyDummyNameSpace\Foo']);
//Ready to use
echo \MyDummyNameSpace\Foo::getTimestamp();
echo \FooAlias::getTimestamp();

Wiring it up

Step 1

If you're using a PSR11 Container, you can skip this step. Oterwise you'll need to use an adapter:

  • Mrubiosan\Facade\ServiceLocatorAdapter\ArrayAccessAdapter: if you're using pimple you can use this.
  • Mrubiosan\Facade\ServiceLocatorAdapter\CallableAdapter: you can provide a callable parameter that will receive the service name it should retrieve.

Or straight implement Psr\Container\ContainerInterface

Step 2

Initialize the facade system

Mrubiosan\Facade\FacadeLoader::init($psrContainer);

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-08-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固