ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Handler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use ILIAS\Export\ImportHandler\I\File\XSD\FactoryInterface as XSDFileFactoryInterface;
27 use ILIAS\Export\ImportHandler\I\Parser\FactoryInterface as ParserFactoryInterface;
31 
32 class Handler implements SchemaInterface
33 {
34  protected SchemaFolderInterface $schema_folder;
35  protected ParserFactoryInterface $parser_factory;
36  protected XSDFileFactoryInterface $xsd_file_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 
93  public function doesXSDFileWithMatchingVersionExist(): bool
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(
149  Version $version
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 }
SchemaFolderInterface $schema_folder
Definition: Handler.php:34
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const ILIAS_VERSION_NUMERIC
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withInformationOf(XMLFileNodeInfoInterface $xml_file_node_info)
Definition: Handler.php:110
XSDFileFactoryInterface $xsd_file_factory
Definition: Handler.php:36
ParserFactoryInterface $parser_factory
Definition: Handler.php:35
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:26
__construct(SchemaFolderInterface $schema_folder, DataFactory $data_factory, ParserFactoryInterface $parser_factory, XSDFileFactoryInterface $xsd_file_factory)
Definition: Handler.php:42