SugiPHP Micro Framework

v0.0.1 2014-09-12 13:12 UTC

This package is not auto-updated.

Last update: 2021-10-10 16:38:36 UTC


Build Status

Sugi is a micro framework using SugiPHP Components as well as some other components. It works as a Dependency Injection Container and it is very flexible.

Hello World! example

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


composer require sugiphp/sugi:dev-master


Defined paths


use SugiPHP\Sugi\App;

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

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

PSR-3 Logger

The App is using SugiPHP\Logger by default, which is PSR-3 compliant. To use logger you can use one lazy method: log(string $level, string $message, array $context = []), or use the instance app["logger"] to access methods given by the specification:

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

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

PSR-7 Requests

The App is PSR-7 compatible and is using zendframework/zend-diactoros internally. You can plug any other PSR-7 compatible library for ServerRequest (instance of \Psr\Http\Message\ServerRequestInterface.)


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


The URI is an instance of \Psr\Http\Message\UriInterface, so you can use:




and all other PSR-7 UriInterface methods. Note that manipulating an $app["uri"] will not change it's value:


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"



The default cache is a virtual cache that is only available till the end of the script. All values can be set and get with one method cache()


$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


By default Sugi is using SugiPHP Cache. To set up Sugi to use memcached server you can use a configuration file /path/to/config/cache.php:

return [
    "store" => "memcached",
    "host" => "",
    "port" => 11211, 
    "prefix" => "myprefix",

See config file example