99namespace Engine \Utils ;
1010
1111
12- use Engine \Error \ShiftError ;
12+ use Engine \Error \StorageError ;
1313
1414class Storage {
1515
1616 public $ storageDir ;
1717 public $ storageViewsDir ;
1818
1919 public function __construct () {
20- $ this ->storageDir = realpath (__DIR__ . '/../storage/ ' );
20+ $ storageParentDir = realpath (__DIR__ . '/../ ' );
21+ $ this ->storageDir = $ storageParentDir . '/storage/ ' ;
2122 $ this ->storageViewsDir = $ this ->storageDir . '/views/ ' ;
22-
23- if (!file_exists ($ this ->storageDir )) {
24- throw new ShiftError ('Storage directory ' . $ this ->storageDir . ' does not exists ' );
25- }
26- if (!is_writable ($ this ->storageDir )) {
27- throw new ShiftError ('Storage directory ' . $ this ->storageDir . ' is not writable ' );
28- }
23+ $ this ->checkDir ($ this ->storageViewsDir );
2924 }
3025
3126 public function saveView (string $ name , string $ content ): void {
@@ -35,4 +30,16 @@ public function saveView(string $name, string $content): void {
3530
3631 file_put_contents ($ this ->storageViewsDir . $ name , $ content );
3732 }
33+
34+ private function checkDir (string $ dir ): void {
35+ if (!file_exists ($ dir )) {
36+ mkdir ($ dir , 0777 , true );
37+ }
38+ if (!file_exists ($ dir )) {
39+ throw new StorageError ('Directory ' . $ dir . ' does not exists ' );
40+ }
41+ if (!is_writable ($ dir )) {
42+ throw new StorageError ('Directory ' . $ dir . ' is not writable ' );
43+ }
44+ }
3845}
0 commit comments