PHP code example of nsrosenqvist / soma-router
1. Go to this page and download the library: Download nsrosenqvist/soma-router 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/ */
nsrosenqvist / soma-router example snippets
namespace MyApp;
use Soma\ServiceProvider;
use Psr\Container\ContainerInterface;
use Laminas\Diactoros\Response;
class RouterProvider extends ServiceProvider
{
public function boot(ContainerInterface $c)
{
listen('router.init', function($router) use ($c) {
// map a route
$router->map('GET', '/', function (ServerRequestInterface $request) : ResponseInterface {
$response = new Response;
$response->getBody()->write('<h1>Hello, World!</h1>');
return $response;
});
// or