1 | <?php |
||
16 | final class WritableFolder |
||
17 | { |
||
18 | /** @var bool */ |
||
19 | private $frozen; |
||
20 | |||
21 | /** @var FilesystemPath */ |
||
22 | private $folder; |
||
23 | |||
24 | /** |
||
25 | * @param string $folderPath |
||
26 | */ |
||
27 | 13 | public function __construct($folderPath) |
|
37 | |||
38 | public function __toString() |
||
39 | { |
||
40 | return $this->folder->getAbsolutePath(); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get the file path to this Folder in an OOP friendly way. |
||
45 | * |
||
46 | * @return FilesystemPath |
||
47 | */ |
||
48 | public function getFilesystemPath() |
||
49 | { |
||
50 | return new FilesystemPath($this->__toString()); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Set this Folder to a "frozen" state meaning its path can no longer be modified. |
||
55 | */ |
||
56 | 1 | public function freeze() |
|
60 | |||
61 | /** |
||
62 | * Check whether or not this Folder's path has been frozen. |
||
63 | * |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function isFrozen() |
||
70 | |||
71 | /** |
||
72 | * Set a base folder that will be prefixed before all file writes and copies. |
||
73 | * |
||
74 | * @param string $folderName |
||
75 | * |
||
76 | * @since 0.2.0 An \Exception is thrown when a frozen Folder is attempted to |
||
77 | * be modified |
||
78 | * @since 0.1.0 |
||
79 | * |
||
80 | * @throws \Exception |
||
81 | */ |
||
82 | public function setTargetDirectory($folderName) |
||
96 | |||
97 | /** |
||
98 | * Copy a file from an absolute file to a path relative to the Folder's location. |
||
99 | * |
||
100 | * @param string $absolutePath The absolute path of the file |
||
101 | * @param string $targetPath The relative file path to the Folder's location |
||
102 | * |
||
103 | * @since 0.1.0 |
||
104 | */ |
||
105 | public function copyFile($absolutePath, $targetPath) |
||
111 | |||
112 | /** |
||
113 | * Write a file with the specified content. |
||
114 | * |
||
115 | * @param string $relativePath The file path relative to this Folder's location |
||
116 | * @param string $content The content that will be written to the file |
||
117 | * |
||
118 | * @since 0.1.0 |
||
119 | * |
||
120 | * @return File |
||
121 | */ |
||
122 | 12 | public function writeFile($relativePath, $content) |
|
136 | } |
||
137 |