class ContentNegotiator (View source)

The content negotiator performs "text/html" or "application/xhtml+xml" switching. It does this through the public static function ContentNegotiator::process(). By default, ContentNegotiator will comply to the Accept headers the clients sends along with the HTTP request, which is most likely "application/xhtml+xml" (see "Order of selection" below).

Order of selection between html or xhtml is as follows:

  • if PHP has already sent the HTTP headers, default to "html" (we can't send HTTP Content-Type headers any longer)
  • if a GET variable ?forceFormat is set, it takes precedence (for testing purposes)
  • if the user agent is detected as W3C Validator we always deliver "xhtml"
  • if an HTTP Accept header is sent from the client, we respect its order (this is the most common case)
  • if none of the above matches, fallback is "html"

ContentNegotiator doesn't enable you to send content as a true XML document through the "text/xml" or "application/xhtml+xml" Content-Type.

Please see http://webkit.org/blog/68/understanding-html-xml-and-xhtml/ for further information.

Traits

A class that can be instantiated or replaced via DI

Provides extensions to this object to integrate it with standard config API methods.

Properties

static private string $content_type
static private string $encoding
static private bool $enabled
static private string $default_format

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.

static Config_ForClass
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

mixed
stat(string $name) deprecated

Get inherited config value

mixed
uninherited(string $name)

Gets the uninherited value for the given config option

$this
set_stat(string $name, mixed $value) deprecated

Update the config value for a given property

static bool
enabled_for(HTTPResponse $response)

Returns true if negotiation is enabled for the given response. By default, negotiation is only enabled for pages that have the xml header.

static bool
getEnabled()

Gets the current enabled status, if it is not set this will fallback to config

static 
setEnabled(bool $enabled)

Sets the current enabled status

static 
process(HTTPResponse $response)

No description

xhtml(HTTPResponse $response)

Check user defined content type and use it, if it's empty use the strict application/xhtml+xml.

html(HTTPResponse $response)

Performs the following replacements:

  • Check user defined content type and use it, if it's empty use the text/html.

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::class); $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

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed stat(string $name) deprecated

deprecated 5.0 Use ->config()->get() instead

Get inherited config value

Parameters

string $name

Return Value

mixed

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

$this set_stat(string $name, mixed $value) deprecated

deprecated 5.0 Use ->config()->set() instead

Update the config value for a given property

Parameters

string $name
mixed $value

Return Value

$this

static bool enabled_for(HTTPResponse $response)

Returns true if negotiation is enabled for the given response. By default, negotiation is only enabled for pages that have the xml header.

Parameters

HTTPResponse $response

Return Value

bool

static bool getEnabled()

Gets the current enabled status, if it is not set this will fallback to config

Return Value

bool

static setEnabled(bool $enabled)

Sets the current enabled status

Parameters

bool $enabled

static process(HTTPResponse $response)

Parameters

HTTPResponse $response

xhtml(HTTPResponse $response)

Check user defined content type and use it, if it's empty use the strict application/xhtml+xml.

Replaces a few common tags and entities with their XHTML representations (
, ,   , checked, selected).

Parameters

HTTPResponse $response

html(HTTPResponse $response)

Performs the following replacements:

  • Check user defined content type and use it, if it's empty use the text/html.

  • If find a XML header replaces it and existing doctypes with HTML4.01 Strict.
  • Replaces self-closing tags like with unclosed solitary tags like .
  • Replaces all occurrences of "application/xhtml+xml" with "text/html" in the template.
  • Removes "xmlns" attributes and any <?xml> Pragmas.

Parameters

HTTPResponse $response