ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
Handler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 use ilLogger;
30 use SplFileInfo;
31 
32 class Handler implements SchemaFolderInterface
33 {
34  protected const FILE_EXTENSION = 'xsd';
35  protected const FILE_PREFIX = 'ilias_';
36  protected const SCHEMA_DEFINITION_LOCATION = '../components/ILIAS/Export/xml/SchemaValidation';
37  protected SchemaInfoFactoryInterface $schema_info_factory;
38  protected SchemaInfoCollectionInterface $collection;
39  protected ilLogger $logger;
40 
41  public function __construct(
42  SchemaInfoFactoryInterface $schema_info_factory,
43  ilLogger $logger
44  ) {
45  $this->schema_info_factory = $schema_info_factory;
46  $this->logger = $logger;
47  $this->collection = $this->schema_info_factory->collection();
48  $this->readSchemaFiles();
49  }
50 
51  public function getLatest(string $type, string $sub_type = ''): SchemaInfoInterface|null
52  {
53  return $this->collection->getLatest($type, $sub_type);
54  }
55 
56  public function getByVersion(Version $version, string $type, string $sub_type = ''): SchemaInfoInterface|null
57  {
58  return $this->collection->getByVersion($version, $type, $sub_type);
59  }
60 
61  public function getByVersionOrLatest(Version $version, string $type, string $sub_type = ''): SchemaInfoInterface|null
62  {
63  return $this->collection->getByVersionOrLatest($version, $type, $sub_type);
64  }
65 
66  private function readSchemaFiles(): void
67  {
68  foreach (new DirectoryIterator(self::SCHEMA_DEFINITION_LOCATION) as $file) {
69  if (
70  $file->isDot() ||
71  $file->getExtension() !== self::FILE_EXTENSION ||
72  !str_starts_with($file->getFilename(), self::FILE_PREFIX)
73  ) {
74  continue;
75  }
76  $matches = [];
77  if (preg_match('/ilias_([a-zA-Z]+)(_([a-zA-Z]+))?_([3-9]|([1-9][0-9]+))_?([0-9]+)?.xsd/', $file->getFilename(), $matches) !== 1) {
78  $this->logger->debug('Ignoring file (match): ' . $file->getFilename());
79  $this->logger->dump($matches, \ilLogLevel::DEBUG);
80  continue;
81  }
82  $element = $this->schema_info_factory->handler()
83  ->withSplFileInfo(new SplFileInfo($file->getPathname()))
84  ->withComponent((string) $matches[1])
85  ->withSubtype((string) $matches[3])
86  ->withVersion(new Version($matches[4] . (($matches[6] ?? '') ? '.' . $matches[6] : '')));
87  $this->collection = $this->collection
88  ->withElement($element);
89  $this->logger->debug($file->getFilename() . ' matches');
90  }
91  }
92 }
getLatest(string $type, string $sub_type='')
Definition: Handler.php:51
$version
Definition: plugin.php:24
SchemaInfoCollectionInterface $collection
Definition: Handler.php:38
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(SchemaInfoFactoryInterface $schema_info_factory, ilLogger $logger)
Definition: Handler.php:41
getByVersionOrLatest(Version $version, string $type, string $sub_type='')
Definition: Handler.php:61
SchemaInfoFactoryInterface $schema_info_factory
Definition: Handler.php:37
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:26
getByVersion(Version $version, string $type, string $sub_type='')
Definition: Handler.php:56