Documentation

LocatorResolver
in package

Class LocatorResolver

This class provides functionality for resolving locators against taxonomy schemas, handling locators within XBRL instances, and providing lookup for associated element data.

Table of Contents

Properties

$basePath  : string
$currentDir  : string
$currentFile  : string
$elementCache  : array<string|int, mixed>
$loadedSchemas  : array<string|int, mixed>
$locators  : array<string|int, mixed>
$mySql  : MySql
$namespaceRegistry  : NamespaceRegistry
$schemaTargetNamespaceCache  : array<string|int, mixed>
$taxonomyVersionId  : int
$xsdSchemaParser  : XsdSchemaParser

Methods

__construct()  : void
Constructor method.
loadLocators()  : void
Loads locators from the given XML element and populates the locators array.
parseFragment()  : array<string|int, mixed>
Parses the given fragment into its prefix and local name components.
resetLocators()  : self
Resets all locators to an empty array.
resolve()  : int
Resolves the given label and retrieves the corresponding element ID.
resolveAsDimension()  : array<string|int, mixed>
Resolves an element by its label and ensures it belongs to the 'dimensionItem' substitution group.
resolveAsHypercube()  : array<string|int, mixed>
Resolves the given label as a hypercube.
resolveBySubstitutionGroup()  : array<string|int, mixed>
Resolves an element by its label and checks whether it belongs to the expected substitution group.
resolveElement()  : array<string|int, mixed>
Resolves an element based on the provided label.
setBasePath()  : self
Sets the base path for the current instance.
setCurrentDir()  : self
Sets the current directory for the instance.
setCurrentFile()  : self
Sets the current file path for the instance.
setTaxonomyVersionId()  : self
Sets the taxonomy version ID.
buildCacheKey()  : string
Builds a cache key by combining the namespace and local name.
findElementInDbByNamespace()  : array<string|int, mixed>|false
Finds an element in the database by its name and namespace.
findElementInDbFallback()  : array<string|int, mixed>|false
Searches for an element in the database by its name, with a fallback mechanism.
getSchemaTargetNamespace()  : string
Retrieves the target namespace of a given XML schema file.
isUrl()  : bool
Checks if the given path is a valid URL.
loadSchemaIfNeeded()  : void
Loads the schema file if it has not already been loaded.
resolveHrefToElement()  : array<string|int, mixed>
Resolves an href string to its corresponding element in the database or schema.
resolvePath()  : string
Resolves the given relative path to an absolute path.

Properties

$schemaTargetNamespaceCache

private array<string|int, mixed> $schemaTargetNamespaceCache = []

Methods

__construct()

Constructor method.

public __construct(MySql $mySql, XsdSchemaParser $xsdSchemaParser, NamespaceRegistry $namespaceRegistry) : void
Parameters
$mySql : MySql

An instance of the MySql class to handle database interactions.

$xsdSchemaParser : XsdSchemaParser

An instance of the XsdSchemaParser class for parsing XSD schemas.

$namespaceRegistry : NamespaceRegistry

An instance of the NamespaceRegistry class for managing namespace registrations.

loadLocators()

Loads locators from the given XML element and populates the locators array.

public loadLocators(SimpleXMLElement $xml) : void
Parameters
$xml : SimpleXMLElement

The XML element containing the locators to be loaded. It must include the relevant namespaces and locator elements.

parseFragment()

Parses the given fragment into its prefix and local name components.

public parseFragment(string $fragment) : array<string|int, mixed>
Parameters
$fragment : string

The fragment to parse.

Tags
throws
RuntimeException

If the provided fragment is an empty string.

Return values
array<string|int, mixed>

Returns an associative array with keys 'prefix' and 'local_name'. The 'prefix' key contains the namespace prefix if present, or an empty string. The 'local_name' key contains the local name of the fragment.

resetLocators()

Resets all locators to an empty array.

public resetLocators() : self
Return values
self

Returns the current instance for method chaining.

resolve()

Resolves the given label and retrieves the corresponding element ID.

public resolve(string $label) : int
Parameters
$label : string

The label to resolve into an element ID.

Return values
int

Returns the ID of the resolved element as an integer.

resolveAsDimension()

Resolves an element by its label and ensures it belongs to the 'dimensionItem' substitution group.

public resolveAsDimension(string $label) : array<string|int, mixed>
Parameters
$label : string

The identifier of the element to resolve.

Tags
throws
UnexpectedSubstitutionGroupException

If the resolved element's substitution group is not 'dimensionItem'.

Return values
array<string|int, mixed>

The resolved element as an associative array.

resolveAsHypercube()

Resolves the given label as a hypercube.

public resolveAsHypercube(string $label) : array<string|int, mixed>
Parameters
$label : string

The label to resolve.

Return values
array<string|int, mixed>

Returns an array representing the resolved hypercube.

resolveBySubstitutionGroup()

Resolves an element by its label and checks whether it belongs to the expected substitution group.

public resolveBySubstitutionGroup(string $label, string $expectedGroup) : array<string|int, mixed>
Parameters
$label : string

The identifier of the element to resolve.

$expectedGroup : string

The expected substitution group of the element.

Tags
throws
UnexpectedSubstitutionGroupException

If the resolved element's substitution group does not match the expected group.

Return values
array<string|int, mixed>

The resolved element as an associative array.

resolveElement()

Resolves an element based on the provided label.

public resolveElement(string $label) : array<string|int, mixed>
Parameters
$label : string

The label used to identify the element within the defined locators.

Tags
throws
RuntimeException

If the locator for the given label is not found.

Return values
array<string|int, mixed>

The resolved element information as an array.

setBasePath()

Sets the base path for the current instance.

public setBasePath(string $path) : self
Parameters
$path : string

The base path to be set. Trailing directory separators will be removed.

Return values
self

Returns the current instance for method chaining.

setCurrentDir()

Sets the current directory for the instance.

public setCurrentDir(string $currentDir) : self
Parameters
$currentDir : string

The directory path to set. Trailing directory separators will be removed.

Return values
self

Returns the instance to allow method chaining.

setCurrentFile()

Sets the current file path for the instance.

public setCurrentFile(string $currentFile) : self
Parameters
$currentFile : string

The file path to be set. If the file exists, its resolved absolute path will be used; otherwise, the input path will be retained.

Return values
self

Returns the current instance for method chaining.

setTaxonomyVersionId()

Sets the taxonomy version ID.

public setTaxonomyVersionId(int $taxonomyVersionId) : self
Parameters
$taxonomyVersionId : int

The ID of the taxonomy version to set.

Return values
self

Returns the current instance for method chaining.

buildCacheKey()

Builds a cache key by combining the namespace and local name.

private buildCacheKey(string $namespace, string $localName) : string
Parameters
$namespace : string

The namespace to include in the cache key.

$localName : string

The local name to include in the cache key.

Return values
string

Returns the generated cache key.

findElementInDbByNamespace()

Finds an element in the database by its name and namespace.

private findElementInDbByNamespace(string $elementName, string $namespace) : array<string|int, mixed>|false
Parameters
$elementName : string

The name of the element to search for.

$namespace : string

The namespace of the element to search for.

Return values
array<string|int, mixed>|false

Returns an associative array representing the element if found, or false if no match is found.

findElementInDbFallback()

Searches for an element in the database by its name, with a fallback mechanism.

private findElementInDbFallback(string $elementName) : array<string|int, mixed>|false
Parameters
$elementName : string

The name of the element to find in the database.

Return values
array<string|int, mixed>|false

Returns an associative array representing the database row if the element is found, or false if no matching element is found.

getSchemaTargetNamespace()

Retrieves the target namespace of a given XML schema file.

private getSchemaTargetNamespace(string $schemaFile) : string
Parameters
$schemaFile : string

The file path or URL of the XML schema.

Tags
throws
RuntimeException

If the schema cannot be loaded for namespace detection.

Return values
string

Returns the target namespace as a string. If the schema file is a URL or cannot be parsed, an empty string is returned.

isUrl()

Checks if the given path is a valid URL.

private isUrl(string $path) : bool
Parameters
$path : string

The path to be checked.

Return values
bool

Returns true if the path is a valid URL, otherwise false.

loadSchemaIfNeeded()

Loads the schema file if it has not already been loaded.

private loadSchemaIfNeeded(string $relativeFile) : void
Parameters
$relativeFile : string

The relative path to the schema file.

Tags
throws
RuntimeException

If the schema is not found or cannot be loaded.

resolveHrefToElement()

Resolves an href string to its corresponding element in the database or schema.

private resolveHrefToElement(string $href) : array<string|int, mixed>
Parameters
$href : string

The href to resolve, which must include a fragment (e.g., "#fragment").

Tags
throws
RuntimeException

If the href is invalid or the element cannot be resolved.

throws
ExternalTaxonomyNotResolvedException

If the element belongs to an external schema that cannot be resolved locally.

Return values
array<string|int, mixed>

Returns an array representing the resolved element data if found.

resolvePath()

Resolves the given relative path to an absolute path.

private resolvePath(string $relativePath) : string
Parameters
$relativePath : string

The relative path to resolve.

Return values
string

Returns the resolved absolute path. If the path is invalid or cannot be resolved, it returns the given path as is.


        
On this page

Search results