File.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\FileReader;
  3. /**
  4. * Description of File
  5. *
  6. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  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. if (!is_string($path) || file_exists($path)) {
  45. return;
  46. }
  47. return mkdir($path, $permission);
  48. }
  49. public static function setPermission($file, $permission = 0777)
  50. {
  51. return chmod($file, $permission);
  52. }
  53. public static function setUser($file, $user)
  54. {
  55. return chown($file, $user);
  56. }
  57. /**
  58. * @return PathValidator
  59. */
  60. public static function getValidator()
  61. {
  62. return new PathValidator();
  63. }
  64. }