ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 @inheritDoc More...
 
 applyTo (Result $result)
 @inheritDoc More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 transform ($from)
 Perform the transformation. More...
 
 applyTo (Result $result)
 Perform the transformation and reify possible failures. More...
 
 __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.

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

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

+ Here is the call graph for this function:

Member Function Documentation

◆ applyTo()

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

@inheritDoc

Implements ILIAS\Refinery\Transformation.

Definition at line 70 of file AddLabels.php.

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 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
value()
Get the encapsulated value.

References factory(), and ILIAS\Data\Result\value().

+ Here is the call graph for this function:

◆ transform()

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

@inheritDoc

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: