ILIAS  release_8 Revision v8.24
Factory.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
6
7namespace ILIAS\Data;
8
11
21{
27
33 public function ok($value): Result
34 {
35 return new Result\Ok($value);
36 }
37
44 public function error($e): Result
45 {
46 return new Result\Error($e);
47 }
48
55 public function color($value): Color
56 {
57 if (!$this->colorfactory) {
58 $this->colorfactory = new Color\Factory();
59 }
60 return $this->colorfactory->build($value);
61 }
62
68 public function uri(string $uri_string): URI
69 {
70 return new URI($uri_string);
71 }
72
80 public function dataSize($size, string $unit = null): DataSize
81 {
82 if (is_string($size)) {
83 $match = [];
84 if (!preg_match("/(\d+)\s*([a-zA-Z]+)/", $size, $match)) {
85 throw new \InvalidArgumentException("'$size' can't be interpreted as data size.");
86 }
87 return $this->dataSize((int) $match[1], $match[2]);
88 }
89 if (is_int($size) && (is_null($unit) || !array_key_exists($unit, DataSize::$abbreviations))) {
90 throw new \InvalidArgumentException(
91 "Expected second argument to be a unit for data, '$unit' is unknown."
92 );
93 }
94 $unit_size = DataSize::$abbreviations[$unit];
95 return new DataSize($size * $unit_size, $unit_size);
96 }
97
98 public function password(string $pass): Password
99 {
100 return new Password($pass);
101 }
102
103 public function clientId(string $clientId): ClientId
104 {
105 return new ClientId($clientId);
106 }
107
108 public function refId(int $ref_id): ReferenceId
109 {
110 return new ReferenceId($ref_id);
111 }
112
113 public function objId(int $obj_id): ObjectId
114 {
115 return new ObjectId($obj_id);
116 }
117
121 public function alphanumeric($value): Alphanumeric
122 {
123 return new Alphanumeric($value);
124 }
125
126 public function positiveInteger(int $value): PositiveInteger
127 {
128 return new PositiveInteger($value);
129 }
130
131 public function dateFormat(): DateFormat\Factory
132 {
133 $builder = new DateFormat\FormatBuilder();
134 return new DateFormat\Factory($builder);
135 }
136
137 public function range(int $start, int $length): Range
138 {
139 return new Range($start, $length);
140 }
141
145 public function order(string $subject, string $direction): Order
146 {
147 return new Order($subject, $direction);
148 }
149
154 public function version(string $version): Version
155 {
156 return new Version($version);
157 }
158
159 public function link(string $label, URI $url): Link
160 {
161 return new Link($label, $url);
162 }
163
164 public function clock(): ClockFactory
165 {
166 return new ClockFactoryImpl();
167 }
168
169 public function dimension(): Dimension\Factory
170 {
171 if (!$this->dimensionfactory) {
172 $this->dimensionfactory = new Dimension\Factory();
173 }
175 }
176
180 public function dataset(array $dimensions): Chart\Dataset
181 {
182 return new Chart\Dataset($dimensions);
183 }
184}
$version
Definition: plugin.php:24
Builds a Color from either hex- or rgb values.
Definition: Factory.php:17
Color expresses a certain color by giving the mixing ratio in the RGB color space.
Definition: Color.php:16
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
static array $abbreviations
Definition: DataSize.php:53
Factory for Date Formats.
Definition: Factory.php:27
Builds a Date Format with split up elements to ease conversion.
Builds data types.
Definition: Factory.php:21
alphanumeric($value)
Definition: Factory.php:121
positiveInteger(int $value)
Definition: Factory.php:126
password(string $pass)
Definition: Factory.php:98
Dimension Factory $dimensionfactory
Definition: Factory.php:26
Color Factory $colorfactory
cache for color factory.
Definition: Factory.php:25
color($value)
Color is a data type representing a color in HTML.
Definition: Factory.php:55
refId(int $ref_id)
Definition: Factory.php:108
dataset(array $dimensions)
Definition: Factory.php:180
range(int $start, int $length)
Definition: Factory.php:137
clientId(string $clientId)
Definition: Factory.php:103
objId(int $obj_id)
Definition: Factory.php:113
link(string $label, URI $url)
Definition: Factory.php:159
dataSize($size, string $unit=null)
Represents the size of some data.
Definition: Factory.php:80
order(string $subject, string $direction)
Definition: Factory.php:145
ok($value)
Get an ok result.
Definition: Factory.php:33
error($e)
Get an error result.
Definition: Factory.php:44
uri(string $uri_string)
Object representing an uri valid according to RFC 3986 with restrictions imposed on valid characters ...
Definition: Factory.php:68
version(string $version)
Definition: Factory.php:154
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:13
A password is used as part of credentials for authentication.
Definition: Password.php:17
A simple class to express a range of whole positive numbers.
Definition: Range.php:31
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:18
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:17
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:27
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:15
$ref_id
Definition: ltiauth.php:67
$clientId
Definition: ltiregend.php:27
$url