ExpressionRequestMatcher

class ExpressionRequestMatcher extends RequestMatcher

ExpressionRequestMatcher uses an expression to match a Request.

Methods

public __construct(string $path = null, string $host = null, string|string[]|null $methods = null, string|string[]|null $ips = null, array $attributes = array(), string|string[]|null $schemes = null) No description from RequestMatcher
public matchScheme(string|string[]|null $scheme) Adds a check for the HTTP scheme. from RequestMatcher
public matchHost(string|null $regexp) Adds a check for the URL host name. from RequestMatcher
public matchPath(string|null $regexp) Adds a check for the URL path info. from RequestMatcher
public matchIp(string $ip) Adds a check for the client IP. from RequestMatcher
public matchIps(string|string[]|null $ips) Adds a check for the client IP. from RequestMatcher
public matchMethod(string|string[]|null $method) Adds a check for the HTTP method. from RequestMatcher
public matchAttribute(string $key, string $regexp) Adds a check for request attribute. from RequestMatcher
public bool matches(Request $request) Decides whether the rule(s) implemented by the strategy matches the supplied request.
public setExpression(ExpressionLanguage $language, $expression) No description

Details

in RequestMatcher at line 59

__construct()

public __construct(string $path = null, string $host = null, string|string[]|null $methods = null, string|string[]|null $ips = null, array $attributes = array(), string|string[]|null $schemes = null)

Parameters

string $path
string $host
string|string[]|null $methods
string|string[]|null $ips
array $attributes
string|string[]|null $schemes
in RequestMatcher at line 77

matchScheme()

public matchScheme(string|string[]|null $scheme)

Adds a check for the HTTP scheme.

Parameters

string|string[]|null $scheme An HTTP scheme or an array of HTTP schemes
in RequestMatcher at line 87

matchHost()

public matchHost(string|null $regexp)

Adds a check for the URL host name.

Parameters

string|null $regexp A Regexp
in RequestMatcher at line 97

matchPath()

public matchPath(string|null $regexp)

Adds a check for the URL path info.

Parameters

string|null $regexp A Regexp
in RequestMatcher at line 107

matchIp()

public matchIp(string $ip)

Adds a check for the client IP.

Parameters

string $ip A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
in RequestMatcher at line 117

matchIps()

public matchIps(string|string[]|null $ips)

Adds a check for the client IP.

Parameters

string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
in RequestMatcher at line 127

matchMethod()

public matchMethod(string|string[]|null $method)

Adds a check for the HTTP method.

Parameters

string|string[]|null $method An HTTP method or an array of HTTP methods
in RequestMatcher at line 138

matchAttribute()

public matchAttribute(string $key, string $regexp)

Adds a check for request attribute.

Parameters

string $key The request attribute name
string $regexp A Regexp
at line 32

matches()

public bool matches(Request $request)

Decides whether the rule(s) implemented by the strategy matches the supplied request.

Parameters

Request $request

Return Value

bool true if the request matches, false otherwise
at line 26

setExpression()

public setExpression(ExpressionLanguage $language, $expression)

Parameters

ExpressionLanguage $language
$expression

Source code

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App\Khan\Component\HttpFoundation;

use App\Khan\Component\ExpressionLanguage\ExpressionLanguage;

/**
 * ExpressionRequestMatcher uses an expression to match a Request.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ExpressionRequestMatcher extends RequestMatcher
{
    private $language;
    private $expression;

    public function setExpression(ExpressionLanguage $language, $expression)
    {
        $this->language = $language;
        $this->expression = $expression;
    }

    public function matches(Request $request)
    {
        if (!$this->language) {
            throw new \LogicException('Unable to match the request as the expression language is not available.');
        }

        return $this->language->evaluate($this->expression, array(
            'request' => $request,
            'method' => $request->getMethod(),
            'path' => rawurldecode($request->getPathInfo()),
            'host' => $request->getHost(),
            'ip' => $request->getClientIp(),
            'attributes' => $request->attributes->all(),
        )) && parent::matches($request);
    }
}