PHP code example of brightnucleus / static-facade

1. Go to this page and download the library: Download brightnucleus/static-facade 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/ */

    

brightnucleus / static-facade example snippets


// Without a static Facade.
$userRepository = Services::get( 'UserRepository' );
$user = $userRepository->find( $userID );

// With a static Facade.
$user = UserRepository::find( $userID );

 declare(strict_types = 1);

namespace Example\Project;

use BrightNucleus\StaticFacade\StaticFacade;

class UserRepository extends StaticFacade
{
    
    protected static function getFacadeInstance()
    {
        // Return the shared instance of the object you are wrapping here. 
    }
}

 declare(strict_types = 1);

namespace Example\Project;

use BrightNucleus\StaticFacade\StaticFacadeTrait;

class UserRepository extends AbstractRepository
{
    
    use StaticFacadeTrait;

    protected static function getFacadeInstance()
    {
        // Return the shared instance of the object you are wrapping here. 
    }
}

protected static function getFacadeException(string $method, array $arguments) : Exception

public static function find(int $userID) {
    return Services::get('UserRepository')
                   ->find($userID);
}