ContextBuilder
in package
Class ContextBuilder
Responsible for constructing and managing contextual data structures based on input data, ensuring proper validation, dimension resolution, and context uniqueness.
Table of Contents
Properties
- $contexts : array<string|int, mixed>
- $taxonomyReaderService : TaxonomyReaderService
Methods
- __construct() : void
- Constructor method for initializing the class with required dependencies.
- buildContext() : array<string|int, mixed>
- Builds a context from the provided input data by assembling entity, period, dimensions, and other context-specific elements, and generates a unique context ID.
- getAllContexts() : array<string|int, mixed>
- Retrieves all available contexts as an indexed array.
- buildContextId() : string
- Creates a unique context identifier based on the normalized data.
- buildDimensions() : array<string|int, mixed>
- Builds a list of dimensions and their associated members based on the provided primary element ID and requested dimensions, ensuring that each dimension is valid and allowed.
- buildPeriod() : array<string|int, mixed>
- Builds a period data structure based on the given period type and input data.
- detectContextElement() : string
- Detects the context element based on the provided primary element ID and dimensions.
- guessPrefixFromNamespace() : string
- Infers a prefix from the provided namespace based on predefined patterns.
- toQName() : string
- Converts a namespace and element name into a qualified name (QName).
Properties
$contexts
private
array<string|int, mixed>
$contexts
= []
$taxonomyReaderService
private
TaxonomyReaderService
$taxonomyReaderService
Methods
__construct()
Constructor method for initializing the class with required dependencies.
public
__construct(TaxonomyReaderService $taxonomyReaderService) : void
Parameters
- $taxonomyReaderService : TaxonomyReaderService
-
Service for reading taxonomy data.
buildContext()
Builds a context from the provided input data by assembling entity, period, dimensions, and other context-specific elements, and generates a unique context ID.
public
buildContext(array<string|int, mixed> $input) : array<string|int, mixed>
Parameters
- $input : array<string|int, mixed>
-
An associative array containing input data required for context construction. Expected keys include:
- 'concept_element_id': The ID of the concept element (integer).
- 'entity_identifier': The identifier of the entity (string).
- 'entity_scheme': The entity scheme identifier (string).
- 'dimensions': An optional array of dimension data.
Tags
Return values
array<string|int, mixed> —The constructed context data, including entity, period, context element, dimensions, and a unique context ID.
getAllContexts()
Retrieves all available contexts as an indexed array.
public
getAllContexts() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array containing all contexts.
buildContextId()
Creates a unique context identifier based on the normalized data.
private
buildContextId(array<string|int, mixed> $normalized) : string
Parameters
- $normalized : array<string|int, mixed>
-
An array of normalized data used to generate the context ID.
Return values
string —The generated context ID.
buildDimensions()
Builds a list of dimensions and their associated members based on the provided primary element ID and requested dimensions, ensuring that each dimension is valid and allowed.
private
buildDimensions(int $primaryElementId, array<string|int, mixed> $requestedDimensions) : array<string|int, mixed>
Parameters
- $primaryElementId : int
-
The ID of the primary element to retrieve dimensions for.
- $requestedDimensions : array<string|int, mixed>
-
An array of requested dimensions, where each item contains 'dimension_element_id' and 'member_element_id' as keys.
Tags
Return values
array<string|int, mixed> —A sorted array of dimensions and their associated members, including their qualified names and context elements.
buildPeriod()
Builds a period data structure based on the given period type and input data.
private
buildPeriod(string $periodType, array<string|int, mixed> $input) : array<string|int, mixed>
Parameters
- $periodType : string
-
The type of period, either 'instant' or 'duration'.
- $input : array<string|int, mixed>
-
The input data containing keys such as 'instant_date', 'period_start', and 'period_end'.
Tags
Return values
array<string|int, mixed> —Returns an array representing the period with its type and associated dates.
detectContextElement()
Detects the context element based on the provided primary element ID and dimensions.
private
detectContextElement(int $primaryElementId, array<string|int, mixed> $dimensions) : string
Parameters
- $primaryElementId : int
-
The ID of the primary element.
- $dimensions : array<string|int, mixed>
-
An array of dimensions, where each dimension may contain a 'context_element' key.
Return values
string —Returns the detected context element or the default 'scenario' if no specific context is determined.
guessPrefixFromNamespace()
Infers a prefix from the provided namespace based on predefined patterns.
private
guessPrefixFromNamespace(string $namespace) : string
Parameters
- $namespace : string
-
The namespace to analyze and determine the prefix from.
Return values
string —The inferred prefix, or an empty string if no match is found.
toQName()
Converts a namespace and element name into a qualified name (QName).
private
toQName(string $namespace, string $elementName) : string
Parameters
- $namespace : string
-
The namespace to use for the qualified name.
- $elementName : string
-
The local element name to be qualified.
Return values
string —The fully qualified name in the format "prefix:elementName" or "elementName" if no prefix is available.