ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
FileSystemStorageHandler.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
14
24{
25 const BASE = "storage";
26 const DATA = 'data';
30 private $fs;
34 private $id;
35
36
40 public function __construct()
41 {
42 global $DIC;
43 $this->fs = $DIC->filesystem()->storage();
44 $this->id = new UniqueIDIdentificationGenerator();
45 }
46
47
51 public function getID() : string
52 {
53 return 'fsv1';
54 }
55
56
61 {
62 return $this->id;
63 }
64
65
66 public function has(ResourceIdentification $identification) : bool
67 {
68 return $this->fs->has($this->getBasePath($identification));
69 }
70
71
75 public function getStream(Revision $revision) : FileStream
76 {
77 return $this->fs->readStream($this->getRevisionPath($revision) . '/' . self::DATA);
78 }
79
80
81 public function storeUpload(UploadedFileRevision $revision) : bool
82 {
83 global $DIC;
84
85 $DIC->upload()->moveOneFileTo($revision->getUpload(), $this->getRevisionPath($revision), Location::STORAGE, self::DATA);
86
87 return true;
88 }
89
90
94 public function deleteRevision(Revision $revision) : void
95 {
96 $this->fs->deleteDir($this->getRevisionPath($revision));
97 }
98
99
103 public function deleteResource(StorableResource $resource) : void
104 {
105 $this->fs->deleteDir($this->getBasePath($resource->getIdentification()));
106 }
107
108
109 private function getBasePath(ResourceIdentification $identification) : string
110 {
111 return self::BASE . '/' . str_replace("-", "/", $identification->serialize());
112 }
113
114
115 private function getRevisionPath(Revision $revision) : string
116 {
117 return $this->getBasePath($revision->getIdentification()) . '/' . $revision->getVersionNumber();
118 }
119}
An exception for terminatinating execution or to throw for unit testing.
Interface Location.
Definition: Location.php:17
const STORAGE
The filesystem outside of the ilias web root.
Definition: Location.php:28
Interface Filesystem.
Definition: Filesystem.php:27
$DIC
Definition: xapitoken.php:46