provider.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 with the bundle.
  33. mkdir($work.'zip');
  34. $zip->extractTo($work.'zip');
  35. $latest = File::latest($work.'zip')->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. File::rmdir($work.'zip');
  42. @unlink($target);
  43. }
  44. /**
  45. * Download a remote zip archive from a URL.
  46. *
  47. * @param string $url
  48. * @return string
  49. */
  50. protected function download($url)
  51. {
  52. $remote = file_get_contents($url);
  53. // If we were unable to download the zip archive correctly
  54. // we'll bomb out since we don't want to extract the last
  55. // zip that was put in the storage directory.
  56. if ($remote === false)
  57. {
  58. throw new \Exception("Error downloading bundle [{$bundle}].");
  59. }
  60. return $remote;
  61. }
  62. }