RedirectPlugin
in package
implements
EventSubscriberInterface
Plugin to implement HTTP redirects. Can redirect like a web browser or using strict RFC 2616 compliance
Table of Contents
Interfaces
- EventSubscriberInterface
- An EventSubscriber knows himself what events he is interested in.
Constants
- DISABLE = 'redirect.disable'
- MAX_REDIRECTS = 'redirect.max'
- PARENT_REQUEST = 'redirect.parent_request'
- REDIRECT_COUNT = 'redirect.count'
- STRICT_REDIRECTS = 'redirect.strict'
Properties
- $defaultMaxRedirects : int
Methods
- 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
DISABLE
public
mixed
DISABLE
= 'redirect.disable'
MAX_REDIRECTS
public
mixed
MAX_REDIRECTS
= 'redirect.max'
PARENT_REQUEST
public
mixed
PARENT_REQUEST
= 'redirect.parent_request'
REDIRECT_COUNT
public
mixed
REDIRECT_COUNT
= 'redirect.count'
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
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:
- array('eventName' => 'methodName')
- array('eventName' => array('methodName', $priority))
- array('eventName' => array(array('methodName1', $priority), array('methodName2')))
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
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
Return values
RequestInterface —Returns a new redirect request
getOriginalRequest()
Get the original request that initiated a series of redirects
protected
getOriginalRequest(RequestInterface $request) : RequestInterface
Parameters
- $request : RequestInterface
-
Request to get the original request from
Return values
RequestInterfaceprepareRedirection()
Prepare the request for redirection and enforce the maximum number of allowed redirects per client
protected
prepareRedirection(RequestInterface $original, RequestInterface $request, Response $response) : RequestInterface
Parameters
- $original : RequestInterface
-
Original request
- $request : RequestInterface
-
Request to prepare and validate
- $response : Response
-
The current response
Return values
RequestInterfacesendRedirectRequest()
Send a redirect request and handle any errors
protected
sendRedirectRequest(RequestInterface $original, RequestInterface $request, Response $response) : mixed
Parameters
- $original : RequestInterface
-
The originating request
- $request : RequestInterface
-
The current request being redirected
- $response : Response
-
The response of the current request
Tags
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