PHPackages                             lagdo/yii-facades - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. lagdo/yii-facades

ActiveLibrary[Framework](/categories/framework)

lagdo/yii-facades
=================

Call Yii services using facades.

v1.0.0(1y ago)08BSD-3-ClausePHP

Since Mar 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/lagdo/yii-facades)[ Packagist](https://packagist.org/packages/lagdo/yii-facades)[ Docs](https://github.com/lagdo/yii-facades)[ RSS](/packages/lagdo-yii-facades/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/c3ca0bba39d4c95839d8afd3eb06477e030b260c6be2b80cc723fa0d18146707/68747470733a2f2f706f7365722e707567782e6f72672f6c6167646f2f7969692d666163616465732f762f737461626c65)](https://packagist.org/packages/lagdo/yii-facades)[![Total Downloads](https://camo.githubusercontent.com/6950fbf0754dcfb725b229b264892ff5c733a99a274af7e51d2ab619344829d4/68747470733a2f2f706f7365722e707567782e6f72672f6c6167646f2f7969692d666163616465732f646f776e6c6f616473)](https://packagist.org/packages/lagdo/yii-facades)[![License](https://camo.githubusercontent.com/69b97eca241bd704f7e5f439e4399d8fc85d325533a05dc5c51c5f389b45c535/68747470733a2f2f706f7365722e707567782e6f72672f6c6167646f2f7969692d666163616465732f6c6963656e7365)](https://packagist.org/packages/lagdo/yii-facades)

Facades for Yii services
========================

[](#facades-for-yii-services)

With this package, Yii services can be called using service facades, with static method syntax.

It is a simpler alternative to passing services as parameters in the constructors of other classes, or using lazy services. It will be especially interesting in the case when a class depends on many services, but calls some of them only occasionally.

### Facades definition

[](#facades-definition)

The base classes for service facade definitions are provided by the [lagdo/facades](https://github.com/lagdo/facades) package.

A service facade based on this package can be use without any change with other frameworks, if a package for this framework is available, or a `PSR-11` container can be provided.

The following packages are also available:

- Symfony:
- Laravel (yes):
- CakePHP:

### Installation

[](#installation)

Install the package with `composer`.

```
composer require lagdo/yii-facades
```

Register the `Lagdo\Yii\Facades\FacadesFilter` filter ([read the doc](https://www.yiiframework.com/doc/guide/2.0/en/structure-filters)) with the application or controllers or modules, depending on where the service facades will be used.

### Usage

[](#usage)

A service facade inherits from the `Lagdo\Facades\AbstractFacade` abstract class, and implements the `getServiceIdentifier()` method, which must return the id of the corresponding service in the service container.

```
namespace App\Facades;

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

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

The methods of the `App\Services\MyService` service can now be called using the `App\Facades\MyFacade` facade, like this.

```
class TheService
{
    public function theMethod()
    {
        MyFacade::myMethod();
    }
}
```

Instead of this.

```
class TheService
{
    /**
     * @var MyService
     */
    protected $myService;

    public function __construct(MyService $myService)
    {
        $this->myService = $myService;
    }

    public function theMethod()
    {
        $this->myService->myMethod();
    }
}
```

The `@extends AbstractFacade` phpdoc will prevent errors during code analysis with [PHPStan](https://phpstan.org/), and allow code completion on calls to service facades in editors.

### Getting the service instance

[](#getting-the-service-instance)

The `instance()` method of a service facade returns the instance of the linked service.

```
class TheService
{
    public function theMethod()
    {
        $service = MyFacade::instance();
        $service->myMethod();
    }
}
```

### The `Lagdo\Facades\ServiceInstance` trait

[](#the-lagdofacadesserviceinstance-trait)

By default, each call to a service facade method will also call the service container. The service instance can be saved in the facade after the first call to the service container, using the `Lagdo\Facades\ServiceInstance` trait. The next calls with return the service instance without calling the service container.

```
namespace App\Facades;

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

/**
 * @extends AbstractFacade
 */
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 is called only once in this example code.

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

### Provided facades

[](#provided-facades)

Some service facades are included by default in this package.

#### Logger

[](#logger)

This facade requires that the `Psr\Log\LoggerInterface` id is defined and bound to the logger in the service container.

```
use Lagdo\Facades\Logger;

Logger::info($message, $vars);
```

Contribute
----------

[](#contribute)

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

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance49

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

403d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebb668d7515d81741c86e42cf3194f5623636fbb15dd5412e26ea8320865d229?d=identicon)[lagdo](/maintainers/lagdo)

---

Top Contributors

[![feuzeu](https://avatars.githubusercontent.com/u/15174329?v=4)](https://github.com/feuzeu "feuzeu (3 commits)")

---

Tags

phpframeworkyiifacadesservices

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lagdo-yii-facades/health.svg)

```
[![Health](https://phpackages.com/badges/lagdo-yii-facades/health.svg)](https://phpackages.com/packages/lagdo-yii-facades)
```

###  Alternatives

[lagdo/symfony-facades

Call Symfony services using facades.

1868.7k](/packages/lagdo-symfony-facades)[dragon-code/support

Support package is a collection of helpers and tools for any project.

238.7M100](/packages/dragon-code-support)[luyadev/luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.

8086.9k2](/packages/luyadev-luya)[phpmv/php-mv-ui

A JQuery and UI library for php and php MVC frameworks

3319.7k2](/packages/phpmv-php-mv-ui)[samdark/yii2-minimal

Yii 2 minimal Application Template

1383.3k](/packages/samdark-yii2-minimal)[iiifx-production/yii2-autocomplete-helper

Yii2 Autocomplete Helper

4226.9k2](/packages/iiifx-production-yii2-autocomplete-helper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
