ILIAS  release_7 Revision v7.30-3-g800a261c036
ilFileSystemAbstractionStorage Class Reference
+ Inheritance diagram for ilFileSystemAbstractionStorage:
+ Collaboration diagram for ilFileSystemAbstractionStorage:

Public Member Functions

 __construct ($a_storage_type, $a_path_conversion, $a_container_id)
 Constructor. More...
 
 fileExists ($a_absolute_path)
 
 getContainerId ()
 
 create ()
 Create directory. More...
 
 getAbsolutePath ()
 Calculates the full path on the filesystem. More...
 
 writeToFile ($a_data, $a_absolute_path)
 
 deleteFile ($a_absolute_path)
 
 deleteDirectory ($a_absolute_path)
 
 delete ()
 
 copyFile ($a_from, $a_to)
 
 appendToPath ($a_appendix)
 
 getStorageType ()
 
 getPath ()
 

Static Public Member Functions

static _createPathFromId ($a_container_id, $a_name)
 Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5. More...
 
static _copyDirectory ($a_sdir, $a_tdir)
 

Data Fields

const STORAGE_WEB = 1
 
const STORAGE_DATA = 2
 
const STORAGE_SECURED = 3
 
const FACTOR = 100
 
const MAX_EXPONENT = 3
 
const SECURED_DIRECTORY = "sec"
 

Protected Member Functions

 getLegacyFullAbsolutePath ($relative_path)
 
 getFileSystemService ()
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get directory name. More...
 
 getLegacyAbsolutePath ()
 Calculates the absolute filesystem storage location. More...
 
 init ()
 Read path info. More...
 

Protected Attributes

 $path
 

Private Member Functions

 createRelativePathForFileSystem ($a_absolute_path)
 

Private Attributes

 $container_id
 
 $storage_type
 
 $path_conversion = false
 

Detailed Description

Definition at line 35 of file class.ilFileSystemAbstractionStorage.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileSystemAbstractionStorage::__construct (   $a_storage_type,
  $a_path_conversion,
  $a_container_id 
)

Constructor.

@access public

Parameters
intstorage type
boolEn/Disable automatic path conversion. If enabled files with id 123 will be stored in directory files/1/file_123
intobject id of container (e.g file_id or mob_id)

Definition at line 65 of file class.ilFileSystemAbstractionStorage.php.

66 {
67 $this->storage_type = $a_storage_type;
68 $this->path_conversion = $a_path_conversion;
69 $this->container_id = $a_container_id;
70
71 // Get path info
72 $this->init();
73 }

References init().

+ Here is the call graph for this function:

Member Function Documentation

◆ _copyDirectory()

static ilFileSystemAbstractionStorage::_copyDirectory (   $a_sdir,
  $a_tdir 
)
static
Parameters
$a_sdir
$a_tdir
Returns
bool

Definition at line 364 of file class.ilFileSystemAbstractionStorage.php.

365 {
366 try {
367 $sourceFS = LegacyPathHelper::deriveFilesystemFrom($a_sdir);
368 $targetFS = LegacyPathHelper::deriveFilesystemFrom($a_tdir);
369
370 $sourceDir = LegacyPathHelper::createRelativePath($a_sdir);
371 $targetDir = LegacyPathHelper::createRelativePath($a_tdir);
372
373 // check if arguments are directories
374 if (!$sourceFS->hasDir($sourceDir)) {
375 return false;
376 }
377
378 $sourceList = $sourceFS->listContents($sourceDir, true);
379
380 foreach ($sourceList as $item) {
381 if ($item->isDir()) {
382 continue;
383 }
384
385 $itemPath = $targetDir . '/' . substr($item->getPath(), strlen($sourceDir));
386 $stream = $sourceFS->readStream($sourceDir);
387 $targetFS->writeStream($itemPath, $stream);
388 }
389
390 return true;
391 } catch (\Exception $exception) {
392 return false;
393 }
394 }

◆ _createPathFromId()

static ilFileSystemAbstractionStorage::_createPathFromId (   $a_container_id,
  $a_name 
)
static

Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5.

Parameters
$a_container_id
$a_name
Returns
string

Definition at line 134 of file class.ilFileSystemAbstractionStorage.php.

135 {
136 $path = array();
137 $found = false;
138 $num = $a_container_id;
139 $path_string = '';
140 for ($i = self::MAX_EXPONENT; $i > 0; $i--) {
141 $factor = pow(self::FACTOR, $i);
142 if (($tmp = (int) ($num / $factor)) or $found) {
143 $path[] = $tmp;
144 $num = $num % $factor;
145 $found = true;
146 }
147 }
148
149 if (count($path)) {
150 $path_string = (implode('/', $path) . '/');
151 }
152
153 return $path_string . $a_name . '_' . $a_container_id;
154 }
$i
Definition: metadata.php:24

References $i, and $path.

Referenced by init().

+ Here is the caller graph for this function:

◆ appendToPath()

ilFileSystemAbstractionStorage::appendToPath (   $a_appendix)
Parameters
string$a_appendix

Definition at line 400 of file class.ilFileSystemAbstractionStorage.php.

401 {
402 $this->path .= $a_appendix;
403 }

◆ copyFile()

ilFileSystemAbstractionStorage::copyFile (   $a_from,
  $a_to 
)
Parameters
$a_from
$a_to
Returns
bool

Definition at line 342 of file class.ilFileSystemAbstractionStorage.php.

343 {
344 $relative_path_from = $this->createRelativePathForFileSystem($a_from);
345 $relative_path_to = $this->createRelativePathForFileSystem($a_to);
346 if ($this->getFileSystemService()->has($relative_path_from)) {
347 try {
348 $this->getFileSystemService()->copy($relative_path_from, $relative_path_to);
349 } catch (Exception $e) {
350 return false;
351 }
352 }
353
354 return true;
355 }
has(string $class_name)

References Vendor\Package\$e, createRelativePathForFileSystem(), getFileSystemService(), and ILIAS\GlobalScreen\has().

+ Here is the call graph for this function:

◆ create()

ilFileSystemAbstractionStorage::create ( )

Create directory.

@access public

Definition at line 188 of file class.ilFileSystemAbstractionStorage.php.

189 {
190 if (!$this->getFileSystemService()->has($this->path)) {
191 $this->getFileSystemService()->createDir($this->path);
192 }
193
194 return true;
195 }

References getFileSystemService(), and ILIAS\GlobalScreen\has().

+ Here is the call graph for this function:

◆ createRelativePathForFileSystem()

ilFileSystemAbstractionStorage::createRelativePathForFileSystem (   $a_absolute_path)
private
Parameters
$a_absolute_path
Returns
string

Definition at line 429 of file class.ilFileSystemAbstractionStorage.php.

430 {
431 $relative_path = ILIAS\Filesystem\Util\LegacyPathHelper::createRelativePath($a_absolute_path);
432
433 return $relative_path;
434 }
static createRelativePath(string $absolute_path)
Creates a relative path from an absolute path which starts with a valid storage location.

References ILIAS\Filesystem\Util\LegacyPathHelper\createRelativePath().

Referenced by copyFile(), deleteDirectory(), deleteFile(), fileExists(), and writeToFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilFileSystemAbstractionStorage::delete ( )
Returns
bool

Definition at line 324 of file class.ilFileSystemAbstractionStorage.php.

325 {
326 try {
327 $this->getFileSystemService()->deleteDir($this->getAbsolutePath());
328 } catch (Exception $e) {
329 return false;
330 }
331
332 return true;
333 }
getAbsolutePath()
Calculates the full path on the filesystem.

References Vendor\Package\$e, getAbsolutePath(), and getFileSystemService().

+ Here is the call graph for this function:

◆ deleteDirectory()

ilFileSystemAbstractionStorage::deleteDirectory (   $a_absolute_path)
Parameters
$a_absolute_path
Returns
bool

Definition at line 306 of file class.ilFileSystemAbstractionStorage.php.

307 {
308 $relative_path = $this->createRelativePathForFileSystem($a_absolute_path);
309 if ($this->getFileSystemService()->has($relative_path)) {
310 try {
311 $this->getFileSystemService()->deleteDir($relative_path);
312 } catch (Exception $e) {
313 return false;
314 }
315 }
316
317 return true;
318 }

References Vendor\Package\$e, createRelativePathForFileSystem(), getFileSystemService(), and ILIAS\GlobalScreen\has().

+ Here is the call graph for this function:

◆ deleteFile()

ilFileSystemAbstractionStorage::deleteFile (   $a_absolute_path)
Parameters
$a_absolute_path
Returns
bool

Definition at line 286 of file class.ilFileSystemAbstractionStorage.php.

287 {
288 $relative_path = $this->createRelativePathForFileSystem($a_absolute_path);
289 if ($this->getFileSystemService()->has($relative_path)) {
290 try {
291 $this->getFileSystemService()->delete($relative_path);
292 } catch (Exception $e) {
293 return false;
294 }
295 }
296
297 return true;
298 }

References Vendor\Package\$e, createRelativePathForFileSystem(), getFileSystemService(), and ILIAS\GlobalScreen\has().

+ Here is the call graph for this function:

◆ fileExists()

ilFileSystemAbstractionStorage::fileExists (   $a_absolute_path)
Parameters
$a_absolute_path
Returns
bool

Definition at line 81 of file class.ilFileSystemAbstractionStorage.php.

82 {
83 $relative_path = $this->createRelativePathForFileSystem($a_absolute_path);
84
85 return $this->getFileSystemService()->has($relative_path);
86 }

References createRelativePathForFileSystem(), and getFileSystemService().

+ Here is the call graph for this function:

◆ getAbsolutePath()

ilFileSystemAbstractionStorage::getAbsolutePath ( )

Calculates the full path on the filesystem.

This method is filesystem aware and will create the absolute path if it's not already existing.

Returns
string Absolute filesystem path.
Exceptions
IOExceptionThrown if the absolute path could not be created.

Definition at line 207 of file class.ilFileSystemAbstractionStorage.php.

208 {
209 return $this->getLegacyAbsolutePath();
210 }
getLegacyAbsolutePath()
Calculates the absolute filesystem storage location.

References getLegacyAbsolutePath().

Referenced by delete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getContainerId()

ilFileSystemAbstractionStorage::getContainerId ( )

◆ getFileSystemService()

ilFileSystemAbstractionStorage::getFileSystemService ( )
protected
Returns
\ILIAS\Filesystem\Filesystem

Definition at line 105 of file class.ilFileSystemAbstractionStorage.php.

106 {
107 global $DIC;
108 switch ($this->getStorageType()) {
110 return $DIC->filesystem()->storage();
111 break;
114 return $DIC->filesystem()->web();
115 break;
116 }
117 }
global $DIC
Definition: goto.php:24

References $DIC, getStorageType(), SECURED_DIRECTORY, STORAGE_DATA, and STORAGE_WEB.

Referenced by copyFile(), create(), delete(), deleteDirectory(), deleteFile(), fileExists(), getLegacyAbsolutePath(), getLegacyFullAbsolutePath(), and writeToFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLegacyAbsolutePath()

ilFileSystemAbstractionStorage::getLegacyAbsolutePath ( )
protected

Calculates the absolute filesystem storage location.

Returns
string The absolute path.
Exceptions
IOExceptionThrown if the directory could not be created.

Definition at line 220 of file class.ilFileSystemAbstractionStorage.php.

221 {
222 if (!$this->getFileSystemService()->has($this->path)) {
223 $this->getFileSystemService()->createDir($this->path);
224 }
225
226 if ($this->getStorageType() === self::STORAGE_DATA) {
227 return CLIENT_DATA_DIR . '/' . $this->path;
228 }
229 return CLIENT_WEB_DIR . '/' . $this->path;
230 }
const CLIENT_WEB_DIR
Definition: constants.php:45
const CLIENT_DATA_DIR
Definition: constants.php:44

References $path, CLIENT_DATA_DIR, CLIENT_WEB_DIR, getFileSystemService(), getStorageType(), and ILIAS\GlobalScreen\has().

Referenced by getAbsolutePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLegacyFullAbsolutePath()

ilFileSystemAbstractionStorage::getLegacyFullAbsolutePath (   $relative_path)
protected
Parameters
$relative_path
Returns
array|mixed|null

Definition at line 94 of file class.ilFileSystemAbstractionStorage.php.

95 {
96 $stream = $this->getFileSystemService()->readStream($relative_path);
97
98 return $stream->getMetadata('uri');
99 }

References getFileSystemService().

+ Here is the call graph for this function:

◆ getPath()

ilFileSystemAbstractionStorage::getPath ( )
Returns
string

Definition at line 418 of file class.ilFileSystemAbstractionStorage.php.

419 {
420 return $this->path;
421 }

References $path.

◆ getPathPostfix()

ilFileSystemAbstractionStorage::getPathPostfix ( )
abstractprotected

Get directory name.

E.g for files => file Only relative path, no trailing slash '_<obj_id>' will be appended automatically

@abstract @access protected

Returns
string directory name

Reimplemented in ilFSStorageFile, and ilFSStorageFile.

Referenced by init().

+ Here is the caller graph for this function:

◆ getPathPrefix()

ilFileSystemAbstractionStorage::getPathPrefix ( )
abstractprotected

Get path prefix.

Prefix that will be prepended to the path No trailing slash. E.g ilFiles for files

@abstract @access protected

Returns
string path prefix e.g files

Reimplemented in ilFSStorageFile, and ilFSStorageFile.

Referenced by init().

+ Here is the caller graph for this function:

◆ getStorageType()

ilFileSystemAbstractionStorage::getStorageType ( )
Returns
int

Definition at line 409 of file class.ilFileSystemAbstractionStorage.php.

References $storage_type.

Referenced by getFileSystemService(), and getLegacyAbsolutePath().

+ Here is the caller graph for this function:

◆ init()

ilFileSystemAbstractionStorage::init ( )
protected

Read path info.

@access private

Definition at line 238 of file class.ilFileSystemAbstractionStorage.php.

239 {
240 switch ($this->storage_type) {
243 break;
245 $this->path .= '/' . self::SECURED_DIRECTORY;
246 break;
247 }
248
249 // Append path prefix
250 $this->path .= ($this->getPathPrefix() . '/');
251
252 if ($this->path_conversion) {
253 $this->path .= self::_createPathFromId($this->container_id, $this->getPathPostfix());
254 } else {
255 $this->path .= ($this->getPathPostfix() . '_' . $this->container_id);
256 }
257
258 return true;
259 }
static _createPathFromId($a_container_id, $a_name)
Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5.
getPathPrefix()
Get path prefix.
getPathPostfix()
Get directory name.

References $container_id, _createPathFromId(), getPathPostfix(), getPathPrefix(), SECURED_DIRECTORY, STORAGE_DATA, STORAGE_SECURED, and STORAGE_WEB.

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeToFile()

ilFileSystemAbstractionStorage::writeToFile (   $a_data,
  $a_absolute_path 
)
Parameters
$a_data
$a_absolute_path
Returns
bool

Definition at line 268 of file class.ilFileSystemAbstractionStorage.php.

269 {
270 $relative_path = $this->createRelativePathForFileSystem($a_absolute_path);
271 try {
272 $this->getFileSystemService()->write($relative_path, $a_data);
273 } catch (Exception $e) {
274 return false;
275 }
276
277 return true;
278 }

References Vendor\Package\$e, createRelativePathForFileSystem(), and getFileSystemService().

+ Here is the call graph for this function:

Field Documentation

◆ $container_id

ilFileSystemAbstractionStorage::$container_id
private

Definition at line 43 of file class.ilFileSystemAbstractionStorage.php.

Referenced by getContainerId(), and init().

◆ $path

ilFileSystemAbstractionStorage::$path
protected

◆ $path_conversion

ilFileSystemAbstractionStorage::$path_conversion = false
private

Definition at line 45 of file class.ilFileSystemAbstractionStorage.php.

◆ $storage_type

ilFileSystemAbstractionStorage::$storage_type
private

Definition at line 44 of file class.ilFileSystemAbstractionStorage.php.

Referenced by getStorageType().

◆ FACTOR

const ilFileSystemAbstractionStorage::FACTOR = 100

Definition at line 40 of file class.ilFileSystemAbstractionStorage.php.

◆ MAX_EXPONENT

const ilFileSystemAbstractionStorage::MAX_EXPONENT = 3

Definition at line 41 of file class.ilFileSystemAbstractionStorage.php.

◆ SECURED_DIRECTORY

const ilFileSystemAbstractionStorage::SECURED_DIRECTORY = "sec"

Definition at line 42 of file class.ilFileSystemAbstractionStorage.php.

Referenced by getFileSystemService(), and init().

◆ STORAGE_DATA

const ilFileSystemAbstractionStorage::STORAGE_DATA = 2

Definition at line 38 of file class.ilFileSystemAbstractionStorage.php.

Referenced by getFileSystemService(), and init().

◆ STORAGE_SECURED

const ilFileSystemAbstractionStorage::STORAGE_SECURED = 3

Definition at line 39 of file class.ilFileSystemAbstractionStorage.php.

Referenced by init().

◆ STORAGE_WEB

const ilFileSystemAbstractionStorage::STORAGE_WEB = 1

Definition at line 37 of file class.ilFileSystemAbstractionStorage.php.

Referenced by getFileSystemService(), and init().


The documentation for this class was generated from the following file: