Download the PHP package flawlol/facade without Composer
On this page you can find all versions of the php package flawlol/facade. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package facade
Symfony - Facade
Author
- name: Norbert Kecső
- email: [email protected]
Overview
This project provides a facade implementation for Symfony applications. The facade pattern is used to provide a simplified interface to a complex subsystem. In this case, the facade interacts with a container to manage dependencies.
Installation
To install the package, use Composer:
Usage
Defining a Facade
To define a facade, create a class that extends the Facade
abstract class and implements the getFacadeAccessor
method. This method should return the name of the service in the container that the facade will interact with.
Using the Facade
Once the facade is defined, you can use it to call methods on the underlying service.
Setting the Container
The container is automatically set during the bundle boot process. Ensure that your bundle extends FacadeBundle
.
Exceptions
The package defines the following exceptions:
ContainerIsAlreadySetException
: Thrown when attempting to set the container more than once.ContainerIsNotSetException
: Thrown when attempting to use the facade without setting the container.
IDE Helper
The flawlol/facade-ide-helper
package provides a command to generate IDE helper files for facades in Symfony.
Its recommended to use this package to improve IDE autocompletion and static analysis.
Its also recommended to use the flawlol/facade-ide-helper
package as a dev dependency.
The _ide-helper.php
file provides helper classes to improve IDE autocompletion and static analysis. These helpers act as proxies to the actual service methods,
making it easier to work with facades in your IDE.
To generate the facade helpers, run the following command:
Example
The following example demonstrates the helper class generated for a facade named Arr
:
- Namespace:
App\Facade
- Class:
Arr
- Method:
get(array $array, string $keyPath, mixed $defaultValue = null)
The Arr
class provides a static method get
to retrieve values from an array using a key path.
This method acts as a proxy to the get
method of the ArrayHelper
service, allowing you to use the facade for cleaner and more readable code.
Real World Example
If you you have a service like this:
You can use the facade like this, and the IDE will provide autocompletion and type hints:
Inside the Facade Class
Make sure the Service is register in getFacadeAccessor
method in the Facade class.
License
This project is open-source software licensed under the MIT license.