1. Go to this page and download the library: Download lagdo/laravel-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 / laravel-facades example snippets
namespace App\Facades;
use App\Services\MyService;
use Lagdo\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();
}
}
class TheService
{
public function theMethod()
{
$service = MyFacade::instance();
$service->myMethod();
}
}
namespace App\Facades;
use App\Services\MyService;
use Lagdo\Facades\AbstractFacade;
use Lagdo\Facades\ServiceInstance;
/**
* @extends AbstractFacade<MyService>
*/
class MyFacade extends AbstractFacade
{
use ServiceInstance;
/**
* @inheritDoc
*/
protected static function getServiceIdentifier(): string
{
return MyService::class;
}
}
MyFacade::myMethod1(); // Calls the service container
MyFacade::myMethod2(); // Doesn't call the service container
MyFacade::myMethod1(); // Doesn't call the service container
use Lagdo\Facades\Logger;
Logger::info($message, $vars);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.