class Url implements Rule, Bypass (View source)

A rule to match a particular URL

Traits

Path aware trait for rules and bypasses

Methods

public
string
getPath()

Returns the path

public
$this
setPath(string $path)

Update the path

protected
string
normalisePath(string $path)

Returns the normalised version of the given path

public
__construct(string $path, string[]|string|null $httpMethods = null, string[]|null $params = null)

Initialize the rule with the parameters

public
$this
addHttpMethods(string[] ...$methods)

Add HTTP methods to check against

public
string[]
getHttpMethods()

Returns HTTP methods to be checked

public
$this
setParams(string|null $params = null)

Set the GET parameters null to skip parameter check

public
bool
checkRequestForBypass(HTTPRequest $request)

Check the request for whether we can bypass the confirmation

public
null|Item
getRequestConfirmationItem(HTTPRequest $request)

Check the request by the rule and return a confirmation item

public
bool
checkRequest(HTTPRequest $request)

Match the request against the rules

protected
bool
checkPath(string $path)

Checks the given path by the rules and returns true if it is matching

protected
buildConfirmationItem(string $token, string $url)

Generates the confirmation item

protected
string
generateToken(string $httpMethod, string $path)

Generates the unique token depending on the path

Details

string getPath()

Returns the path

Return Value

string

$this setPath(string $path)

Update the path

Parameters

string $path

Return Value

$this

protected string normalisePath(string $path)

Returns the normalised version of the given path

Parameters

string $path

Path to normalise

Return Value

string

normalised version of the path

__construct(string $path, string[]|string|null $httpMethods = null, string[]|null $params = null)

Initialize the rule with the parameters

Parameters

string $path

url path to check for

string[]|string|null $httpMethods

to match against

string[]|null $params

a list of GET parameters

$this addHttpMethods(string[] ...$methods)

Add HTTP methods to check against

Parameters

string[] ...$methods

Return Value

$this

string[] getHttpMethods()

Returns HTTP methods to be checked

Return Value

string[]

$this setParams(string|null $params = null)

Set the GET parameters null to skip parameter check

If an array of parameters provided, then URL should contain ALL of them and ONLY them to match. If the values in the list contain strings, those will be checked against parameter values accordingly. Null as a value in the array matches any parameter values.

Parameters

string|null $params

Return Value

$this

bool checkRequestForBypass(HTTPRequest $request)

Check the request for whether we can bypass the confirmation

Parameters

HTTPRequest $request

Return Value

bool

True if we can bypass, False if the confirmation is required

null|Item getRequestConfirmationItem(HTTPRequest $request)

Check the request by the rule and return a confirmation item

Parameters

HTTPRequest $request

Return Value

null|Item

Confirmation item if necessary to protect the request or null otherwise

bool checkRequest(HTTPRequest $request)

Match the request against the rules

Parameters

HTTPRequest $request

Return Value

bool

protected bool checkPath(string $path)

Checks the given path by the rules and returns true if it is matching

Parameters

string $path

Path to be checked

Return Value

bool

protected Item buildConfirmationItem(string $token, string $url)

Generates the confirmation item

Parameters

string $token
string $url

Return Value

Item

protected string generateToken(string $httpMethod, string $path)

Generates the unique token depending on the path

Parameters

string $httpMethod

HTTP method

string $path

URL path

Return Value

string