Download the PHP package lagdo/symfony-facades without Composer

On this page you can find all versions of the php package lagdo/symfony-facades. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package symfony-facades

Build Status Scrutinizer Code Quality StyleCI codecov

Latest Stable Version Total Downloads License

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 some of them only occasionally.

Installation

Install the package with composer. For Symfony version 6. or older, install the version 2.3 of the package. For Symfony version 7., install the version 3.0.

Register the Lagdo\Symfony\Facades\FacadesBundle bundle in the config/bundles.php file.

Usage

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

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

Instead of this.

The @extends AbstractFacade<MyService> phpdoc will prevent errors during code analysis with PHPStan, and allow code completion on calls to facades in editors.

Using a service locator

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

In order to call private services with facades, a service locator with id lagdo.facades.service_locator must be declared in the config/services.yaml file. See the Symfony service locators documentation.

The private services that need to be accessed with a facade must be passed as arguments to the service locator. For each argument, the key is the service id in the facade, while the value is the service id in the container.

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

A facade can then be defined for the Twig service.

Templates can now be rendered using the facade.

The lagdo.facades.service tag

Starting from version 2.3.0, the private services that need to be accessed with a facade can be tagged with lagdo.facades.service.

These services will then be automatically passed to the service locator, together with those received as arguments.

In the following example, the Twig and App\Services\TaggedService services will be passed to the service locator.

A facade can then be defined for the service.

Getting the service instance

Starting from version 2.0.0, the instance() method returns the instance of the service.

The ServiceInstance trait

By default, each call to a facade method will also call the Symfony service container.

Starting from version 2.2.0, the service instance can be saved in the facade after the first call to the Symfony service container, using the ServiceInstance trait. The next calls with return the service instance without calling the Symfony service container.

The Symfony service container is called only once in this example code.

Provided facades

This package includes facades for some Symfony services.

Logger

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

Messages can now be logged using the facade.

View

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

Views can now be rendered using the facade.

Contribute

License

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


All versions of symfony-facades with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
psr/container Version >=2.0.0
symfony/framework-bundle Version 7.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lagdo/symfony-facades contains the following files

Loading the files please wait ....