ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Factory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3 
4 namespace ILIAS\Data;
5 
10 
19 class Factory
20 {
24  private $colorfactory;
25 
32  public function ok($value)
33  {
34  return new Result\Ok($value);
35  }
36 
43  public function error($e)
44  {
45  return new Result\Error($e);
46  }
47 
55  public function color($value)
56  {
57  if (!$this->colorfactory) {
58  $this->colorfactory = new Color\Factory();
59  }
60  return $this->colorfactory->build($value);
61  }
62 
71  public function uri($uri_string)
72  {
73  return new URI($uri_string);
74  }
75 
83  public function dataSize($size, string $unit = null) : DataSize
84  {
85  if (is_string($size)) {
86  $match = [];
87  if (!preg_match("/(\d+)\s*([a-zA-Z]+)/", $size, $match)) {
88  throw \InvalidArgumentException("'$size' can't be interpreted as data size.");
89  }
90  return $this->dataSize((int) $match[1], $match[2]);
91  }
92  if (is_int($size) && (is_null($unit) || !array_key_exists($unit, DataSize::$abbreviations))) {
93  throw new \InvalidArgumentException(
94  "Expected second argument to be a unit for data, '$unit' is unknown."
95  );
96  }
97  $unit_size = DataSize::$abbreviations[$unit];
98  return new DataSize($size * $unit_size, $unit_size);
99  }
100 
107  public function password($pass)
108  {
109  return new Password($pass);
110  }
111 
116  public function clientId(string $clientId) : ClientId
117  {
118  return new ClientId($clientId);
119  }
120 
126  public function refId(int $ref_id) : ReferenceId
127  {
128  return new ReferenceId($ref_id);
129  }
130 
135  public function alphanumeric($value) : Alphanumeric
136  {
137  return new Alphanumeric($value);
138  }
139 
144  public function positiveInteger(int $value) : PositiveInteger
145  {
146  return new PositiveInteger($value);
147  }
148 
152  public function dateFormat() : DateFormat\Factory
153  {
155  return new DateFormat\Factory($builder);
156  }
157 
163  public function range(int $start, int $length) : Range
164  {
165  return new Range($start, $length);
166  }
167 
171  public function order(string $subject, $direction) : Order
172  {
173  return new Order($subject, $direction);
174  }
175 }
color($value)
Color is a data type representing a color in HTML.
Definition: Factory.php:55
$size
Definition: RandomTest.php:84
error($e)
Get an error result.
Definition: Factory.php:43
Class DataSize.
Definition: DataSize.php:15
order(string $subject, $direction)
Definition: Factory.php:171
A password is used as part of credentials for authentication.
Definition: Password.php:13
static $abbreviations
Definition: DataSize.php:69
refId(int $ref_id)
Definition: Factory.php:126
dataSize($size, string $unit=null)
Represents the size of some data.
Definition: Factory.php:83
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:10
Factory for Date Formats.
Definition: Factory.php:9
Builds a Date Format with split up elements to ease conversion.
$colorfactory
cache for color factory.
Definition: Factory.php:24
positiveInteger(int $value)
Definition: Factory.php:144
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:17
Builds data types.
Definition: Factory.php:19
password($pass)
Get a password.
Definition: Factory.php:107
clientId(string $clientId)
Definition: Factory.php:116
range(int $start, int $length)
Definition: Factory.php:163
ok($value)
Get an ok result.
Definition: Factory.php:32
uri($uri_string)
Object representing an uri valid according to RFC 3986 with restrictions imposed on valid characters ...
Definition: Factory.php:71
alphanumeric($value)
Definition: Factory.php:135
$builder
Definition: parser.php:5
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:10