ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
ILIAS\UI\Implementation\Component\Input\Container\Container\AddLabels Class Reference

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

+ Inheritance diagram for ILIAS\UI\Implementation\Component\Input\Container\Container\AddLabels:
+ Collaboration diagram for ILIAS\UI\Implementation\Component\Input\Container\Container\AddLabels:

Public Member Functions

 __construct (array $labels, Factory $factory)
 
 transform ($from)
 
 applyTo (Result $result)
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 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\UI\Implementation\Component\Input\Container\Container\AddLabels::__construct ( array  $labels,
Factory  $factory 
)

Member Function Documentation

◆ applyTo()

ILIAS\UI\Implementation\Component\Input\Container\Container\AddLabels::applyTo ( Result  $result)

Definition at line 70 of file AddLabels.php.

References factory(), and 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  }
factory()
+ Here is the call graph for this function:

◆ transform()

ILIAS\UI\Implementation\Component\Input\Container\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\UI\Implementation\Component\Input\Container\Container\AddLabels::$factory
private

◆ $labels

array ILIAS\UI\Implementation\Component\Input\Container\Container\AddLabels::$labels
private

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