| @@ 5-37 (lines=33) @@ | ||
| 2 | ||
| 3 | namespace Gitilicious\GitClient\FileSystem; |
|
| 4 | ||
| 5 | class Directory |
|
| 6 | { |
|
| 7 | private $path; |
|
| 8 | ||
| 9 | public function __construct(string $path) |
|
| 10 | { |
|
| 11 | if (!is_dir($path)) { |
|
| 12 | throw new NotFoundException(sprintf('The directory `%s` does not exist.', $path)); |
|
| 13 | } |
|
| 14 | ||
| 15 | $this->path = $path; |
|
| 16 | } |
|
| 17 | ||
| 18 | public static function create(string $path, int $permissions = 0770): Directory |
|
| 19 | { |
|
| 20 | if (is_dir($path)) { |
|
| 21 | throw new ExistsException(sprintf('The directory `%s` already exists.', $path)); |
|
| 22 | } |
|
| 23 | ||
| 24 | @mkdir($path, $permissions, true); |
|
| 25 | ||
| 26 | if (!is_dir($path)) { |
|
| 27 | throw new PermissionDeniedException(error_get_last()['message'], error_get_last()['type']); |
|
| 28 | } |
|
| 29 | ||
| 30 | return new self($path); |
|
| 31 | } |
|
| 32 | ||
| 33 | public function getPath(): string |
|
| 34 | { |
|
| 35 | return $this->path; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| @@ 5-37 (lines=33) @@ | ||
| 2 | ||
| 3 | namespace Gitilicious\GitClient\FileSystem; |
|
| 4 | ||
| 5 | class File |
|
| 6 | { |
|
| 7 | private $path; |
|
| 8 | ||
| 9 | public function __construct(string $path) |
|
| 10 | { |
|
| 11 | if (!is_file($path)) { |
|
| 12 | throw new NotFoundException(sprintf('The file `%s` does not exist.', $path)); |
|
| 13 | } |
|
| 14 | ||
| 15 | $this->path = $path; |
|
| 16 | } |
|
| 17 | ||
| 18 | public static function create(string $path, string $content): File |
|
| 19 | { |
|
| 20 | if (is_file($path)) { |
|
| 21 | throw new ExistsException(sprintf('The file `%s` already exists.', $path)); |
|
| 22 | } |
|
| 23 | ||
| 24 | @file_put_contents($path, $content); |
|
| 25 | ||
| 26 | if (!is_file($path)) { |
|
| 27 | throw new PermissionDeniedException(error_get_last()['message'], error_get_last()['type']); |
|
| 28 | } |
|
| 29 | ||
| 30 | return new self($path); |
|
| 31 | } |
|
| 32 | ||
| 33 | public function getPath(): string |
|
| 34 | { |
|
| 35 | return $this->path; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||