ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4namespace ILIAS\Data;
5
6use ILIAS\Data\Interval\OpenedFloatInterval;
7use ILIAS\Data\Interval\OpenedIntegerInterval;
8use ILIAS\Data\Interval\ClosedFloatInterval;
9use ILIAS\Data\Interval\ClosedIntegerInterval;
10
20{
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}
$size
Definition: RandomTest.php:84
An exception for terminatinating execution or to throw for unit testing.
Builds a Color from either hex- or rgb values.
Definition: Factory.php:14
Class DataSize.
Definition: DataSize.php:16
static $abbreviations
Definition: DataSize.php:69
Factory for Date Formats.
Definition: Factory.php:10
Builds a Date Format with split up elements to ease conversion.
Builds data types.
Definition: Factory.php:20
alphanumeric($value)
Definition: Factory.php:135
positiveInteger(int $value)
Definition: Factory.php:144
color($value)
Color is a data type representing a color in HTML.
Definition: Factory.php:55
refId(int $ref_id)
Definition: Factory.php:126
$colorfactory
cache for color factory.
Definition: Factory.php:24
range(int $start, int $length)
Definition: Factory.php:163
clientId(string $clientId)
Definition: Factory.php:116
uri($uri_string)
Object representing an uri valid according to RFC 3986 with restrictions imposed on valid characters ...
Definition: Factory.php:71
order(string $subject, $direction)
Definition: Factory.php:171
dataSize($size, string $unit=null)
Represents the size of some data.
Definition: Factory.php:83
ok($value)
Get an ok result.
Definition: Factory.php:32
error($e)
Get an error result.
Definition: Factory.php:43
password($pass)
Get a password.
Definition: Factory.php:107
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:11
A password is used as part of credentials for authentication.
Definition: Password.php:14
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:11
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:14
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:14
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:18
$builder
Definition: parser.php:5