ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Factory.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Data;
22 
25 use ILIAS\Data\Meta;
26 
35 class Factory
36 {
40  private ?Color\Factory $colorfactory = 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 
197  public function dataset(array $dimensions): Chart\Dataset
198  {
199  return new Chart\Dataset($dimensions);
200  }
201 
202  public function htmlMetadata(): Meta\Html\Factory
203  {
204  if (null === $this->html_metadata_factory) {
205  $this->html_metadata_factory = new Meta\Html\Factory();
206  }
207 
209  }
210 
211  public function openGraphMetadata(): Meta\Html\OpenGraph\Factory
212  {
213  if (null === $this->open_graph_metadata_factory) {
214  $this->open_graph_metadata_factory = new Meta\Html\OpenGraph\Factory();
215  }
216 
218  }
219 
220  public function languageTag(string $language_tag): LanguageTag
221  {
222  return LanguageTag::fromString($language_tag);
223  }
224 }
color($value)
Color is a data type representing a color in HTML.
Definition: Factory.php:72
dataset(array $dimensions)
Definition: Factory.php:197
languageTag(string $language_tag)
Definition: Factory.php:220
Color expresses a certain color by giving the mixing ratio in the RGB color space.
Definition: Color.php:15
Meta Html OpenGraph Factory $open_graph_metadata_factory
Definition: Factory.php:43
password(string $pass)
Definition: Factory.php:115
static fromString(string $string)
Definition: LanguageTag.php:48
error($e)
Get an error result.
Definition: Factory.php:61
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:30
$clientId
Definition: ltiregend.php:27
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:14
A password is used as part of credentials for authentication.
Definition: Password.php:16
This class represents a valid language tag that should be used instead of plain strings.
Definition: LanguageTag.php:39
version(string $version)
Definition: Factory.php:171
refId(int $ref_id)
Definition: Factory.php:125
dataSize($size, string $unit=null)
Represents the size of some data.
Definition: Factory.php:97
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
Factory for Date Formats.
Definition: Factory.php:26
static array $abbreviations
Definition: DataSize.php:52
Builds a Date Format with split up elements to ease conversion.
positiveInteger(int $value)
Definition: Factory.php:143
$ref_id
Definition: ltiauth.php:67
Meta Html Factory $html_metadata_factory
Definition: Factory.php:42
link(string $label, URI $url)
Definition: Factory.php:176
Dimension Factory $dimensionfactory
Definition: Factory.php:41
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:18
$url
Definition: ltiregstart.php:35
Color Factory $colorfactory
cache for color factory.
Definition: Factory.php:40
uri(string $uri_string)
Object representing an uri valid according to RFC 3986 with restrictions imposed on valid characters ...
Definition: Factory.php:85
clientId(string $clientId)
Definition: Factory.php:120
range(int $start, int $length)
Definition: Factory.php:154
order(string $subject, string $direction)
Definition: Factory.php:162
ok($value)
Get an ok result.
Definition: Factory.php:50
objId(int $obj_id)
Definition: Factory.php:130
alphanumeric($value)
Definition: Factory.php:138
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:26
A simple class to express a range of whole positive numbers.
Definition: Range.php:30
$version
Definition: plugin.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...