publisher.php 1.16 KB
Newer Older
1 2
<?php namespace Laravel\CLI\Tasks\Bundle;

3
use Laravel\File;
4 5 6 7 8 9 10 11 12 13 14 15 16
use Laravel\Bundle;
use FilesystemIterator;

class Publisher {

	/**
	 * Publish a bundle's assets to the public directory.
	 *
	 * @param  string  $bundle
	 * @return void
	 */
	public function publish($bundle)
	{
17 18 19 20 21 22 23
		if ( ! Bundle::exists($bundle))
		{
			echo "Bundle [$bundle] is not registered.";

			return;
		}

24
		$path = Bundle::path($bundle);
25

Taylor Otwell committed
26
		$this->move($path.'public', path('public').'bundles'.DS.$bundle);
27

Taylor Otwell committed
28
		echo "Assets published for bundle [$bundle].".PHP_EOL;
29 30 31 32 33 34 35 36 37
	}

	/**
	 * Copy the contents of a bundle's assets to the public folder.
	 *
	 * @param  string  $source
	 * @param  string  $destination
	 * @return void
	 */
38
	protected function move($source, $destination)
39
	{
40
		File::cpdir($source, $destination);	
41 42 43 44 45 46 47 48 49 50
	}

	/**
	 * Get the "to" location of the bundle's assets.
	 *
	 * @param  string  $bundle
	 * @return string
	 */
	protected function to($bundle)
	{
Taylor Otwell committed
51
		return path('public').'bundles'.DS.$bundle.DS;
52 53 54 55 56 57 58 59 60 61 62 63 64 65
	}

	/**
	 * Get the "from" location of the bundle's assets.
	 *
	 * @param  string  $bundle
	 * @return string
	 */
	protected function from($bundle)
	{
		return Bundle::path($bundle).'public';
	}

}