PHPackages                             lagdo/cake-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/cake-facades

ActiveLibrary[Framework](/categories/framework)

lagdo/cake-facades
==================

Call CakePHP services using facades.

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

Since Mar 31Pushed 1y ago1 watchersCompare

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

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

[![Latest Stable Version](https://camo.githubusercontent.com/1c58da2b90526f8856fb1f39f0e9f1a4960c41b74c91e26e7ccd11b0a566f2a2/68747470733a2f2f706f7365722e707567782e6f72672f6c6167646f2f63616b652d666163616465732f762f737461626c65)](https://packagist.org/packages/lagdo/cake-facades)[![Total Downloads](https://camo.githubusercontent.com/4fef7450ae93a886b5d6b5955e5fda89e4f77a98849ce736726576b6d74c5bae/68747470733a2f2f706f7365722e707567782e6f72672f6c6167646f2f63616b652d666163616465732f646f776e6c6f616473)](https://packagist.org/packages/lagdo/cake-facades)[![License](https://camo.githubusercontent.com/4b4202c458618bc2d112f477821c353d2d5de1aae93c8dbe7a10f0d5d72c7379/68747470733a2f2f706f7365722e707567782e6f72672f6c6167646f2f63616b652d666163616465732f6c6963656e7365)](https://packagist.org/packages/lagdo/cake-facades)

Facades for CakePHP services
============================

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

With this package, CakePHP 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/cake-facades
```

Load the `Lagdo\Cake\Facades\FacadesPlugin` plugin in the `src/Application.php` file.

```
    /**
     * Load all the application configuration and bootstrap logic.
     *
     * @return void
     */
    public function bootstrap(): void
    {
        ...

        // Load more plugins here
        $this->addPlugin(\Lagdo\Cake\Facades\FacadesPlugin::class);
    }
```

### 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/cake-facades/issues
- Source Code: github.com/lagdo/cake-facades

License
-------

[](#license)

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

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance46

Moderate activity, may be stable

Popularity1

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

404d 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

phpframeworkcakephpfacadesservices

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[lagdo/symfony-facades

Call Symfony services using facades.

1868.7k](/packages/lagdo-symfony-facades)[cakedc/cakephp-phppm

PHP PM bridge for CakePHP

221.7k](/packages/cakedc-cakephp-phppm)

PHPackages © 2026

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