publisher.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php namespace Laravel\CLI\Tasks\Bundle;
  2. use Laravel\File;
  3. use Laravel\Bundle;
  4. use FilesystemIterator;
  5. class Publisher {
  6. /**
  7. * Publish a bundle's assets to the public directory.
  8. *
  9. * @param string $bundle
  10. * @return void
  11. */
  12. public function publish($bundle)
  13. {
  14. if ( ! Bundle::exists($bundle))
  15. {
  16. echo "Bundle [$bundle] is not registered.";
  17. return;
  18. }
  19. $path = Bundle::path($bundle);
  20. $this->move($path.'public', path('public').'bundles'.DS.$bundle);
  21. echo "Assets published for bundle [$bundle].".PHP_EOL;
  22. }
  23. /**
  24. * Copy the contents of a bundle's assets to the public folder.
  25. *
  26. * @param string $source
  27. * @param string $destination
  28. * @return void
  29. */
  30. protected function move($source, $destination)
  31. {
  32. File::cpdir($source, $destination);
  33. }
  34. /**
  35. * Get the "to" location of the bundle's assets.
  36. *
  37. * @param string $bundle
  38. * @return string
  39. */
  40. protected function to($bundle)
  41. {
  42. return path('public').'bundles'.DS.$bundle.DS;
  43. }
  44. /**
  45. * Get the "from" location of the bundle's assets.
  46. *
  47. * @param string $bundle
  48. * @return string
  49. */
  50. protected function from($bundle)
  51. {
  52. return Bundle::path($bundle).'public';
  53. }
  54. }