|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Aternos\Codex\Minecraft\Analysis\Solution\Folder; |
| 4 | + |
| 5 | +use Aternos\Codex\Minecraft\Analysis\Solution\File\FilePathType; |
| 6 | +use Aternos\Codex\Minecraft\Analysis\Solution\MinecraftSolution; |
| 7 | + |
| 8 | +abstract class FolderSolution extends MinecraftSolution |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @param string $path The relative path (without a starting slash) or absolute path to the folder. |
| 12 | + * If the path is relative, it will be treated as relative to the Minecraft server root directory. |
| 13 | + * @param FilePathType $type Is the path relative or absolute? |
| 14 | + */ |
| 15 | + public function __construct( |
| 16 | + protected string $path, |
| 17 | + protected FilePathType $type = FilePathType::RELATIVE |
| 18 | + ) |
| 19 | + { |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Set the relative path |
| 24 | + * The path is relative to the Minecraft server root directory without a starting slash |
| 25 | + * |
| 26 | + * @param string $path |
| 27 | + * @return $this |
| 28 | + */ |
| 29 | + public function setRelativePath(string $path): static |
| 30 | + { |
| 31 | + $this->path = $path; |
| 32 | + $this->type = FilePathType::RELATIVE; |
| 33 | + return $this; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Set the absolute path |
| 38 | + * |
| 39 | + * @param string $path |
| 40 | + * @return $this |
| 41 | + */ |
| 42 | + public function setAbsolutePath(string $path): static |
| 43 | + { |
| 44 | + $this->path = $path; |
| 45 | + $this->type = FilePathType::ABSOLUTE; |
| 46 | + return $this; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Get the path |
| 51 | + * If isRelative() the path is relative to the Minecraft server root directory without a starting slash |
| 52 | + * |
| 53 | + * @return string |
| 54 | + */ |
| 55 | + public function getPath(): string |
| 56 | + { |
| 57 | + return $this->path; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Get the type of the path (absolute or relative) |
| 62 | + * |
| 63 | + * @return FilePathType |
| 64 | + */ |
| 65 | + public function getType(): FilePathType |
| 66 | + { |
| 67 | + return $this->type; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Check if the path is relative |
| 72 | + * The path is relative to the Minecraft server root directory without a starting slash |
| 73 | + * |
| 74 | + * @return bool |
| 75 | + */ |
| 76 | + public function isRelative(): bool |
| 77 | + { |
| 78 | + return $this->getType() === FilePathType::RELATIVE; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Check if the path is absolute |
| 83 | + * |
| 84 | + * @return bool |
| 85 | + */ |
| 86 | + public function isAbsolutePath(): bool |
| 87 | + { |
| 88 | + return $this->getType() === FilePathType::ABSOLUTE; |
| 89 | + } |
| 90 | +} |
0 commit comments