PHP code example of ifcanduela / kernel-middleware

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

    

ifcanduela / kernel-middleware example snippets




use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class App extends \ifcanduela\kernel\Kernel
{
    public function __construct(array $middleware)
    {
        $middleware[] = $this->run(...);

        parent::__construct($middleware)
    }

    public function run(Request $request, Closure $next): Response
    {
        return new Response("hello");
    }
}

function (Request $request, Closure $next): Response;

class ExampleMiddleware implements Middleware
{
    public function handle($request, $next)
    {
        return $next();
    }
}

new Kernel([
    InitSessionMiddleware::class,

    new InitContainerMiddleware($container)

    new class implements Middleware {
        public function handle(Request $request, Closure $next): Response
        {
            // ...
        }
    }
])

new Kernel([
    new class {
        public function __invoke($req, $next) {
            return $next();
        }
    },

    fn ($req, $next) => new JsonResponse([]),
])