<commit_before><?php
/**
 * @license MIT
 * @copyright Copyright (c) 2017
 * @author: bugbear
 * @date: 2017/12/22
 * @time: 下午12:31
 */
define('ROOT', dirname(dirname(__FILE__)));

require ROOT . '/vendor/autoload.php';

use Courser\App;
use Hayrick\Http\Response;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Message\RequestInterface;
use DI\Container;


$app = new App();


class Test implements MiddlewareInterface
{
    public function __construct()
    {
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response =  $handler->handle($request);

        return $response;
    }
}

$app->add(new Test());

$app->get('/', function ($request, RequestHandlerInterface$next) {
    $response = $next->handle($request);
    return $response->withStatus(400)->write('test1');
});

$app->get('/', function ($request, $next) {
    $response = new Response();
    throw new Exception('just test error');
    return $response->withStatus(400)->write('test1');
});

$app->get('/test/:id', function ($request, $next) {
    $id = $request->getParam('id');
    $response = new Response();
    return $response->json(['id' => $id]);
});
$app->setReporter(function(RequestInterface $request, Throwable $err) {
//    var_dump($request, $err->getMessage());
    $response = new Response();
    $response = $response->json([
        'error' => $err->getMessage(),
    ])->withStatus(500);
//    var_dump($response->getHeaders());

    return $response;
});

//echo "<pre>";
$app->run($_SERVER['REQUEST_URI']);

<commit_msg>grammar fix<commit_after><?php
/**
 * @license MIT
 * @copyright Copyright (c) 2017
 * @author: bugbear
 * @date: 2017/12/22
 * @time: 下午12:31
 */
define('ROOT', dirname(dirname(__FILE__)));

require ROOT . '/vendor/autoload.php';

use Courser\App;
use Hayrick\Http\Response;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Message\RequestInterface;
use DI\Container;


$app = new App();


class Test implements MiddlewareInterface
{
    public function __construct()
    {
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response =  $handler->handle($request);

        return $response;
    }
}

$app->add(new Test());

$app->get('/', function ($request, RequestHandlerInterface $next) {
    $response = $next->handle($request);
    return $response->withStatus(400)->write('test1');
});

$app->get('/', function ($request, $next) {
    $response = new Response();
    throw new Exception('just test error');
    return $response->withStatus(400)->write('test1');
});

$app->get('/test/:id', function ($request, $next) {
    $id = $request->getParam('id');
    $response = new Response();
    return $response->json(['id' => $id]);
});
$app->setReporter(function(RequestInterface $request, Throwable $err) {
//    var_dump($request, $err->getMessage());
    $response = new Response();
    $response = $response->json([
        'error' => $err->getMessage(),
    ])->withStatus(500);
//    var_dump($response->getHeaders());

    return $response;
});

//echo "<pre>";
$app->run($_SERVER['REQUEST_URI']);


{'fraction_non_alphanumeric': 0.18354978354978355, 'fraction_numerical': 0.015584415584415584, 'mean_word_length': 4.307810107197549, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7174462', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1069, 'n_words': 224}