PHP code example of lagdo / facades

1. Go to this page and download the library: Download lagdo/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 / 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;
    }
}

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\ContainerWrapper;

ContainerWrapper::setContainer($container);

$container = ContainerWrapper::getContainer();

use Lagdo\Facades\Logger;

Logger::info('This is an information');

use Lagdo\Facades\ContainerWrapper;
use Lagdo\Facades\Logger;

ContainerWrapper::registerLocalServices([
    'filename' => '/path/to/logs/dir/app',
    'extension' => '.log',
]);

// Log a message in the '/path/to/logs/dir/app.log' file.
Logger::info('This is an information');