provider.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php namespace Laravel\CLI\Tasks\Bundle\Providers;
  2. use Laravel\File;
  3. abstract class Provider {
  4. /**
  5. * Install the given bundle into the application.
  6. *
  7. * @param string $bundle
  8. * @param string $path
  9. * @return void
  10. */
  11. abstract public function install($bundle, $path);
  12. /**
  13. * Install a bundle from by downloading a Zip.
  14. *
  15. * @param string $url
  16. * @param array $bundle
  17. * @param string $path
  18. * @return void
  19. */
  20. protected function zipball($url, $bundle, $path)
  21. {
  22. $work = path('storage').'work/';
  23. // When installing a bundle from a Zip archive, we'll first clone
  24. // down the bundle zip into the bundles "working" directory so
  25. // we have a spot to do all of our bundle extration work.
  26. $target = $work.'laravel-bundle.zip';
  27. File::put($target, $this->download($url));
  28. $zip = new \ZipArchive;
  29. $zip->open($target);
  30. // Once we have the Zip archive, we can open it and extract it
  31. // into the working directory. By convention, we expect the
  32. // archive to contain one root directory, and all of the
  33. // bundle contents should be stored in that directory.
  34. $zip->extractTo($work);
  35. $latest = File::latest($work)->getRealPath();
  36. @chmod($latest, 0777);
  37. // Once we have the latest modified directory, we should be
  38. // able to move its contents over into the bundles folder
  39. // so the bundle will be usable by the develoepr.
  40. File::mvdir($latest, $path);
  41. @unlink($target);
  42. }
  43. /**
  44. * Download a remote zip archive from a URL.
  45. *
  46. * @param string $url
  47. * @return string
  48. */
  49. protected function download($url)
  50. {
  51. $remote = file_get_contents($url);
  52. // If we were unable to download the zip archive correctly
  53. // we'll bomb out since we don't want to extract the last
  54. // zip that was put in the storage directory.
  55. if ($remote === false)
  56. {
  57. throw new \Exception("Error downloading bundle [{$bundle}].");
  58. }
  59. return $remote;
  60. }
  61. }