vaened/dictionary-parser

v0.3 2023-08-31 23:46 UTC

This package is auto-updated.

Last update: 2024-04-30 00:49:07 UTC


README

The Dictionary Parser library empowers developers to conduct comprehensive evaluations within a data dictionary structure comprising key-value pairs. This versatile tool streamlines the process of interpreting andanalyzing values within the collection. By enabling users to define precise evaluation conditions and corresponding actions, it facilitates data-driven decision-making.

Installation

You can install the library using composer.

composer require vaened/dictionary-parser

Usage

$mediator = new Mediator($parameters);

// Utilize reflection to dynamically evaluate the data dictionary
// based on the specified function signature.
$mediator->when(
    new Matcher(
        fn(array $skills) => /* Perform appropriate action for skills */
    )
);

// Manually check if the 'birthdate' key has a value and process
// it accordingly.
$mediator->when(
    Has::value(
        Input::date('birthdate'),
        fn(DateTimeInterface $birthdate) => /* Perform relevant action based on birthdate */
    )
);

Initialize

To start utilizing the library, follow these steps to set up the essential components:

// Define your input data as an associative array.
$dictionary = [
    'name' => 'You',
    'birthdate' => '1996-01-01',
    'married' => false,
    'skills' => ['PHP', 'Js', 'Python']
];

// Create a Parameters instance from the defined dictionary.
$parameters = Parameters::from($dictionary);

// Initialize the Mediator using the prepared Parameters instance.
$mediator = new Mediator($parameters);