承接 blast/facades 相关项目开发

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

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

blast/facades

Composer 安装命令:

composer require blast/facades

包简介

Minimize complexity and represent dependencies as facades.

README 文档

README

Latest Version on Packagist Software License Build Status Total Downloads Coverage Status

Blast facades is aiming to minimize complexity and represent dependencies as generic facades. This package is part of Blast component collection.

This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.

This package is also supporting container-interop (PSR-11) and all container packages which are using container-interop.

Install

Via Composer

$ composer require blast/facades

Usage

Initialize

First of all we need to tell FacadeFactory which container instance should be used. We could use thephpleague/container for example:

A bootstrap is looking like this:

<?php

use Blast\Facades\FacadeFactory;
use League\Container\Container;

$container = new Container();
FacadeFactory::setContainer($container);

Dealing with dependencies

We need to register a service to our container, for example with league/container.

There are several ways to now register this service with the container.

For a better transparency and design we recommend to pass an Interface or Contract FQCN as service id.

<?php

//add our service
$container->add('Acme\Service', 'Acme\Service\SomeService');

//returns an instance of Acme\Service\SomeService
$container->get('Acme\Service');

or

<?php

//add our service
$container->add('Acme\Service\SomeService');

//returns an instance of Acme\Service\SomeService
$container->get('Acme\Service\SomeService');

or

<?php

//returns an instance of Acme\Service\SomeService without registration
$container->get('Acme\Service\SomeService');

for more information please read league/container documentation

Creating and using a facade

A Facade should be an instance of AbstractFacade and should provide an accessor.

The accessor is the service identifier. It will be used to fetch the service in the container (via Interop\Container\ContainerInterface::get($accessor).

<?php

namespace Acme\Facades\Service;

use Blast\Facades\AbstractFacade;
use Acme\Service;

class Service extends AbstractFacade
{
    protected static function accessor()
    {
        return Acme\Service::class;
    }
}

We could now call serivce methods from our facade, or the service instance itself.

Calling service instance

<?php

use Acme\Facades\Service;

//is returning the service instance
$service = Service::__instance();

Calling service methods

<?php

use Acme\Facades\Service;

Service::someMethod();

or

<?php

use Acme\Facades\Service;

//is returning the service instance
$service = Service::__instance();
$service->someMethod();

or

<?php

use Acme\Facades\Service;

forward_static_call([Service::class, 'someMethod']);

or

<?php

use Acme\Facades\Service;

call_user_func(sprintf('%s::%s', Service::class, 'someMethod'));

You are also able to pass arguments. The method call itself is behaving like the call of original class.

Instance swaping

Sometimes service will be replaced by another service. As long as the service id is not changing, we don't need to modify anything in our facade.

<?php

use Acme\Facades\Service;

//add a service
$container->add('Acme\Service', 'Acme\Service\SomeService');

//is returning the service instance Acme\Service\SomeService
$service = Service::__instance();

//replace a service with another one
$container->add('Acme\Service', 'Acme\Service\AnotherService');

//is now returning the service instance Acme\Service\AnotherService
$service = Service::__instance();

Supporting projects

Projects using ContainerInterface

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email :author_email instead of using the issue tracker.

Credits

Special thanks

License

The MIT License (MIT). Please see License File for more information.

blast/facades 适用场景与选型建议

blast/facades 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 179.7k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 179.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 28
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-22