1<?php 2 3 4namespace ComboStrap; 5 6 7class FileSystems 8{ 9 10 static function exists(Path $path): bool 11 { 12 $scheme = $path->getScheme(); 13 switch ($scheme) { 14 case LocalFs::SCHEME: 15 return LocalFs::getOrCreate()->exists($path); 16 case DokuFs::SCHEME: 17 return DokuFs::getOrCreate()->exists($path); 18 default: 19 throw new ExceptionComboRuntime("File system ($scheme) unknown"); 20 } 21 } 22 23 public static function getContent(Path $path) 24 { 25 $scheme = $path->getScheme(); 26 switch ($scheme) { 27 case LocalFs::SCHEME: 28 return LocalFs::getOrCreate()->getContent($path); 29 case DokuFs::SCHEME: 30 return DokuFs::getOrCreate()->getContent($path); 31 } 32 throw new ExceptionComboRuntime("File system ($scheme) unknown"); 33 } 34 35 public static function getModifiedTime(Path $path): ?\DateTime 36 { 37 $scheme = $path->getScheme(); 38 switch ($scheme) { 39 case LocalFs::SCHEME: 40 return LocalFs::getOrCreate()->getModifiedTime($path); 41 case DokuFs::SCHEME: 42 return DokuFs::getOrCreate()->getModifiedTime($path); 43 default: 44 throw new ExceptionComboRuntime("File system ($scheme) unknown"); 45 } 46 47 } 48 49 public static function getCreationTime(Path $path) 50 { 51 $scheme = $path->getScheme(); 52 switch ($scheme) { 53 case LocalFs::SCHEME: 54 return LocalFs::getOrCreate()->getCreationTime($path); 55 case DokuFs::SCHEME: 56 return DokuFs::getOrCreate()->getCreationTime($path); 57 default: 58 throw new ExceptionComboRuntime("File system ($scheme) unknown"); 59 } 60 } 61 62 public static function deleteIfExists(Path $path) 63 { 64 if (FileSystems::exists($path)) { 65 FileSystems::delete($path); 66 } 67 } 68 69 public static function delete(Path $path) 70 { 71 $scheme = $path->getScheme(); 72 switch ($scheme) { 73 case LocalFs::SCHEME: 74 LocalFs::getOrCreate()->delete($path); 75 return; 76 case DokuFs::SCHEME: 77 DokuFs::getOrCreate()->delete($path); 78 return; 79 default: 80 throw new ExceptionComboRuntime("File system ($scheme) unknown"); 81 } 82 } 83 84 public static function getSize(Path $path) 85 { 86 87 $scheme = $path->getScheme(); 88 switch ($scheme) { 89 case LocalFs::SCHEME: 90 return LocalFs::getOrCreate()->getSize($path); 91 case DokuFs::SCHEME: 92 return DokuFs::getOrCreate()->getSize($path); 93 default: 94 throw new ExceptionComboRuntime("File system ($scheme) unknown"); 95 } 96 } 97 98 99 /** 100 * @throws ExceptionCombo 101 */ 102 public static function createDirectory(Path $dirPath) 103 { 104 $scheme = $dirPath->getScheme(); 105 switch ($scheme) { 106 case LocalFs::SCHEME: 107 return LocalFs::getOrCreate()->createDirectory($dirPath); 108 case DokuFs::SCHEME: 109 return DokuFs::getOrCreate()->createDirectory($dirPath); 110 default: 111 throw new ExceptionComboRuntime("File system ($scheme) unknown"); 112 } 113 } 114} 115