1: <?php namespace Laravel\CLI\Tasks\Bundle;
2:
3: use Laravel\File;
4: use Laravel\Bundle;
5: use FilesystemIterator;
6:
7: class Publisher {
8:
9: /**
10: * Publish a bundle's assets to the public directory.
11: *
12: * @param string $bundle
13: * @return void
14: */
15: public function publish($bundle)
16: {
17: if ( ! Bundle::exists($bundle))
18: {
19: echo "Bundle [$bundle] is not registered.";
20:
21: return;
22: }
23:
24: $path = Bundle::path($bundle);
25:
26: $this->move($path.'public', path('public').'bundles'.DS.$bundle);
27:
28: echo "Assets published for bundle [$bundle].".PHP_EOL;
29: }
30:
31: /**
32: * Delete a bundle's assets from the public directory
33: *
34: * @param string $bundle
35: * @return void
36: */
37: public function unpublish($bundle)
38: {
39: if ( ! Bundle::exists($bundle))
40: {
41: echo "Bundle [$bundle] is not registered.";
42:
43: return;
44: }
45:
46: File::rmdir(path('public').'bundles'.DS.$bundle);
47:
48: echo "Assets deleted for bundle [$bundle].".PHP_EOL;
49: }
50:
51: /**
52: * Copy the contents of a bundle's assets to the public folder.
53: *
54: * @param string $source
55: * @param string $destination
56: * @return void
57: */
58: protected function move($source, $destination)
59: {
60: File::cpdir($source, $destination);
61: }
62:
63: /**
64: * Get the "to" location of the bundle's assets.
65: *
66: * @param string $bundle
67: * @return string
68: */
69: protected function to($bundle)
70: {
71: return path('public').'bundles'.DS.$bundle.DS;
72: }
73:
74: /**
75: * Get the "from" location of the bundle's assets.
76: *
77: * @param string $bundle
78: * @return string
79: */
80: protected function from($bundle)
81: {
82: return Bundle::path($bundle).'public';
83: }
84:
85: }