Support Facades for Symfony service.
thanks to:
- Service Locator - for making all the referenced facade service lazy-loaded.
- Service Autoconfiguration - for making all classes that extend
Indragunawan\FacadeBundle\AbstractFacade
class automatically tagged as facade.
If your project already uses Symfony Flex, execute this command to download, register and configure the bundle automatically:
composer require indragunawan/facade-bundle
If you install without using Symfony Flex, first add the bundle by using composer then enable the bundle by adding new Indragunawan\FacadeBundle\IndragunawanFacadeBundle()
to the list of registered bundles in the app/AppKernel.php file of your project
To create a facade create a class that extends base Indragunawan\FacadeBundle\AbstractFacade
class and implement the getFacadeAccessor
method that returns the service id
, support private and public service.
<?php
namespace App\Facades;
use Indragunawan\FacadeBundle\AbstractFacade;
class Foo extends AbstractFacade
{
protected static function getFacadeAccessor()
{
return 'App\Service\Foo'; // service id - supports private and public service.
}
}
Now the facade now ready. Simply import the facade namespace. When you call any static method on the Foo
facade, then it will resolve the service that you define in getFacadeAccessor
method and call the requested method from the service.
This bundle is under the MIT license. See the complete license