PHP code example of sugiphp / sugi

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

    

sugiphp / sugi example snippets



$app = new \SugiPHP\Sugi\App();
$app->route("HelloWorld", "/hello", function () {
    echo "Hello World!";
});
$app->run();



use SugiPHP\Sugi\App;

// Instantiate SugiPHP Application:
$app = new App(["base_path" => dirname(__DIR__) . "/"]);

// Or use Singleton pattern:
$app = App::getInstance();


    $app->log("debug", "Debug message");
    $app->log("info", "user input was", $_POST);

    $app["logger"]->error("my error message");
    $app["logger"]->setLevel("warning");
    $app["logger"]->info("this will not be logged");



$app["request"] = new \Your\ServerRequest();




$app["uri"]->getHost();
$app["uri"]->getPath();




echo $app["uri"]->getPath(); // "/"
echo $app["uri"]->withPath("/foo/bar")->getPath(); // "/foo/bar"
echo $app["uri"]->getPath(); // "/"

// to override it:
$app["uri"] = $app["uri"]->withPath("/foo");
echo $app["uri"]->getPath(); // "/foo"




$app->cache("key", "value");
echo $app->cache("key"); // returns "value"

// to access all methods for the cache you can use:
$app["cache"]->has("key"); // returns TRUE