PHP code example of lastguest / mu

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

    

lastguest / mu example snippets


class µ{static function __callStatic($n,$a){static$r;$n==@_?($_=@$r[getenv(REQUEST_METHOD).getenv(REQUEST_URI)])&&$_():$r[$n.$a[0]]=$a[1];}}

µ::GET('/',function(){
    echo 'What is your name?';
    echo '<form method=post><input type=text name=username><input type=submit></form>';
});

µ::POST('/',function(){
    echo 'Hello ',$_POST['username'],', how are you?';
});

µ::_();


class µ {
    public static function __callStatic($functionName,$functionParameters){
        static $callbackMap;
        
        // Check if we must resolve the request
        if($functionName == '_'){
        
            // Compose the method+uri key and
            // invoke the callback (silence failures)
        
            ($callback = @$callbackMap[getenv(REQUEST_METHOD).getenv(REQUEST_URI)]) && $callback();
        
        } else {
        
            // Add the route handler to the callbackMap
            // $functionName is the Request HTTP Method
            // $functionParameters[0] is the route
            // $functionParameters[1] is the callback
        
            $callbackMap[$functionName.$functionParameters[0]] = $functionParameters[1];
        }
    }
}