ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ExportFilename.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29{
30 private ?string $path = null;
31
32 public function __construct(
33 private int $test_id
34 ) {
35 }
36
37 public function getPathname(string $extension = '', string $additional = ''): string
38 {
39 if ($this->path !== null) {
40 return $this->path;
41 }
42 if ($extension === '') {
43 throw new \ilException('Missing file extension! Please pass a file extension of type string.');
44 }
45
46 if (substr_count($extension, '.') > 1 || (strpos($extension, '.') !== false && strpos($extension, '.') !== 0)) {
47 throw new \ilException('Please use at most one dot in your file extension.');
48 }
49
50 if (strpos($extension, '.') === 0) {
51 $extension = substr($extension, 1);
52 }
53
54 $corrected_additional = '_';
55 if ($additional !== '') {
56 if (strpos($additional, '__') === 0) {
57 throw new ilException('The additional file part may not contain __ at the beginning!');
58 }
59
60 $corrected_additional = '__' . $additional . '_';
61 }
62
63 $this->path = \ilFileUtils::ilTempnam() . '__' . IL_INST_ID
64 . $corrected_additional . $this->test_id . '.' . $extension;
65 return $this->path;
66 }
67}
getPathname(string $extension='', string $additional='')
Base class for ILIAS Exception handling.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
const IL_INST_ID
Definition: constants.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...