<commit_before><?php

namespace Phapi\Middleware\Route;

use Phapi\Contract\Middleware\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
 * Class Router
 *
 * @category Phapi
 * @package  Phapi\Middleware\Route
 * @author   <NAME> <<EMAIL>>
 * @license  MIT (http://opensource.org/licenses/MIT)
 * @link     https://github.com/phapi/middleware-route
 */
class Route implements Middleware
{

    /**
     * The router
     *
     * @var Router
     */
    private $router;

    /**
     * The attribute name that should be used on the request object
     *
     * @var string
     */
    private $requestAttribName;

    /**
     * @param Router $router
     * @param string $requestAttribName The attribute name that should be used on the request object
     */
    public function __construct(Router $router, $requestAttribName = 'routeEndpoint')
    {
        // Set router
        $this->router = $router;
        // Set attribute name
        $this->requestAttribName = $requestAttribName;
    }

    /**
     * Add routes to the route table
     *
     * @param array $routes
     */
    public function addRoutes(array $routes = [])
    {
        // Add routes to the routers table
        $this->router->addRoutes($routes);
    }

    /**
     * Handle the invoke of the middleware
     *
     * @param ServerRequestInterface $request
     * @param ResponseInterface $response
     * @param callable $next
     * @return ResponseInterface
     * @throws \Phapi\Exception\NotFound
     */
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
    {
        // Match request to route, error handling is done by the router itself
        $this->router->match($request->getUri()->getPath(), $request->getMethod());

        // Get matched endpoint from router and add to request
        $request = $request->withAttribute($this->requestAttribName, $this->router->getMatchedEndpoint());

        // Get all url params from router and add as attribute to request
        $request = $request->withAttribute('routeParams', $this->router->getParams());
        
        // Get the matched route from the router and add it as an attribute to the request
        $request = $request->withAttribute('routeRoute', $this->route->getMatchedRoute());

        // Call next middleware and return any response<commit_msg>Fixed typo in variable<commit_after><?php

namespace Phapi\Middleware\Route;

use Phapi\Contract\Middleware\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
 * Class Router
 *
 * @category Phapi
 * @package  Phapi\Middleware\Route
 * @author   <NAME> <<EMAIL>>
 * @license  MIT (http://opensource.org/licenses/MIT)
 * @link     https://github.com/phapi/middleware-route
 */
class Route implements Middleware
{

    /**
     * The router
     *
     * @var Router
     */
    private $router;

    /**
     * The attribute name that should be used on the request object
     *
     * @var string
     */
    private $requestAttribName;

    /**
     * @param Router $router
     * @param string $requestAttribName The attribute name that should be used on the request object
     */
    public function __construct(Router $router, $requestAttribName = 'routeEndpoint')
    {
        // Set router
        $this->router = $router;
        // Set attribute name
        $this->requestAttribName = $requestAttribName;
    }

    /**
     * Add routes to the route table
     *
     * @param array $routes
     */
    public function addRoutes(array $routes = [])
    {
        // Add routes to the routers table
        $this->router->addRoutes($routes);
    }

    /**
     * Handle the invoke of the middleware
     *
     * @param ServerRequestInterface $request
     * @param ResponseInterface $response
     * @param callable $next
     * @return ResponseInterface
     * @throws \Phapi\Exception\NotFound
     */
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
    {
        // Match request to route, error handling is done by the router itself
        $this->router->match($request->getUri()->getPath(), $request->getMethod());

        // Get matched endpoint from router and add to request
        $request = $request->withAttribute($this->requestAttribName, $this->router->getMatchedEndpoint());

        // Get all url params from router and add as attribute to request
        $request = $request->withAttribute('routeParams', $this->router->getParams());
        
        // Get the matched route from the router and add it as an attribute to the request
        $request = $request->withAttribute('routeRoute', $this->router->getMatchedRoute());

        // Call next middleware and return any response
{'fraction_non_alphanumeric': 0.11124845488257108, 'fraction_numerical': 0.0, 'mean_word_length': 2.672465960665658, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 47, 'https://': 2, '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': '2998935', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1304, 'n_words': 392}