provider.php 1.88 KB
Newer Older
1 2
<?php namespace Laravel\CLI\Tasks\Bundle\Providers;

3 4
use Laravel\File;

5
abstract class Provider {
6 7 8 9 10

	/**
	 * Install the given bundle into the application.
	 *
	 * @param  string  $bundle
11
	 * @param  string  $path
12 13
	 * @return void
	 */
14
	abstract public function install($bundle, $path);
15 16

	/**
17 18 19
	 * Install a bundle from by downloading a Zip.
	 *
	 * @param  string  $url
20 21
	 * @param  array   $bundle
	 * @param  string  $path
22 23
	 * @return void
	 */
24
	protected function zipball($url, $bundle, $path)
25
	{
26 27
		$work = path('storage').'work/';

28
		// When installing a bundle from a Zip archive, we'll first clone
Taylor Otwell committed
29
		// down the bundle zip into the bundles "working" directory so
30
		// we have a spot to do all of our bundle extration work.
31
		$target = $work.'laravel-bundle.zip';
32

33
		File::put($target, $this->download($url));
34 35 36 37 38 39 40

		$zip = new \ZipArchive;

		$zip->open($target);

		// Once we have the Zip archive, we can open it and extract it
		// 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 45 46
		$zip->extractTo($work.'zip');

		$latest = File::latest($work.'zip')->getRealPath();
47

Taylor Otwell committed
48
		@chmod($latest, 0777);
49

50 51 52
		// Once we have the latest modified directory, we should be
		// able to move its contents over into the bundles folder
		// so the bundle will be usable by the develoepr.
53
		File::mvdir($latest, $path);
54

55 56
		File::rmdir($work.'zip');

57
		@unlink($target);
58 59
	}

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
	/**
	 * Download a remote zip archive from a URL.
	 *
	 * @param  string  $url
	 * @return string
	 */
	protected function download($url)
	{
		$remote = file_get_contents($url);

		// If we were unable to download the zip archive correctly
		// we'll bomb out since we don't want to extract the last
		// zip that was put in the storage directory.
		if ($remote === false)
		{
			throw new \Exception("Error downloading bundle [{$bundle}].");
		}

		return $remote;
	}

81
}