ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\Refinery\String\SplitString Class Reference

Split a string by delimiter into array. More...

+ Inheritance diagram for ILIAS\Refinery\String\SplitString:
+ Collaboration diagram for ILIAS\Refinery\String\SplitString:

Public Member Functions

 __construct ($delimiter, 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

 $delimiter
 

Private Attributes

 $factory
 

Detailed Description

Split a string by delimiter into array.

Definition at line 14 of file SplitString.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\String\SplitString::__construct (   $delimiter,
Factory  $factory 
)
Parameters
string$delimiter
Factory$factory

Definition at line 32 of file SplitString.php.

References ILIAS\Refinery\String\SplitString\$delimiter, and ILIAS\Refinery\String\SplitString\$factory.

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

Member Function Documentation

◆ applyTo()

ILIAS\Refinery\String\SplitString::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 53 of file SplitString.php.

References ILIAS\Data\Result\value().

53  : Result
54  {
55  $dataValue = $data->value();
56  if (false === is_string($dataValue)) {
57  $exception = new \InvalidArgumentException(__METHOD__ . " the argument is not a string.");
58  return $this->factory->error($exception);
59  }
60 
61  $value = explode($this->delimiter, $dataValue);
62  return $this->factory->ok($value);
63  }
$data
Definition: storeScorm.php:23
+ Here is the call graph for this function:

◆ transform()

ILIAS\Refinery\String\SplitString::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 SplitString.php.

42  {
43  if (!is_string($from)) {
44  throw new \InvalidArgumentException(__METHOD__ . " the argument is not a string.");
45  }
46 
47  return explode($this->delimiter, $from);
48  }

Field Documentation

◆ $delimiter

ILIAS\Refinery\String\SplitString::$delimiter
protected

Definition at line 21 of file SplitString.php.

Referenced by ILIAS\Refinery\String\SplitString\__construct().

◆ $factory

ILIAS\Refinery\String\SplitString::$factory
private

Definition at line 26 of file SplitString.php.

Referenced by ILIAS\Refinery\String\SplitString\__construct().


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