File.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\FileReader;
  3. /**
  4. * Description of File
  5. *
  6. * @autor ThurData <info@thurdata.ch>
  7. */
  8. class File
  9. {
  10. public static function createFile()
  11. {
  12. // next version
  13. }
  14. public static function createPaths()
  15. {
  16. foreach (func_get_args() as $path)
  17. {
  18. if (is_array($path) && isset($path['permission']) && self::createPath($path['full'], $path['permission']) === false)
  19. {
  20. $parentPath = explode(DS, $path['full']);
  21. array_pop($pathFull);
  22. $parentPath = implode(DS, $parentPath);
  23. self::setPermission($parentPath);
  24. self::setUser($path['full'], 'www-data');
  25. self::createPath($path['full'], $path['permission']);
  26. }
  27. elseif (is_array($path) && self::createPath($path['full']) === false)
  28. {
  29. $parentPath = explode(DS, $path['full']);
  30. array_pop($pathFull);
  31. $parentPath = implode(DS, $parentPath);
  32. self::setPermission($parentPath);
  33. self::setUser($path['full'], 'www-data');
  34. self::createPath($path['full']);
  35. }
  36. else
  37. {
  38. self::createPath($path);
  39. }
  40. }
  41. }
  42. public static function createPath($path, $permission = 0777)
  43. {
  44. return mkdir($path, $permission);
  45. }
  46. public static function setPermission($file, $permission = 0777)
  47. {
  48. return chmod($file, $permission);
  49. }
  50. public static function setUser($file, $user)
  51. {
  52. return chown($file, $user);
  53. }
  54. /**
  55. * @return PathValidator
  56. */
  57. public static function getValidator()
  58. {
  59. return new PathValidator();
  60. }
  61. }