Skip to content

XmlConfigParser

XmlConfigParser handles both Quiote and foreign XML configuration files, deals with XIncludes, XSL transformations and validation as well as filtering and ordering of configuration blocks and parent file resolution and parsing.

class XmlConfigParser

Since1.0.0
SourceConfig/XmlConfigParser.php
ConstantValueDescription
NAMESPACE_QUIOTE_ANNOTATIONS_1_0'http://quiote.dev/quiote/config/global/annotations/1.0'
NAMESPACE_QUIOTE_ANNOTATIONS_LATEST'http://quiote.dev/quiote/config/global/annotations/1.0'
NAMESPACE_QUIOTE_ENVELOPE_1_1'http://quiote.dev/quiote/config/global/envelope/1.1'
NAMESPACE_QUIOTE_ENVELOPE_LATEST'http://quiote.dev/quiote/config/global/envelope/1.1'
NAMESPACE_SCHEMATRON_ISO'http://purl.oclc.org/dsdl/schematron'
NAMESPACE_SVRL_ISO'http://purl.oclc.org/dsdl/svrl'
NAMESPACE_XINCLUDE_2001'http://www.w3.org/2001/XInclude'
NAMESPACE_XMLNS_2000'http://www.w3.org/2000/xmlns/'
NAMESPACE_XML_1998'http://www.w3.org/XML/1998/namespace'
NAMESPACE_XSL_1999'http://www.w3.org/1999/XSL/Transform'
STAGE_COMPILATION'compilation'
STAGE_SINGLE'single'
STEP_TRANSFORMATIONS_AFTER'transformations_after'
STEP_TRANSFORMATIONS_BEFORE'transformations_before'
VALIDATION_TYPE_RELAXNG'relax_ng'
VALIDATION_TYPE_SCHEMATRON'schematron'
VALIDATION_TYPE_XMLSCHEMA'xml_schema'
PropertyTypeDescription
$quioteEnvelopeNamespacesmixedstatic.
$quioteNamespacesmixedstatic.

public function __construct(string $path, ?string $environment = null, ?string $context = null): mixed

The constructor.

The optional name of the current context.

ParameterTypeDescription
$pathstringThe path to the configuration file.
$environment?``stringThe optional name of the current environment.
$context?``stringThe optional name of the current context.

Returns mixed

MethodDescription
__destruct(): mixedDestructor to do the cleaning up.
cleanup(XmlConfigDomDocument $document): voidClean up a given document.
execute(array<int, string> $transformationInfo = [], array<string, mixed> $validationInfo = []): XmlConfigDomDocument
executeCompilation(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<int, string> $transformationInfo = [], array<string, mixed> $validationInfo = []): XmlConfigDomDocumentExecutes the parser for a compilation document.
getQuioteNamespacePrefix(string $namespaceUri): ?stringRetrieves an XPath namespace prefix based on a given namespace URI.
isLegacyEnvelopeNamespace(string $namespaceUri): boolCheck if the given namespace URI is a Quiote envelope namespace that used to be supported (pre-1.1) but has since been dropped.
isQuioteConfigurationDocument(XmlConfigDomDocument $doc): boolTest if the given document looks like an Quiote config file.
isQuioteEnvelopeNamespace(string $namespaceUri): boolCheck if the given namespace URI is a valid Quiote envelope namespace.
isQuioteNamespace(string $namespaceUri): boolCheck if a given namespace URI is a valid Quiote namespace.
match(XmlConfigDomDocument $document, ?string $environment, ?string $context): voidAnnotate the document with matched attributes against each configuration element that matches the given context and environment.
registerQuioteNamespaces(XmlConfigDomDocument $document): voidRegister Quiote namespace prefixes in a given document.
run(string $path, ?string $environment, ?string $context = null, array<string, array<int, string>> $transformationInfo = [], array<string, mixed> $validationInfo = [], ?ElementPositionIndex $positions = null): XmlConfigDomDocument
testPattern(mixed $pattern, mixed $subject): boolBuilds a proper regular expression from the input pattern to test against the given subject.
transform(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<int, string> $transformationInfo = [], array<int, XmlConfigDomDocument> $transformations = []): XmlConfigDomDocumentTransform the document using info from embedded processing instructions and given stylesheets.
transformProcessingInstructions(XmlConfigDomDocument $document, ?string $environment, ?string $context): XmlConfigDomDocumentTransforms a given document according to xml-stylesheet processing instructions
validate(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<string, mixed> $validationInfo = []): voidPerform validation on a given document.
validateRelaxng(XmlConfigDomDocument $document, array<int, string> $validationFiles = []): voidValidate the document against the given list of RELAX NG files.
validateSchematron(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<int, string> $validationFiles = []): voidValidate the document against the given list of Schematron files.
validateXmlschema(XmlConfigDomDocument $document, array<int, string> $validationFiles = []): voidValidate the document against the given list of XML Schema files.
validateXmlschemaSource(XmlConfigDomDocument $document, array<int, string> $validationSources = []): voidValidate the document against the given list of XML Schema documents.
validateXsi(XmlConfigDomDocument $document): voidValidate a given document according to XMLSchema-instance (xsi) declarations.
xinclude(XmlConfigDomDocument $document): voidResolve xinclude directives on a given document.

public function __destruct(): mixed

Destructor to do the cleaning up.

Returns mixed

public static function cleanup(XmlConfigDomDocument $document): void

Clean up a given document.

The document to clean up.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to clean up.

public function execute(array<int, string> $transformationInfo = [], array<string, mixed> $validationInfo = []): XmlConfigDomDocument

An associative array of validation information.

ParameterTypeDescription
$transformationInfoarray``<``int``, ``string``>An array of XSL paths for transformation.
$validationInfoarray``<``string``, ``mixed``>An associative array of validation information.

Returns XmlConfigDomDocument — Our DOMDocument.

public static function executeCompilation(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<int, string> $transformationInfo = [], array<string, mixed> $validationInfo = []): XmlConfigDomDocument

Executes the parser for a compilation document.

An associative array of validation information.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$environment?``stringThe environment name, or null if none is configured.
$context?``stringThe context name, or null if none is configured.
$transformationInfoarray``<``int``, ``string``>An array of XSL paths for transformation.
$validationInfoarray``<``string``, ``mixed``>An associative array of validation information.

Returns XmlConfigDomDocument — The compiled document.

public static function getQuioteNamespacePrefix(string $namespaceUri): ?string

Retrieves an XPath namespace prefix based on a given namespace URI.

The namespace URI.

ParameterTypeDescription
$namespaceUristringThe namespace URI.

Returns ?``string — The prefix for the namespace URI, or null if none exists.

public static function isLegacyEnvelopeNamespace(string $namespaceUri): bool

Check if the given namespace URI is a Quiote envelope namespace that used to be supported (pre-1.1) but has since been dropped.

The namespace URI.

ParameterTypeDescription
$namespaceUristringThe namespace URI.

Returns bool — True, if the given URI is a legacy envelope namespace, false otherwise.

public static function isQuioteConfigurationDocument(XmlConfigDomDocument $doc): bool

Test if the given document looks like an Quiote config file.

The document to test.

ParameterTypeDescription
$docXmlConfigDomDocumentThe document to test.

Returns bool — True, if it is an Quiote config document, false otherwise.

public static function isQuioteEnvelopeNamespace(string $namespaceUri): bool

Check if the given namespace URI is a valid Quiote envelope namespace.

The namespace URI.

ParameterTypeDescription
$namespaceUristringThe namespace URI.

Returns bool — True, if the given URI is a valid namespace URI, or false.

public static function isQuioteNamespace(string $namespaceUri): bool

Check if a given namespace URI is a valid Quiote namespace.

The namespace URI.

ParameterTypeDescription
$namespaceUristringThe namespace URI.

Returns bool — True if the given URI is a valid namespace URI, false otherwise.

public static function match(XmlConfigDomDocument $document, ?string $environment, ?string $context): void

Annotate the document with matched attributes against each configuration element that matches the given context and environment.

The context name, or null if none is configured.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$environment?``stringThe environment name, or null if none is configured.
$context?``stringThe context name, or null if none is configured.

public static function registerQuioteNamespaces(XmlConfigDomDocument $document): void

Register Quiote namespace prefixes in a given document.

The document.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document.

public static function run(string $path, ?string $environment, ?string $context = null, array<string, array<int, string>> $transformationInfo = [], array<string, mixed> $validationInfo = [], ?ElementPositionIndex $positions = null): XmlConfigDomDocument

When given, populated with a {file, line} entry for every merged element (and its descendants) whose pre-merge source node still had a real line number — i.e. it survived to the merge step without being cloned/transformed away first. Left untouched (and this is a no-op) when null, which is the default for every existing caller.

ParameterTypeDescription
$pathstringAn absolute filesystem path to a configuration file.
$environment?``stringThe environment name, or null to resolve it from core.environment (which may itself be unset — see the constructor).
$context?``stringThe optional context name.
$transformationInfoarray``<``string``, ``array``<``int``, ``string``>``>An associative array of transformation information.
$validationInfoarray``<``string``, ``mixed``>An associative array of validation information.
$positions?ElementPositionIndexWhen given, populated with a {file, line} entry for every merged element (and its descendants) whose pre-merge source node still had a real line number — i.e. it survived to the merge step without being cloned/transformed away first. Left untouched (and this is a no-op) when null, which is the default for every existing caller.

Returns XmlConfigDomDocument — A properly merged DOMDocument.

public static function testPattern(mixed $pattern, mixed $subject): bool

Builds a proper regular expression from the input pattern to test against the given subject.

The subject to test against the pattern.

ParameterTypeDescription
$patternmixedA regular expression chunk without delimiters/anchors.
$subjectmixedThe subject to test against the pattern.

Returns bool — Whether or not the subject matched the pattern.

public static function transform(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<int, string> $transformationInfo = [], array<int, XmlConfigDomDocument> $transformations = []): XmlConfigDomDocument

Transform the document using info from embedded processing instructions and given stylesheets.

An array of XSL stylesheets in DOMDocument instances.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$environment?``stringThe environment name, or null if none is configured.
$context?``stringThe context name, or null if none is configured.
$transformationInfoarray``<``int``, ``string``>An array of transformation information.
$transformationsarray``<``int``, XmlConfigDomDocument>An array of XSL stylesheets in DOMDocument instances.

Returns XmlConfigDomDocument — The transformed document.

public static function transformProcessingInstructions(XmlConfigDomDocument $document, ?string $environment, ?string $context): XmlConfigDomDocument

Transforms a given document according to xml-stylesheet processing instructions

The context name, or null if none is configured.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$environment?``stringThe environment name, or null if none is configured.
$context?``stringThe context name, or null if none is configured.

Returns XmlConfigDomDocument — The transformed document.

public static function validate(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<string, mixed> $validationInfo = []): void

Perform validation on a given document.

An array of validation information.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$environment?``stringThe environment name, or null if none is configured.
$context?``stringThe context name, or null if none is configured.
$validationInfoarray``<``string``, ``mixed``>An array of validation information.

public static function validateRelaxng(XmlConfigDomDocument $document, array<int, string> $validationFiles = []): void

Validate the document against the given list of RELAX NG files.

An array of file names to validate against.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$validationFilesarray``<``int``, ``string``>An array of file names to validate against.

public static function validateSchematron(XmlConfigDomDocument $document, ?string $environment, ?string $context, array<int, string> $validationFiles = []): void

Validate the document against the given list of Schematron files.

An array of file names to validate against.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$environment?``stringThe environment name, or null if none is configured.
$context?``stringThe context name, or null if none is configured.
$validationFilesarray``<``int``, ``string``>An array of file names to validate against.

public static function validateXmlschema(XmlConfigDomDocument $document, array<int, string> $validationFiles = []): void

Validate the document against the given list of XML Schema files.

An array of file names to validate against.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$validationFilesarray``<``int``, ``string``>An array of file names to validate against.

public static function validateXmlschemaSource(XmlConfigDomDocument $document, array<int, string> $validationSources = []): void

Validate the document against the given list of XML Schema documents.

An array of schema documents to validate against.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.
$validationSourcesarray``<``int``, ``string``>An array of schema documents to validate against.

public static function validateXsi(XmlConfigDomDocument $document): void

Validate a given document according to XMLSchema-instance (xsi) declarations.

The document to act upon.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.

public static function xinclude(XmlConfigDomDocument $document): void

Resolve xinclude directives on a given document.

The document to act upon.

ParameterTypeDescription
$documentXmlConfigDomDocumentThe document to act upon.