<?php

namespace App\Middleware;

use Snaju\Inception\Http\Middleware\MiddlewareInterface;
use Snaju\Inception\Http\Request\WebRequest;
use Snaju\Inception\Http\Response\ResponseHandler;

class AfterMiddleware implements MiddlewareInterface
{

    public function process(WebRequest $request, \Closure $next)
    {
        // Call the next middleware and pass the request object
        $response = $next($request);

        // YOUR CODE GOES HERE. DO DB QUERY, CHANGE RESPONSE, ETC.
        // TODO: Do some process here for global middleware (after)...

        // This will run in sequence with other middleware located in the
        // $global array in `app/middleware/Middleware.php` that has been configured
        // to run as "after" middleware, after the core of the application. So
        // even if first in the entire group, it will run after the main processing,
        // but in sequence with all other "after" middleware.

        // Return the response when finished
        return $response;
    }

}