master

laravel/framework

Last updated at: 29/12/2023 09:24

UriValidator.php

TLDR

This file contains the UriValidator class, which implements the ValidatorInterface interface. It provides a method matches to validate a given rule against a route and request.

Classes

UriValidator

The UriValidator class implements the ValidatorInterface interface. It provides a method matches that takes a Route object and a Request object as parameters. The matches method validates a given rule against the provided route and request by comparing the request's path against the route's compiled regex pattern.

<?php

namespace Illuminate\Routing\Matching;

use Illuminate\Http\Request;
use Illuminate\Routing\Route;

class UriValidator implements ValidatorInterface
{
    /**
     * Validate a given rule against a route and request.
     *
     * @param  \Illuminate\Routing\Route  $route
     * @param  \Illuminate\Http\Request  $request
     * @return bool
     */
    public function matches(Route $route, Request $request)
    {
        $path = rtrim($request->getPathInfo(), '/') ?: '/';

        return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
    }
}