ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Factory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Data;
22
25use ILIAS\Data\Meta;
26
36{
37 // TODO: move this to proper dependency_injection
42 private ?Text\Factory $text_factory = null;
43 private ?Description\Factory $description_factory = null;
44
50 public function ok($value): Result
51 {
52 return new Result\Ok($value);
53 }
54
61 public function error($e): Result
62 {
63 return new Result\Error($e);
64 }
65
72 public function color($value): Color
73 {
74 if (!$this->colorfactory) {
75 $this->colorfactory = new Color\Factory();
76 }
77 return $this->colorfactory->build($value);
78 }
79
85 public function uri(string $uri_string): URI
86 {
87 return new URI($uri_string);
88 }
89
97 public function dataSize($size, ?string $unit = null): DataSize
98 {
99 if (is_string($size)) {
100 $match = [];
101 if (!preg_match("/(\d+)\s*([a-zA-Z]+)/", $size, $match)) {
102 throw new \InvalidArgumentException("'$size' can't be interpreted as data size.");
103 }
104 return $this->dataSize((int) $match[1], $match[2]);
105 }
106 if (is_int($size) && (is_null($unit) || !array_key_exists($unit, DataSize::$abbreviations))) {
107 throw new \InvalidArgumentException(
108 "Expected second argument to be a unit for data, '$unit' is unknown."
109 );
110 }
111 $unit_size = DataSize::$abbreviations[$unit];
112 return new DataSize($size * $unit_size, $unit_size);
113 }
114
115 public function password(string $pass): Password
116 {
117 return new Password($pass);
118 }
119
120 public function clientId(string $clientId): ClientId
121 {
122 return new ClientId($clientId);
123 }
124
125 public function refId(int $ref_id): ReferenceId
126 {
127 return new ReferenceId($ref_id);
128 }
129
130 public function objId(int $obj_id): ObjectId
131 {
132 return new ObjectId($obj_id);
133 }
134
138 public function alphanumeric($value): Alphanumeric
139 {
140 return new Alphanumeric($value);
141 }
142
143 public function positiveInteger(int $value): PositiveInteger
144 {
145 return new PositiveInteger($value);
146 }
147
148 public function dateFormat(): DateFormat\Factory
149 {
150 $builder = new DateFormat\FormatBuilder();
151 return new DateFormat\Factory($builder);
152 }
153
154 public function range(int $start, int $length): Range
155 {
156 return new Range($start, $length);
157 }
158
162 public function order(string $subject, string $direction): Order
163 {
164 return new Order($subject, $direction);
165 }
166
171 public function version(string $version): Version
172 {
173 return new Version($version);
174 }
175
176 public function link(string $label, URI $url): Link
177 {
178 return new Link($label, $url);
179 }
180
181 public function clock(): ClockFactory
182 {
183 return new ClockFactoryImpl();
184 }
185
186 public function dimension(): Dimension\Factory
187 {
188 if (!$this->dimensionfactory) {
189 $this->dimensionfactory = new Dimension\Factory();
190 }
192 }
193
198 public function dataset(array $dimensions, array $dimension_groups = []): Chart\Dataset
199 {
200 return new Chart\Dataset($dimensions, $dimension_groups);
201 }
202
203 public function htmlMetadata(): Meta\Html\Factory
204 {
205 if (null === $this->html_metadata_factory) {
206 $this->html_metadata_factory = new Meta\Html\Factory();
207 }
208
210 }
211
212 public function openGraphMetadata(): Meta\Html\OpenGraph\Factory
213 {
214 if (null === $this->open_graph_metadata_factory) {
215 $this->open_graph_metadata_factory = new Meta\Html\OpenGraph\Factory();
216 }
217
219 }
220
221 public function languageTag(string $language_tag): LanguageTag
222 {
223 return LanguageTag::fromString($language_tag);
224 }
225
226 public function text(): Text\Factory
227 {
228 if ($this->text_factory === null) {
229 $md_format = new \ILIAS\Refinery\String\MarkdownFormattingToHTML();
230 $this->text_factory = new \ILIAS\Data\Text\Factory(
231 new Text\MarkdownFactory(
232 new Text\Shape\Markdown($md_format),
233 new Text\Shape\SimpleDocumentMarkdown($md_format),
234 new Text\Shape\WordOnlyMarkdown($md_format)
235 )
236 );
237 }
238 return $this->text_factory;
239 }
240
241 public function description(): Description\Factory
242 {
243 if ($this->description_factory === null) {
244 $this->description_factory = new Description\Factory();
245 }
247 }
248}
$version
Definition: plugin.php:24
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Color expresses a certain color by giving the mixing ratio in the RGB color space.
Definition: Color.php:30
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:52
Factory for Date Formats.
Definition: Factory.php:27
Builds a Date Format with split up elements to ease conversion.
This describes some datastructure in terms of standard data structures such as primitives,...
Definition: Description.php:33
Builds data types.
Definition: Factory.php:36
alphanumeric($value)
Definition: Factory.php:138
positiveInteger(int $value)
Definition: Factory.php:143
password(string $pass)
Definition: Factory.php:115
Dimension Factory $dimensionfactory
Definition: Factory.php:39
Color Factory $colorfactory
Definition: Factory.php:38
color($value)
Color is a data type representing a color in HTML.
Definition: Factory.php:72
refId(int $ref_id)
Definition: Factory.php:125
range(int $start, int $length)
Definition: Factory.php:154
clientId(string $clientId)
Definition: Factory.php:120
dataset(array $dimensions, array $dimension_groups=[])
Definition: Factory.php:198
objId(int $obj_id)
Definition: Factory.php:130
link(string $label, URI $url)
Definition: Factory.php:176
Meta Html Factory $html_metadata_factory
Definition: Factory.php:40
order(string $subject, string $direction)
Definition: Factory.php:162
Meta Html OpenGraph Factory $open_graph_metadata_factory
Definition: Factory.php:41
ok($value)
Get an ok result.
Definition: Factory.php:50
dataSize($size, ?string $unit=null)
Represents the size of some data.
Definition: Factory.php:97
Text Factory $text_factory
Definition: Factory.php:42
Description Factory $description_factory
Definition: Factory.php:43
error($e)
Get an error result.
Definition: Factory.php:61
uri(string $uri_string)
Object representing an uri valid according to RFC 3986 with restrictions imposed on valid characters ...
Definition: Factory.php:85
languageTag(string $language_tag)
Definition: Factory.php:221
version(string $version)
Definition: Factory.php:171
This class represents a valid language tag that should be used instead of plain strings.
Definition: LanguageTag.php:40
static fromString(string $string)
Definition: LanguageTag.php:48
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A password is used as part of credentials for authentication.
Definition: Password.php:31
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
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:29
$ref_id
Definition: ltiauth.php:66
$clientId
Definition: ltiregend.php:26
$url
Definition: shib_logout.php:68