PHPackages                             marcbln/symfony-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. marcbln/symfony-facades

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marcbln/symfony-facades
=======================

Call Symfony services using facades.

11.4k1[1 PRs](https://github.com/marcbln/symfony-facades/pulls)PHP

Since Dec 8Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

This is a fork from lagdo/symfony-facades with support for symfony 6.

[![Build Status](https://camo.githubusercontent.com/4f1f708f7eff55b1ab1ed4127908a99b1c2adba5dae3308e81cce25935cee44c/68747470733a2f2f6170692e7472617669732d63692e636f6d2f6d617263626c6e2f73796d666f6e792d666163616465732e7376673f6272616e63683d6d61696e)](https://app.travis-ci.com/github/marcbln/symfony-facades)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5555336a6182ce1bc3fba5426f8b82d0a3037c38a097292c5979a4d881516118/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617263626c6e2f73796d666f6e792d666163616465732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/marcbln/symfony-facades/?branch=main)[![StyleCI](https://camo.githubusercontent.com/80de9e2300154d1898e4f8ac9ed8c71f4afb42b0534ed361ae4cb4978d2b053a/68747470733a2f2f7374796c6563692e696f2f7265706f732f3431383438383531332f736869656c643f6272616e63683d6d61696e)](https://styleci.io/repos/418488513)[![Coverage Status](https://camo.githubusercontent.com/2178181da457d0d41746f8ebbc5a38644f1dc6853b2f0dabdc97c7f3ccbbfe44/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d617263626c6e2f73796d666f6e792d666163616465732f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/marcbln/symfony-facades?branch=main)

[![Latest Stable Version](https://camo.githubusercontent.com/620a2ca37609008e86a644227996b5b63bc0b9e78933ebc45a63165a6a929596/68747470733a2f2f706f7365722e707567782e6f72672f6d617263626c6e2f73796d666f6e792d666163616465732f762f737461626c65)](https://packagist.org/packages/marcbln/symfony-facades)[![Total Downloads](https://camo.githubusercontent.com/a098687a18e7e278b628bf55f81402d17bb96cbf241382d936b0faccff39a20e/68747470733a2f2f706f7365722e707567782e6f72672f6d617263626c6e2f73796d666f6e792d666163616465732f646f776e6c6f616473)](https://packagist.org/packages/marcbln/symfony-facades)[![License](https://camo.githubusercontent.com/d6eb0ad71f262affb1c29e024d156abe10ae0b5231ed090ec255c47f30cff36f/68747470733a2f2f706f7365722e707567782e6f72672f6d617263626c6e2f73796d666f6e792d666163616465732f6c6963656e7365)](https://packagist.org/packages/marcbln/symfony-facades)

Facades for Symfony services
============================

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

With this package, Symfony services can be called using 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 each of them only occasionally.

Installation
------------

[](#installation)

Install the package with `composer`.

```
composer require marcbln/symfony-facades
```

If the project is not using Symfony Flex, then register the `Marcbln\Symfony\Facades\FacadesBundle` bundle in the `src/Kernel.php` file.

Usage
-----

[](#usage)

A facade inherits from the `Marcbln\Symfony\Facades\AbstractFacade` abstract class, and implements the `getServiceIdentifier()` method, which returns the id of the corresponding service.

```
namespace App\Facades;

use App\Services\MyService;
use Marcbln\Symfony\Facades\AbstractFacade;

class MyFacade extends AbstractFacade
{
    /**
     * @inheritDoc
     */
    protected static function getServiceIdentifier()
    {
        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();
    }
}
```

Using a service locator
-----------------------

[](#using-a-service-locator)

The above facade will work only for services that are declared as public.

A service locator must be declared in the `config/services.yaml` file, in order to create facades for private services. See the [Symfony service locators documentation](https://symfony.com/doc/4.4/service_container/service_subscribers_locators.html).

In the following example, the `Twig` service is passed to the service locator.

```
    marcbln.facades.service_locator:
        public: true
        class: Symfony\Component\DependencyInjection\ServiceLocator
        tags: ['container.service_locator']
        arguments:
            -
                Twig\Environment: '@twig'
```

A facade can then be defined for the `Twig` service.

```
namespace App\Facades;

use Twig\Environment;
use Marcbln\Symfony\Facades\AbstractFacade;

class View extends AbstractFacade
{
    /**
     * @inheritdoc
     */
    protected static function getServiceIdentifier()
    {
        return Environment::class;
    }
}
```

Templates can now be rendered using the facade.

```
use App\Facades\View;

class TheService
{
    public function theMethod()
    {
        ...
        $html = View::render($template, $vars);
        ...
    }
}
```

Provided facades
----------------

[](#provided-facades)

This package provides facades for some Symfony services.

#### Logger

[](#logger)

The `logger` service must be passed to the service locator in the `config/services.yaml` file.

```
    marcbln.facades.service_locator:
        public: true
        class: Symfony\Component\DependencyInjection\ServiceLocator
        tags: ['container.service_locator']
        arguments:
            -
                Psr\Log\LoggerInterface: '@logger'
```

Messages can now be logged using the facade.

```
use Marcbln\Symfony\Facades\Log;

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

#### View

[](#view)

The `twig` service must be passed to the service locator in the `config/services.yaml` file.

```
    marcbln.facades.service_locator:
        public: true
        class: Symfony\Component\DependencyInjection\ServiceLocator
        tags: ['container.service_locator']
        arguments:
            -
                Twig\Environment: '@twig'
```

Views can now be rendered using the facade.

```
use Marcbln\Symfony\Facades\View;

$html = View::render($template, $vars);
```

Contribute
----------

[](#contribute)

- Issue Tracker: github.com/marcbln/symfony-facades/issues
- Source Code: github.com/marcbln/symfony-facades

License
-------

[](#license)

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

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 92.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e5e6465bb9a303759e57229a5c1baf3ad74e9dab68bd7b2c9f831cc2fd18331?d=identicon)[mcx](/maintainers/mcx)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/marcbln-symfony-facades/health.svg)

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

###  Alternatives

[jcc/laravel-vote

The package helps you to add user based vote system to your model

13750.6k](/packages/jcc-laravel-vote)[gearsdigital/enhanced-toolbar-link-dialog

Enhanced Toolbar Link Dialog is a Kirby 3 plugin that extends the default link dialog with a search functionality. This makes it possible, to create links to \_existing\_ or \_external\_ pages.

637.1k](/packages/gearsdigital-enhanced-toolbar-link-dialog)[netgen/remote-media-bundle

Remote media field type implementation

189.4k4](/packages/netgen-remote-media-bundle)

PHPackages © 2026

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