ILIAS  release_7 Revision v7.30-3-g800a261c036
SplitString.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
5
10
15{
17
21 protected $delimiter;
22
26 private $factory;
27
33 {
34 $this->delimiter = $delimiter;
35 $this->factory = $factory;
36 }
37
41 public function transform($from)
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 }
49
53 public function applyTo(Result $data) : 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 }
64}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Split a string by delimiter into array.
Definition: SplitString.php:15
__construct($delimiter, Factory $factory)
Definition: SplitString.php:32
applyTo(Result $data)
Perform the transformation and reify possible failures.If $data->isError(), the method MUST do nothin...
Definition: SplitString.php:53
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
Definition: SplitString.php:41
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:12
A transformation is a function from one datatype to another.
$data
Definition: storeScorm.php:23