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