Documentation

RedirectPlugin
in package
implements EventSubscriberInterface

Plugin to implement HTTP redirects. Can redirect like a web browser or using strict RFC 2616 compliance

Interfaces, Classes and Traits

EventSubscriberInterface
An EventSubscriber knows itself what events it is interested in.

Table of Contents

DISABLE  = 'redirect.disable'
MAX_REDIRECTS  = 'redirect.max'
PARENT_REQUEST  = 'redirect.parent_request'
REDIRECT_COUNT  = 'redirect.count'
STRICT_REDIRECTS  = 'redirect.strict'
$defaultMaxRedirects  : int
cleanupRequest()  : mixed
Clean up the parameters of a request when it is cloned
getSubscribedEvents()  : array<string|int, mixed>
Returns an array of event names this subscriber wants to listen to.
onRequestSent()  : mixed
Called when a request receives a redirect response
createRedirectRequest()  : RequestInterface
Create a redirect request for a specific request object
getOriginalRequest()  : RequestInterface
Get the original request that initiated a series of redirects
prepareRedirection()  : RequestInterface
Prepare the request for redirection and enforce the maximum number of allowed redirects per client
sendRedirectRequest()  : mixed
Send a redirect request and handle any errors
throwTooManyRedirectsException()  : mixed
Throw a too many redirects exception for a request

Constants

PARENT_REQUEST

public mixed PARENT_REQUEST = 'redirect.parent_request'

STRICT_REDIRECTS

public mixed STRICT_REDIRECTS = 'redirect.strict'

Properties

$defaultMaxRedirects

protected int $defaultMaxRedirects = 5

Default number of redirects allowed when no setting is supplied by a request

Methods

cleanupRequest()

Clean up the parameters of a request when it is cloned

public cleanupRequest(Event $event) : mixed
Parameters
$event : Event

Event emitted

Return values
mixed

getSubscribedEvents()

Returns an array of event names this subscriber wants to listen to.

public static getSubscribedEvents() : array<string|int, mixed>

The array keys are event names and the value can be:

  • The method name to call (priority defaults to 0)
  • An array composed of the method name to call and the priority
  • An array of arrays composed of the method names to call and respective priorities, or 0 if unset

For instance:

  • ['eventName' => 'methodName']
  • ['eventName' => ['methodName', $priority]]
  • ['eventName' => [['methodName1', $priority], ['methodName2']]]

The code must not depend on runtime state as it will only be called at compile time. All logic depending on runtime state must be put into the individual methods handling the events.

Return values
array<string|int, mixed>

The event names to listen to

onRequestSent()

Called when a request receives a redirect response

public onRequestSent(Event $event) : mixed
Parameters
$event : Event

Event emitted

Return values
mixed

createRedirectRequest()

Create a redirect request for a specific request object

protected createRedirectRequest(RequestInterface $request, int $statusCode, string $location, RequestInterface $original) : RequestInterface

Takes into account strict RFC compliant redirection (e.g. redirect POST with POST) vs doing what most clients do (e.g. redirect POST with GET).

Parameters
$request : RequestInterface

Request being redirected

$statusCode : int

Status code of the redirect

$location : string

Location header of the redirect

$original : RequestInterface

Original request

Tags
throws
CouldNotRewindStreamException

If the body needs to be rewound but cannot

Return values
RequestInterface

Returns a new redirect request

throwTooManyRedirectsException()

Throw a too many redirects exception for a request

protected throwTooManyRedirectsException(RequestInterface $original, int $max) : mixed
Parameters
$original : RequestInterface

Request

$max : int

Max allowed redirects

Tags
throws
TooManyRedirectsException

when too many redirects have been issued

Return values
mixed

Search results