2017 © Pedro Peláez
 

library sugi

SugiPHP Micro Framework

image

sugiphp/sugi

SugiPHP Micro Framework

  • Tuesday, August 23, 2016
  • by tzappa
  • Repository
  • 2 Watchers
  • 2 Stars
  • 394 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Sugi

Build Status, (*1)

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., (*2)

Hello World! example

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

Installation

composer require sugiphp/sugi:dev-master

Usage

Defined paths

 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:, (*3)

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");
?>

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.), (*4)


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

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

?>

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

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"

?>

Cache

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(), (*7)

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:, (*8)

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

See config file example, (*9)

The Versions