ILIAS  release_7 Revision v7.30-3-g800a261c036
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)
 Perform the transformation.Please use this for transformations. It's more performant than calling invoke.
Exceptions
More...
 
 applyTo (Result $data)
 Perform the transformation and reify possible failures.If $data->isError(), the method MUST do nothing. It MUST transform the value in $data like it would transform $data provided to transform. It must reify every exception thrown in this process by returning a Result that isError() and contains the exception that happened.If you simply need to implement a transformation you most probably want to implement transform and derive this via the trait DeriveTransformationInterface.If you simply want to call the transformation, you most probably want to use transform, since it simply throws exceptions that occurred while doing the transformation.If you are implementing some entity that performs processing of input data at some boundary, the reification of exceptions might help you to write cleaner code.
Parameters
Result$data
Returns
Result
More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 __invoke ($from)
 Transformations should be callable. More...
 

Protected Attributes

 $labels
 

Private Attributes

 $factory
 

Detailed Description

Adds to any array keys for each value.

Definition at line 14 of file AddLabels.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 32 of file AddLabels.php.

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

33  {
34  $this->labels = $labels;
35  $this->factory = $factory;
36  }

Member Function Documentation

◆ applyTo()

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

Perform the transformation and reify possible failures.If $data->isError(), the method MUST do nothing. It MUST transform the value in $data like it would transform $data provided to transform. It must reify every exception thrown in this process by returning a Result that isError() and contains the exception that happened.If you simply need to implement a transformation you most probably want to implement transform and derive this via the trait DeriveTransformationInterface.If you simply want to call the transformation, you most probably want to use transform, since it simply throws exceptions that occurred while doing the transformation.If you are implementing some entity that performs processing of input data at some boundary, the reification of exceptions might help you to write cleaner code.

Parameters
Result$data
Returns
Result

Implements ILIAS\Refinery\Transformation.

Definition at line 57 of file AddLabels.php.

References $result, and ILIAS\Data\Result\value().

57  : Result
58  {
59  $dataValue = $data->value();
60  if (false === is_array($dataValue)) {
61  $exception = new \InvalidArgumentException(__METHOD__ . " argument is not an array.");
62  return $this->factory->error($exception);
63  }
64 
65  if (count($dataValue) != count($this->labels)) {
66  $exception = new \InvalidArgumentException(__METHOD__ . " number of items in arrays are not equal.");
67  return $this->factory->error($exception);
68  }
69 
70  $value = array_combine($this->labels, $dataValue);
71  $result = $this->factory->ok($value);
72 
73  return $result;
74  }
$data
Definition: storeScorm.php:23
$result
+ Here is the call graph for this function:

◆ transform()

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

Perform the transformation.Please use this for transformations. It's more performant than calling invoke.

Exceptions

Implements ILIAS\Refinery\Transformation.

Definition at line 41 of file AddLabels.php.

42  {
43  if (!is_array($from)) {
44  throw new \InvalidArgumentException(__METHOD__ . " argument is not an array.");
45  }
46 
47  if (count($from) != count($this->labels)) {
48  throw new \InvalidArgumentException(__METHOD__ . " number of items in arrays are not equal.");
49  }
50 
51  return array_combine($this->labels, $from);
52  }

Field Documentation

◆ $factory

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

Definition at line 26 of file AddLabels.php.

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

◆ $labels

ILIAS\Refinery\Container\AddLabels::$labels
protected

Definition at line 21 of file AddLabels.php.

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


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