abstract class AbstractXmlMiddleware extends AbstractMiddleware (View source)

The base XML middleware class that all other XML middleware classes extend from. It handles low-level functionality that is shared across all XML middleware classes.

Traits

Shared code for working with the logger.

Properties

protected LoggerInterface $logger A PSR-3 logger. from LoggerTrait
protected callable $fn A callable which is used to determine whether or not to run this middleware. from AbstractMiddleware
protected bool $caseSensitive The status of case-sensitivity.

Methods

setLogger(LoggerInterface $logger)

Sets the PSR-3 logger.

getLogger()

Retrieves the PSR-3 logger.

__construct(callable|null $fn = null)

Constructs a new instance of this class.

void
addArrayProperty(mixed $object, string $property)

Checks whether or not a particular property exists on an object, and if not, instantiates it as an array.

get(array $arr, string $key, mixed $default = null)

Return the value of an associative array key, if it exists. If not, return $default.

setCaseInsensitive(bool $makeInsensitive = true)

By default, SimplePie NG is case-sensitive (as per the specification). If an invalid feed is parsed that does not follow the specification with regard to casing of XML elements, this method allows you to trade some performance in favor of case-insensitive parsing.

string
applyNsToQuery(string $query, string $namespaceAlias)

Replace all instances of %s with the $namespaceAlias parameter.

string
generateQuery(string $namespaceAlias, array $path)

Produce an XPath 1.0 expression which is used to query XML document nodes.

Details

LoggerTrait setLogger(LoggerInterface $logger)

Sets the PSR-3 logger.

Parameters

LoggerInterface $logger A PSR-3 compatible logger.

Return Value

LoggerTrait

LoggerInterface getLogger()

Retrieves the PSR-3 logger.

Return Value

LoggerInterface

__construct(callable|null $fn = null)

Constructs a new instance of this class.

Accepts a callable with the following function signature:

function () {}

Parameters

callable|null $fn A callable which is used to determine whether or not to run this middleware. A value of true means that the middleware should run. A value of false means that the middleware should NOT run, By default, the middleware will run.

void addArrayProperty(mixed $object, string $property)

Checks whether or not a particular property exists on an object, and if not, instantiates it as an array.

Parameters

mixed $object An object that you can add ad-hoc properties to. Preferably a stdClass object.
string $property The name of the property to check and/or add.

Return Value

void

get(array $arr, string $key, mixed $default = null)

Return the value of an associative array key, if it exists. If not, return $default.

Parameters

array $arr The associative array to check.
string $key The key in the associative array to return the value for.
mixed $default The default value to return if there is no value. The default value is null.

AbstractXmlMiddleware setCaseInsensitive(bool $makeInsensitive = true)

By default, SimplePie NG is case-sensitive (as per the specification). If an invalid feed is parsed that does not follow the specification with regard to casing of XML elements, this method allows you to trade some performance in favor of case-insensitive parsing.

Parameters

bool $makeInsensitive Whether or not the handling should be made case-insensitive. A value of true means that the handling should be case-insensitive. A value of false means that the handling should be case-sensitive. The default value is true.

Return Value

AbstractXmlMiddleware

string applyNsToQuery(string $query, string $namespaceAlias)

Replace all instances of %s with the $namespaceAlias parameter.

This is similar to sprintf(), but the $namespaceAlias is applied to all instances of %s.

Parameters

string $query An XPath query where %s is used in-place of the XML namespace alias.
string $namespaceAlias The XML namespace alias to apply.

Return Value

string

string generateQuery(string $namespaceAlias, array $path)

Produce an XPath 1.0 expression which is used to query XML document nodes.

['feed', 'entry', 5, 'id', '@xml:lang']
/feed/entry[5]/id/@xml:lang (simplified)

Parameters

string $namespaceAlias The XML namespace alias to apply.
array $path An ordered array of nested elements, starting from the top-level XML node. If an integer is added, then it is assumed that the element before it should be handled as an array and the integer is its index. Expression is generated left-to-right.

Return Value

string An XPath 1.0 expression.