ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\Export\ImportHandler\I\File\ilHandlerInterface as ilFileHandlerInterface;
25 use ILIAS\Export\ImportHandler\I\File\Namespace\ilCollectionInterface as ilFileNamespaceCollectionInterface;
26 use ILIAS\Export\ImportHandler\I\File\Namespace\ilFactoryInterface as ilFileNamespaceFactoryInterface;
27 use ILIAS\Export\ImportHandler\I\File\Namespace\ilHandlerInterface as ilFileNamespaceHandlerInterface;
28 use SplFileInfo;
29 
30 class ilHandler implements ilFileHandlerInterface
31 {
33  protected ilFileNamespaceFactoryInterface $namespace;
34  protected ilFileNamespaceCollectionInterface $namespaces;
35 
36  public function __construct(
37  ilFileNamespaceFactoryInterface $namespace
38  ) {
39  $this->namespace = $namespace;
40  $this->namespaces = $namespace->collection();
41  }
42 
43  public function withAdditionalNamespace(ilFileNamespaceHandlerInterface $namespace_handler): ilFileHandlerInterface
44  {
45  $clone = clone $this;
46  $clone->namespaces = $clone->namespaces->withElement($namespace_handler);
47  return $clone;
48  }
49 
50  public function getNamespaces(): ilFileNamespaceCollectionInterface
51  {
52  return $this->namespaces;
53  }
54 
55  public function withFileInfo(SplFileInfo $file_info): ilFileHandlerInterface
56  {
57  $clone = clone $this;
58  $clone->xml_file_info = $file_info;
59  return $clone;
60  }
61 
62  public function getFileName(): string
63  {
64  return $this->xml_file_info->getFilename();
65  }
66 
67  public function getFilePath(): string
68  {
69  return $this->fileExists()
70  ? $this->xml_file_info->getRealPath()
71  : $this->xml_file_info->getPath() . DIRECTORY_SEPARATOR . $this->xml_file_info->getFilename();
72  }
73 
74  public function getSubPathToDirBeginningAtPathEnd(string $dir_name): ilFileHandlerInterface
75  {
76  $parts = explode(DIRECTORY_SEPARATOR, $this->getFilePath());
77  $trimmed_str = '';
78  for ($i = count($parts) - 1; $i >= 0; $i--) {
79  $trimmed_str = $i < count($parts) - 1
80  ? $parts[$i] . DIRECTORY_SEPARATOR . $trimmed_str
81  : $parts[$i];
82  if ($parts[$i] === $dir_name) {
83  break;
84  }
85  }
86  $clone = clone $this;
87  $clone->xml_file_info = new SplFileInfo($trimmed_str);
88  return $clone;
89  }
90 
91  public function getSubPathToDirBeginningAtPathStart(string $dir_name): ilFileHandlerInterface
92  {
93  $parts = explode(DIRECTORY_SEPARATOR, $this->getFilePath());
94  $trimmed_str = '';
95  for ($i = 0; $i < count($parts); $i++) {
96  $trimmed_str .= $i > 0
97  ? DIRECTORY_SEPARATOR . $parts[$i]
98  : $parts[$i];
99  if ($parts[$i] === $dir_name) {
100  break;
101  }
102  }
103  $clone = clone $this;
104  $clone->xml_file_info = new SplFileInfo($trimmed_str);
105  return $clone;
106  }
107 
108  public function getPathToFileLocation(): string
109  {
110  return $this->xml_file_info->getPath();
111  }
112 
113  public function fileExists(): bool
114  {
115  return $this->xml_file_info->getRealPath() !== false;
116  }
117 
118  public function getPathPart(string $pattern): string|null
119  {
120  $path_parts = explode(DIRECTORY_SEPARATOR, $this->getFilePath());
121  foreach ($path_parts as $path_part) {
122  if (preg_match($pattern, $path_part) === 1) {
123  return $path_part;
124  }
125  }
126  return null;
127  }
128 
129  public function pathContainsFolderName(string $folder_name): bool
130  {
131  $path_parts = explode(DIRECTORY_SEPARATOR, $this->getFilePath());
132  if (in_array($folder_name, $path_parts, true)) {
133  return true;
134  }
135  return false;
136  }
137 }
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
ilFileNamespaceFactoryInterface $namespace
__construct(ilFileNamespaceFactoryInterface $namespace)
ilFileNamespaceCollectionInterface $namespaces
withAdditionalNamespace(ilFileNamespaceHandlerInterface $namespace_handler)