ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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...
 
 __invoke ($from)
 Transformations should be callable.This MUST do the same as transform.
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...
 

Protected Attributes

 $delimiter
 

Private Attributes

 $factory
 

Detailed Description

Split a string by delimiter into array.

Definition at line 13 of file SplitString.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 29 of file SplitString.php.

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

30  {
31  $this->delimiter = $delimiter;
32  $this->factory = $factory;
33  }

Member Function Documentation

◆ __invoke()

ILIAS\Refinery\String\SplitString::__invoke (   $from)

Transformations should be callable.This MUST do the same as transform.

Exceptions

Implements ILIAS\Refinery\Transformation.

Definition at line 50 of file SplitString.php.

References ILIAS\Refinery\String\SplitString\transform().

51  {
52  return $this->transform($from);
53  }
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
Definition: SplitString.php:38
+ Here is the call graph for this function:

◆ 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 58 of file SplitString.php.

References ILIAS\Data\Result\value().

58  : Result
59  {
60  $dataValue = $data->value();
61  if (false === is_string($dataValue)) {
62  $exception = new \InvalidArgumentException(__METHOD__ . " the argument is not a string.");
63  return $this->factory->error($exception);
64  }
65 
66  $value = explode($this->delimiter, $dataValue);
67  return $this->factory->ok($value);
68  }
$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 38 of file SplitString.php.

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

39  {
40  if (!is_string($from)) {
41  throw new \InvalidArgumentException(__METHOD__ . " the argument is not a string.");
42  }
43 
44  return explode($this->delimiter, $from);
45  }
+ Here is the caller graph for this function:

Field Documentation

◆ $delimiter

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

Definition at line 18 of file SplitString.php.

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

◆ $factory

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

Definition at line 23 of file SplitString.php.

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


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