ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ILIAS\Refinery\Container\AddLabels Class Reference

Adds to any array keys for each value. More...

+ Inheritance diagram for ILIAS\Refinery\Container\AddLabels:
+ Collaboration diagram for ILIAS\Refinery\Container\AddLabels:

Public Member Functions

 __construct (array $labels, Factory $factory)
 
 transform ($from)
 
 applyTo (Result $result)
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 __invoke ($from)
 Transformations should be callable. More...
 

Private Attributes

array $labels
 
Factory $factory
 

Detailed Description

Adds to any array keys for each value.

Definition at line 32 of file AddLabels.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\Container\AddLabels::__construct ( array  $labels,
Factory  $factory 
)
Parameters
string[]|int[]$labels
Factory$factory

Definition at line 44 of file AddLabels.php.

References ILIAS\Refinery\Container\AddLabels\$factory, and ILIAS\Refinery\Container\AddLabels\$labels.

45  {
46  $this->labels = $labels;
47  $this->factory = $factory;
48  }

Member Function Documentation

◆ applyTo()

ILIAS\Refinery\Container\AddLabels::applyTo ( Result  $result)

Implements ILIAS\Refinery\Transformation.

Definition at line 70 of file AddLabels.php.

References ILIAS\Data\Result\value().

70  : Result
71  {
72  $dataValue = $result->value();
73  if (false === is_array($dataValue)) {
74  $exception = new InvalidArgumentException(__METHOD__ . " argument is not an array.");
75  return $this->factory->error($exception);
76  }
77 
78  if (count($dataValue) !== count($this->labels)) {
79  $exception = new InvalidArgumentException(__METHOD__ . " number of items in arrays are not equal.");
80  return $this->factory->error($exception);
81  }
82 
83  $value = array_combine($this->labels, $dataValue);
84  $result = $this->factory->ok($value);
85 
86  return $result;
87  }
+ Here is the call graph for this function:

◆ transform()

ILIAS\Refinery\Container\AddLabels::transform (   $from)

Returns
array<int|string, mixed>

Implements ILIAS\Refinery\Transformation.

Definition at line 54 of file AddLabels.php.

54  : array
55  {
56  if (!is_array($from)) {
57  throw new InvalidArgumentException(__METHOD__ . " argument is not an array.");
58  }
59 
60  if (count($from) !== count($this->labels)) {
61  throw new InvalidArgumentException(__METHOD__ . " number of items in arrays are not equal.");
62  }
63 
64  return array_combine($this->labels, $from);
65  }

Field Documentation

◆ $factory

Factory ILIAS\Refinery\Container\AddLabels::$factory
private

Definition at line 38 of file AddLabels.php.

Referenced by ILIAS\Refinery\Container\AddLabels\__construct().

◆ $labels

array ILIAS\Refinery\Container\AddLabels::$labels
private

Definition at line 37 of file AddLabels.php.

Referenced by ILIAS\Refinery\Container\AddLabels\__construct().


The documentation for this class was generated from the following file: