1. Go to this page and download the library: Download lagdo/symfony-facades library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lagdo / symfony-facades example snippets
namespace App\Facades;
use App\Services\MyService;
use Lagdo\Symfony\Facades\AbstractFacade;
/**
* @extends AbstractFacade<MyService>
*/
class MyFacade extends AbstractFacade
{
/**
* @inheritDoc
*/
protected static function getServiceIdentifier(): string
{
return MyService::class;
}
}
class TheService
{
public function theMethod()
{
MyFacade::myMethod();
}
}
class TheService
{
/**
* @var MyService
*/
protected $myService;
public function __construct(MyService $myService)
{
$this->myService = $myService;
}
public function theMethod()
{
$this->myService->myMethod();
}
}
namespace App\Facades;
use Lagdo\Symfony\Facades\AbstractFacade;
use Twig\Environment;
/**
* @extends AbstractFacade<Environment>
*/
class View extends AbstractFacade
{
/**
* @inheritdoc
*/
protected static function getServiceIdentifier(): string
{
return Environment::class;
}
}
use App\Facades\View;
class TheService
{
public function theMethod()
{
...
$html = View::render($template, $vars);
...
}
}
namespace App\Facades;
use App\Services\TaggedService;
use Lagdo\Symfony\Facades\AbstractFacade;
/**
* @extends AbstractFacade<TaggedService>
*/
class TaggedServiceFacade extends AbstractFacade
{
/**
* @inheritdoc
*/
protected static function getServiceIdentifier(): string
{
return TaggedService::class;
}
}
class TheService
{
public function theMethod()
{
/**
* @var MyService $service
*/
$service = MyFacade::instance();
$service->myMethod();
}
}
namespace App\Facades;
use App\Services\MyService;
use Lagdo\Symfony\Facades\AbstractFacade;
use Lagdo\Symfony\Facades\ServiceInstance;
/**
* @extends AbstractFacade<MyService>
*/
class MyFacade extends AbstractFacade
{
use ServiceInstance;
/**
* @inheritDoc
*/
protected static function getServiceIdentifier(): string
{
return MyService::class;
}
}
MyFacade::myMethod1(); // Calls the Symfony service container
MyFacade::myMethod2(); // Doesn't call the Symfony service container
MyFacade::myMethod1(); // Doesn't call the Symfony service container
use Lagdo\Symfony\Facades\Log;
Log::info($message, $vars);
use Lagdo\Symfony\Facades\View;
$html = View::render($template, $vars);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.