Skip to content
Rougin Gutib edited this page Dec 15, 2023 · 32 revisions

Slytherin is a simple and extensible PHP micro-framework that tries to achieve a SOLID-based design for creating your next web application. It uses Composer as the dependency package manager to add, update or even remove external packages.

// app/web/index.php

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Rougin\Slytherin\Application;
use Rougin\Slytherin\Container\Container;
use Rougin\Slytherin\Http\Response;
use Rougin\Slytherin\Http\ServerRequest;
use Rougin\Slytherin\Routing\Dispatcher;
use Rougin\Slytherin\Routing\DispatcherInterface;
use Rougin\Slytherin\Routing\Router;

require 'vendor/autoload.php';

// Define HTTP objects that is compliant to PSR-07 standards ---
$request = new ServerRequest((array) $_SERVER);

$response = new Response(http_response_code());
// -------------------------------------------------------------

// Create a new router to add an HTTP route... ---
$router = new Router;

$router->get('/', function ()
{
    return 'Hello world!';
});
// -----------------------------------------------

// ...then define it to a dispatcher ---
$dispatcher = new Dispatcher($router);
// -------------------------------------

// Add the above objects through a container ------------
$container = new Container;

$container->set(ServerRequestInterface::class, $request);

$container->set(ResponseInterface::class, $response);

$container->set(DispatcherInterface::class, $dispatcher);
// ------------------------------------------------------

// Lastly, run the application ------
(new Application($container))->run();
// ----------------------------------
$ php -S localhost:8000 -t app/web

Credits