Просмотр файла app/Classes/Mix.php

Размер файла: 1.55Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Classes;
  6.  
  7. use Exception;
  8. use Illuminate\Support\Str;
  9.  
  10. class Mix
  11. {
  12. /**
  13. * Get the path to a versioned Mix file.
  14. *
  15. * @param string $path
  16. * @param string $manifestDirectory
  17. *
  18. * @return string
  19. * @throws Exception
  20. */
  21. public function __invoke(string $path, string $manifestDirectory = '')
  22. {
  23. static $manifests = [];
  24.  
  25. if (! Str::startsWith($path, '/')) {
  26. $path = "/{$path}";
  27. }
  28.  
  29. if ($manifestDirectory && ! Str::startsWith($manifestDirectory, '/')) {
  30. $manifestDirectory = "/{$manifestDirectory}";
  31. }
  32.  
  33. if (file_exists(HOME . $manifestDirectory . '/hot')) {
  34. $url = rtrim(file_get_contents(HOME . $manifestDirectory.'/hot'));
  35.  
  36. if (Str::startsWith($url, ['http://', 'https://'])) {
  37. return Str::after($url, ':') . $path;
  38. }
  39.  
  40. return "//localhost:8080{$path}";
  41. }
  42.  
  43. $manifestPath = HOME . $manifestDirectory.'/mix-manifest.json';
  44.  
  45. if (! isset($manifests[$manifestPath])) {
  46. if (! file_exists($manifestPath)) {
  47. throw new Exception('The Mix manifest does not exist.');
  48. }
  49.  
  50. $manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);
  51. }
  52.  
  53. $manifest = $manifests[$manifestPath];
  54.  
  55. if (! isset($manifest[$path])) {
  56. throw new Exception("Unable to locate Mix file: {$path}.");
  57. }
  58.  
  59. return $manifestDirectory . $manifest[$path];
  60. }
  61. }