NamespaceRegistry
in package
Manages the registration and retrieval of XML namespace mappings for multiple files using prefixes and namespaces.
Table of Contents
Properties
- $namespaceToPrefixByFile : array<string|int, mixed>
- $prefixToNamespaceByFile : array<string|int, mixed>
Methods
- allForFile() : array<string|int, mixed>
- Retrieves all prefix-to-namespace mappings associated with the specified file.
- getNamespace() : string|null
- Retrieves the namespace associated with a given file and prefix.
- getPrefix() : string|null
- Retrieves the prefix associated with a given file and namespace.
- hasPrefix() : bool
- Checks if a given file has the specified prefix.
- registerFromXml() : void
- Registers XML namespaces from a given SimpleXMLElement instance and maps prefixes to namespaces and namespaces to prefixes for the provided file key.
- reset() : void
- Resets all stored mappings by clearing internal data structures.
- normalizeFileKey() : string
Properties
$namespaceToPrefixByFile
private
array<string|int, mixed>
$namespaceToPrefixByFile
= []
$prefixToNamespaceByFile
private
array<string|int, mixed>
$prefixToNamespaceByFile
= []
Methods
allForFile()
Retrieves all prefix-to-namespace mappings associated with the specified file.
public
allForFile(string $file) : array<string|int, mixed>
Parameters
- $file : string
-
The file key for which to retrieve the mappings.
Return values
array<string|int, mixed> —An array of prefix-to-namespace mappings for the given file. Returns an empty array if no mappings are found.
getNamespace()
Retrieves the namespace associated with a given file and prefix.
public
getNamespace(string $file, string $prefix) : string|null
Parameters
- $file : string
-
The file name or key to be normalized and used for lookup.
- $prefix : string
-
The prefix used as part of the namespace lookup.
Return values
string|null —The corresponding namespace, or null if not found.
getPrefix()
Retrieves the prefix associated with a given file and namespace.
public
getPrefix(string $file, string $namespace) : string|null
Parameters
- $file : string
-
The file name or key to be normalized and used for lookup.
- $namespace : string
-
The namespace used as part of the prefix lookup.
Return values
string|null —The corresponding prefix, or null if not found.
hasPrefix()
Checks if a given file has the specified prefix.
public
hasPrefix(string $file, string $prefix) : bool
Parameters
- $file : string
-
The file to check after normalization.
- $prefix : string
-
The prefix to look for in the file.
Return values
bool —Returns true if the prefix exists for the given file, otherwise false.
registerFromXml()
Registers XML namespaces from a given SimpleXMLElement instance and maps prefixes to namespaces and namespaces to prefixes for the provided file key.
public
registerFromXml(string $file, SimpleXMLElement $xml) : void
Parameters
- $file : string
-
The file key used to store and organize namespace mappings.
- $xml : SimpleXMLElement
-
The XML object containing namespace definitions to be registered.
reset()
Resets all stored mappings by clearing internal data structures.
public
reset() : void
normalizeFileKey()
private
normalizeFileKey(string $file) : string
Parameters
- $file : string