ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Handler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\Factory as DataFactory;
31
32class Handler implements SchemaInterface
33{
34 protected SchemaFolderInterface $schema_folder;
35 protected ParserFactoryInterface $parser_factory;
36 protected XSDFileFactoryInterface $xsd_file_factory;
37 protected DataFactory $data_factory;
38 protected null|string $type;
39 protected null|string $subtype;
40 protected null|Version $version;
41
42 public function __construct(
43 SchemaFolderInterface $schema_folder,
44 DataFactory $data_factory,
45 ParserFactoryInterface $parser_factory,
46 XSDFileFactoryInterface $xsd_file_factory
47 ) {
48 $this->schema_folder = $schema_folder;
49 $this->parser_factory = $parser_factory;
50 $this->xsd_file_factory = $xsd_file_factory;
51 $this->data_factory = $data_factory;
52 $this->type = null;
53 $this->subtype = null;
54 $this->version = null;
55 }
56
57 public function getXSDFileHandlerByVersionOrLatest(): null|XSDFileInterface
58 {
59 if (
60 is_null($this->getVersion()) ||
61 is_null($this->getPrimaryType()) ||
62 is_null($this->getSecondaryType())
63 ) {
64 return null;
65 }
66 $schema_info = $this->schema_folder->getByVersionOrLatest(
67 $this->getVersion(),
68 $this->getPrimaryType(),
69 $this->getSecondaryType()
70 );
71 return is_null($schema_info)
72 ? null
73 : $this->xsd_file_factory->handler()->withFileInfo($schema_info->getFile());
74 }
75
76 public function getXSDFileHandlerLatest(): null|XSDFileInterface
77 {
78 if (
79 is_null($this->getPrimaryType()) ||
80 is_null($this->getSecondaryType())
81 ) {
82 return null;
83 }
84 $schema_info = $this->schema_folder->getLatest(
85 $this->getPrimaryType(),
86 $this->getSecondaryType()
87 );
88 return is_null($schema_info)
89 ? null
90 : $this->xsd_file_factory->handler()->withFileInfo($schema_info->getFile());
91 }
92
94 {
95 if (
96 is_null($this->getVersion()) ||
97 is_null($this->getPrimaryType()) ||
98 is_null($this->getSecondaryType())
99 ) {
100 return false;
101 }
102 $schema_info = $this->schema_folder->getByVersion(
103 $this->getVersion(),
104 $this->getPrimaryType(),
105 $this->getSecondaryType()
106 );
107 return !is_null($schema_info);
108 }
109
110 public function withInformationOf(
111 XMLFileNodeInfoInterface $xml_file_node_info
112 ): SchemaInterface {
113 $type_str = $xml_file_node_info->getValueOfAttribute('Entity');
114 $types = str_contains($type_str, '_')
115 ? explode('_', $type_str)
116 : [$type_str, ''];
117 $version_str = $xml_file_node_info->hasAttribute('SchemaVersion')
118 ? $xml_file_node_info->getValueOfAttribute('SchemaVersion')
119 : '';
120 if ($version_str === '') {
121 return $this
122 ->withType($types[0])
123 ->withSubType($types[1])
124 ->withVersion($this->data_factory->version(((int) ILIAS_VERSION_NUMERIC) . ".0.0"));
125 }
126 return $this
127 ->withType($types[0])
128 ->withSubType($types[1])
129 ->withVersion($this->data_factory->version($version_str));
130 }
131
132 public function withType(
133 string $type
134 ): SchemaInterface {
135 $clone = clone $this;
136 $clone->type = $type;
137 return $clone;
138 }
139
140 public function withSubType(
141 string $subtype
142 ): SchemaInterface {
143 $clone = clone $this;
144 $clone->subtype = $subtype;
145 return $clone;
146 }
147
148 public function withVersion(
150 ): SchemaInterface {
151 $clone = clone $this;
152 $clone->version = $version;
153 return $clone;
154 }
155
156 public function getMajorVersionString(): string
157 {
158 if (is_null($this->getVersion()) || is_null($this->getVersion()->getMajor())) {
159 return ((int) ILIAS_VERSION_NUMERIC) . ".0.0";
160 }
161 return $this->getVersion()->getMajor() . ".0.0";
162 }
163
164 public function getVersion(): null|Version
165 {
166 return $this->version;
167 }
168
169 public function getPrimaryType(): null|string
170 {
171 return $this->type;
172 }
173
174 public function getSecondaryType(): null|string
175 {
176 return $this->subtype;
177 }
178
179 public function getTypeString(): string
180 {
181 if (is_null($this->getPrimaryType())) {
182 return '';
183 }
184 if (is_null($this->getSecondaryType())) {
185 return $this->getPrimaryType();
186 }
187 return $this->getPrimaryType() . '_' . $this->getSecondaryType();
188 }
189}
$version
Definition: plugin.php:24
Builds data types.
Definition: Factory.php:36
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:27
withInformationOf(XMLFileNodeInfoInterface $xml_file_node_info)
Definition: Handler.php:110
__construct(SchemaFolderInterface $schema_folder, DataFactory $data_factory, ParserFactoryInterface $parser_factory, XSDFileFactoryInterface $xsd_file_factory)
Definition: Handler.php:42
ParserFactoryInterface $parser_factory
Definition: Handler.php:35
SchemaFolderInterface $schema_folder
Definition: Handler.php:34
XSDFileFactoryInterface $xsd_file_factory
Definition: Handler.php:36
const ILIAS_VERSION_NUMERIC