lagdo/facades 问题修复 & 功能扩展

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

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

lagdo/facades

最新稳定版本:v1.1.0

Composer 安装命令:

composer require lagdo/facades

包简介

Base classes to implement service facades.

README 文档

README

Build Status Scrutinizer Code Quality StyleCI codecov

Latest Stable Version Total Downloads License

Base classes for service facades

This package provides base classes for service facades implementations.

The goal of the separation between this package and the framework related ones is to make the facades portable across different frameworks. A service facade can be use without any change with various frameworks, provided that a package for this framework is available, or a PSR-11 container can be provided.

The following packages are currently available:

Facades definition

The Lagdo\Facades\AbstractFacade abstract class is the base class for user defined service facades.

namespace App\Facades;

use App\Services\MyService;
use Lagdo\Facades\AbstractFacade;

/**
 * @extends AbstractFacade<MyService>
 */
class MyFacade extends AbstractFacade
{
    /**
     * @inheritDoc
     */
    protected static function getServiceIdentifier(): string
    {
        return MyService::class;
    }
}

If for any reason a service doesn't need to be fetched from the container at each call, it can be saved in its facade class by using the Lagdo\Facades\ServiceInstance trait.

namespace App\Facades;

use App\Services\MyService;
use Lagdo\Facades\AbstractFacade;
use Lagdo\Facades\ServiceInstance;

/**
 * @extends AbstractFacade<MyService>
 */
class MyFacade extends AbstractFacade
{
    use ServiceInstance;

    /**
     * @inheritDoc
     */
    protected static function getServiceIdentifier(): string
    {
        return MyService::class;
    }
}

Important

The Lagdo\Facades\ServiceInstance trait must be used in each service facade class, and not in a parent class. The same instance will be shared by all the classes inheriting the same base class using the trait, and the service facades will ot work as expected.

The service container will be called only once in the above example.

    MyFacade::myMethod1(); // Calls the service container
    MyFacade::myMethod2(); // Doesn't call the service container
    MyFacade::myMethod1(); // Doesn't call the service container

Container setup

The Lagdo\Facades\ContainerWrapper class gives access to the underlying container.

It needs to be provided with a PSR-11 container, which will be done by the framework specific packages, but can also be done by the developer in case a package is not available.

use Lagdo\Facades\ContainerWrapper;

ContainerWrapper::setContainer($container);

Contribute

  • Issue Tracker: github.com/lagdo/facades/issues
  • Source Code: github.com/lagdo/facades

License

The package is licensed under the 3-Clause BSD license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-03-30