PHP code example of zhangshize / slim-facades

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

    

zhangshize / slim-facades example snippets


    //... Something not important ...
    use SlimFacades\Facade;
    use SlimFacades\Route;
    use SlimFacades\App;
    
    $app = new \Slim\App(/*...*/);
    // initialize the Facade class
    Facade::setFacadeApplication($app);
    
    Route::get('/', function (Request $req, Response $res) {
        $res->getBody()->write("Hello");
        return $res;
    });
    
    App::run();

    App::run();

    Container::hasService('view');

    Route::get('/', function (Request $req, Response $res) {
        $res->getBody()->write("Hello");
        return $res;
    });

    $method = Request::getMethod();

    Response::withStatus(302);

    /**
     * Get the settings value.
     * If $key = null, this function returns settings.
     * @param string|null $key
     * @return mixed
     */
    public static function get($key = null)
    {
        // ...
    }

    Settings::get()['db'];
    Settings::get('db');
    //The same result.

    /**
     * Set the settings value.
     * When $key is an array, it will be viewed to a list of keys.  <br>
     * For Example:
     * $key = ['a','b']; <br>
     * The function will set the value of $container->settions['a']['b'].
     * @param array|string $key
     * @param mixed $value
     */
    public static function set($key, $value)
    {
        // ...
    }

    $container['settings']['db']['host'] = 'localhost';
    Settings::set(['db', 'host'], 'localhost');
    //The same result.

using SlimFacades\Facade;
class CustomFacade extends Facade
{
    protected static function getFacadeAccessor()
    {
        //Change 'serviceName' to you want.
        return 'serviceName';
    }
}

using SlimFacades\Facade;
class CustomFacade extends Facade
{
    public static function self()
    {
        //Change the returned value to you want.
        return self::$app->getContainer()->get('myservice');
    }
}