class CanonicalURLMiddleware implements HTTPMiddleware (View source)

Implements the following URL normalisation rules

  • redirect basic auth requests to HTTPS
  • force WWW, redirect to the subdomain "www."
  • force SSL, redirect to https

Traits

A class that can be instantiated or replaced via DI

Methods

static Injectable
create(array ...$args)

An implementation of the factory method, allows you to create an instance of a class

static Injectable
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

array
getForceSSLPatterns()

No description

$this
setForceSSLPatterns(array $forceSSLPatterns)

No description

string
getForceSSLDomain()

No description

$this
setForceSSLDomain(string $forceSSLDomain)

No description

bool
getForceWWW()

No description

$this
setForceWWW(bool $forceWWW)

No description

bool
getForceSSL()

No description

$this
setForceSSL(bool $forceSSL)

No description

$this
setForceBasicAuthToSSL(bool|null $forceBasicAuth)

No description

bool
getForceBasicAuthToSSL()

No description

process(HTTPRequest $request, callable $delegate)

Generate response for the given request

throwRedirectIfNeeded(HTTPRequest $request = null)

Handles redirection to canonical urls outside of the main middleware chain using HTTPResponseException.

int
getRedirectType()

No description

$this
setRedirectType(int $redirectType)

No description

array|bool
getEnabledEnvs()

Get enabled flag, or list of environments to enable in.

$this
setEnabledEnvs(array|bool $enabledEnvs)

Set enabled flag, or list of environments to enable in.

Details

static Injectable create(array ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create('SiteTree'); $list = SiteTree::get();

Parameters

array ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

array getForceSSLPatterns()

Return Value

array

$this setForceSSLPatterns(array $forceSSLPatterns)

Parameters

array $forceSSLPatterns

Return Value

$this

string getForceSSLDomain()

Return Value

string

$this setForceSSLDomain(string $forceSSLDomain)

Parameters

string $forceSSLDomain

Return Value

$this

bool getForceWWW()

Return Value

bool

$this setForceWWW(bool $forceWWW)

Parameters

bool $forceWWW

Return Value

$this

bool getForceSSL()

Return Value

bool

$this setForceSSL(bool $forceSSL)

Parameters

bool $forceSSL

Return Value

$this

$this setForceBasicAuthToSSL(bool|null $forceBasicAuth)

Parameters

bool|null $forceBasicAuth

Return Value

$this

bool getForceBasicAuthToSSL()

Return Value

bool

HTTPResponse process(HTTPRequest $request, callable $delegate)

Generate response for the given request

Parameters

HTTPRequest $request
callable $delegate

Return Value

HTTPResponse

throwRedirectIfNeeded(HTTPRequest $request = null)

Handles redirection to canonical urls outside of the main middleware chain using HTTPResponseException.

Will not do anything if a current HTTPRequest isn't available

Parameters

HTTPRequest $request

Allow HTTPRequest to be used for the base comparison

Exceptions

HTTPResponse_Exception

int getRedirectType()

Return Value

int

$this setRedirectType(int $redirectType)

Parameters

int $redirectType

Return Value

$this

array|bool getEnabledEnvs()

Get enabled flag, or list of environments to enable in.

Return Value

array|bool

$this setEnabledEnvs(array|bool $enabledEnvs)

Set enabled flag, or list of environments to enable in.

Note: CLI is disabled by default, so "cli"(string) or true(bool) should be specified if you wish to enable for testing.

Parameters

array|bool $enabledEnvs

Return Value

$this