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