master

laravel/framework

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

SchemeValidator.php

TLDR

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

Classes

SchemeValidator

The SchemeValidator class implements the ValidatorInterface and provides the matches method. This method takes a Route object and a Request object as parameters and returns a boolean value indicating whether the given rule matches the route and request. The method checks if the route is set to be HTTP-only, and if so, it checks if the request is not secure. If the route is set to be secure, it checks if the request is secure. Returns true if the rule matches, and false otherwise.

<?php

namespace Illuminate\Routing\Matching;

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

class SchemeValidator 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)
    {
        if ($route->httpOnly()) {
            return ! $request->secure();
        } elseif ($route->secure()) {
            return $request->secure();
        }

        return true;
    }
}