PHP code example of meritum / virtus

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

    

meritum / virtus example snippets


namespace App\Handler;

use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

final class HomeHandler implements RequestHandlerInterface
{
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return new JsonResponse(['message' => 'Hello, world!']);
    }
}

use Meritum\Http\HttpKernelInterface;

public function register(KernelInterface $kernel): void
{
    assert($kernel instanceof HttpKernelInterface);

    $kernel->define(Handler\HomeHandler::class, fn() => new Handler\HomeHandler());

    $kernel->addRoute('GET', '/', Handler\HomeHandler::class);
}

www/index.php             Entry point
src/
  ModuleRepository.php    Register application modules
  AppModule.php           Register handlers, routes, and application config
tests/
devenv.nix                Dev environment