fork download
  1. <?php
  2.  
  3. //namespace Util;
  4. //use DirectoryIterator;
  5.  
  6. class PostInstall {
  7.  
  8. static function install($paths)
  9. {
  10. $files = self::getAllFiles($paths);
  11. self::copy($files);
  12. }
  13.  
  14. static function getAllFiles($paths)
  15. {
  16. $result = [];
  17. foreach ($paths as $libName => $path) {
  18. $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS));
  19. foreach($files as $name => $object) {
  20. if (!empty($files->getSubPath())) {
  21. $folder = $libName . "/" . $files->getSubPath();
  22. } else {
  23. $folder = $libName;
  24. }
  25. $result[$folder][] = $name;
  26. }
  27. }
  28. return $result;
  29. }
  30.  
  31. static function copy($files)
  32. {
  33. foreach ($files as $libFolder => $libFiles)
  34. {
  35. $path = __DIR__ . "/../public/media/{$libFolder}";
  36. if (!is_dir($path)) {
  37. mkdir($path, 0700, true);
  38. }
  39. foreach ($libFiles as $file) {
  40. copy($file, $path . "/" . basename($file));
  41. }
  42. }
  43. }
  44. }
  45.  
  46. $paths = [
  47. 'videojs' => __DIR__ . '/../vendor/videojs/video.js/dist',
  48. 'bootstrap' => __DIR__ . '/../vendor/twbs/bootstrap/dist'
  49. ];
  50.  
  51. PostInstall::install($paths);
  52.  
Runtime error #stdin #stdout #stderr 0.02s 52472KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/home/5jTgYr/../vendor/videojs/video.js/dist): failed to open dir: No such file or directory' in /home/5jTgYr/prog.php:18
Stack trace:
#0 /home/5jTgYr/prog.php(18): RecursiveDirectoryIterator->__construct('/home/5jTgYr/.....', 4096)
#1 /home/5jTgYr/prog.php(10): PostInstall::getAllFiles(Array)
#2 /home/5jTgYr/prog.php(51): PostInstall::install(Array)
#3 {main}
  thrown in /home/5jTgYr/prog.php on line 18