<commit_before><?php

namespace Gini\CGI;

class Router
{
    private $baseRoute;
    private $rules = [];
    private $middlewares = [];
    private static $METHODS = ['get', 'post', 'put', 'delete', 'options'];

    public function __construct($route='')
    {
        $this->baseRoute = trim($route, '/');
    }

    public function __sleep()
    {
        return ['baseRoute', 'rules', 'middlewares'];
    }

    public function __call($method, $params)
    {
        if ($method == __FUNCTION__) {
            return;
        }

        $m = strtolower($method);
        if ($m == 'any') {
            array_unshift($params, '*');
            return call_user_func_array([$this, 'match'], $params);
        } elseif (in_array($m, self::$METHODS)) {
            array_unshift($params, $m);
            return call_user_func_array([$this, 'match'], $params);
        }
    }

    public function use($middleware)
    {
        if (is_subclass_of($middleware, '\\Gini\\CGI\\Middleware\\Prototype')) {
            $this->middlewares[] = $middleware;
        }
    }
<commit_msg>Router::use() support string name, and return $this for chained calling<commit_after><?php

namespace Gini\CGI;

class Router
{
    private $baseRoute;
    private $rules = [];
    private $middlewares = [];
    private static $METHODS = ['get', 'post', 'put', 'delete', 'options'];

    public function __construct($route='')
    {
        $this->baseRoute = trim($route, '/');
    }

    public function __sleep()
    {
        return ['baseRoute', 'rules', 'middlewares'];
    }

    public function __call($method, $params)
    {
        if ($method == __FUNCTION__) {
            return;
        }

        $m = strtolower($method);
        if ($m == 'any') {
            array_unshift($params, '*');
            return call_user_func_array([$this, 'match'], $params);
        } elseif (in_array($m, self::$METHODS)) {
            array_unshift($params, $m);
            return call_user_func_array([$this, 'match'], $params);
        }
    }

    public function use($middleware)
    {
        if (is_string($middleware)) {
            $middleware = Middleware::of($middleware);
        }

        if (is_subclass_of($middleware, '\\Gini\\CGI\\Middleware\\Prototype')) {
            $this->middlewares[] = $middleware;
        }

        return $this;
    }

{'fraction_non_alphanumeric': 0.16517285531370038, 'fraction_numerical': 0.0, 'mean_word_length': 2.269177126917713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1971288', 'n_tokens_mistral': 721, 'n_tokens_neox': 716, 'n_words': 147}