|
4 | 4 |
|
5 | 5 | use Aternos\IO\Exception\MoveException;
|
6 | 6 | use Aternos\IO\Exception\PathOutsideElementException;
|
| 7 | +use Aternos\IO\Exception\StatException; |
| 8 | +use Aternos\IO\Exception\TouchException; |
7 | 9 | use Aternos\IO\Interfaces\Features\GetPathInterface;
|
8 | 10 | use Aternos\IO\System\Directory\Directory;
|
9 | 11 | use Aternos\IO\System\File\File;
|
@@ -134,6 +136,84 @@ public function exists(): bool
|
134 | 136 | return file_exists($this->path);
|
135 | 137 | }
|
136 | 138 |
|
| 139 | + /** |
| 140 | + * @inheritDoc |
| 141 | + * @throws StatException |
| 142 | + */ |
| 143 | + public function getAccessTimestamp(): int |
| 144 | + { |
| 145 | + $time = @fileatime($this->path); |
| 146 | + if ($time === false) { |
| 147 | + $error = error_get_last(); |
| 148 | + throw new StatException("Could not get access timestamp (" . $this->path . ")" . ($error ? ": " . $error["message"] : ""), $this); |
| 149 | + } |
| 150 | + return $time; |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * @inheritDoc |
| 155 | + * @throws StatException |
| 156 | + */ |
| 157 | + public function getModificationTimestamp(): int |
| 158 | + { |
| 159 | + $time = @filemtime($this->path); |
| 160 | + if ($time === false) { |
| 161 | + $error = error_get_last(); |
| 162 | + throw new StatException("Could not get modification timestamp (" . $this->path . ")" . ($error ? ": " . $error["message"] : ""), $this); |
| 163 | + } |
| 164 | + return $time; |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * @inheritDoc |
| 169 | + * @throws StatException |
| 170 | + */ |
| 171 | + public function getStatusChangeTimestamp(): int |
| 172 | + { |
| 173 | + $time = @filectime($this->path); |
| 174 | + if ($time === false) { |
| 175 | + $error = error_get_last(); |
| 176 | + throw new StatException("Could not get status change timestamp (" . $this->path . ")" . ($error ? ": " . $error["message"] : ""), $this); |
| 177 | + } |
| 178 | + return $time; |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * @inheritDoc |
| 183 | + * @throws TouchException |
| 184 | + * @throws StatException |
| 185 | + */ |
| 186 | + public function setAccessTimestamp(int $timestamp): static |
| 187 | + { |
| 188 | + if (!file_exists($this->path)) { |
| 189 | + throw new StatException("Could not set access timestamp because element does not exist (" . $this->path . ")", $this); |
| 190 | + } |
| 191 | + |
| 192 | + if (!@touch($this->path, $timestamp, $timestamp)) { |
| 193 | + $error = error_get_last(); |
| 194 | + throw new TouchException("Could not set access timestamp (" . $this->path . ")" . ($error ? ": " . $error["message"] : ""), $this); |
| 195 | + } |
| 196 | + return $this; |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * @inheritDoc |
| 201 | + * @throws TouchException |
| 202 | + * @throws StatException |
| 203 | + */ |
| 204 | + public function setModificationTimestamp(int $timestamp): static |
| 205 | + { |
| 206 | + if (!file_exists($this->path)) { |
| 207 | + throw new StatException("Could not set modification timestamp because element does not exist (" . $this->path . ")", $this); |
| 208 | + } |
| 209 | + |
| 210 | + if (!@touch($this->path, mtime: $timestamp)) { |
| 211 | + $error = error_get_last(); |
| 212 | + throw new TouchException("Could not set modification timestamp (" . $this->path . ")" . ($error ? ": " . $error["message"] : ""), $this); |
| 213 | + } |
| 214 | + return $this; |
| 215 | + } |
| 216 | + |
137 | 217 | /**
|
138 | 218 | * @return string[]
|
139 | 219 | */
|
|
0 commit comments