publisher.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. * Delete a bundle's assets from the public directory
  25. *
  26. * @param string $bundle
  27. * @return void
  28. */
  29. public function unpublish($bundle)
  30. {
  31. if ( ! Bundle::exists($bundle))
  32. {
  33. echo "Bundle [$bundle] is not registered.";
  34. return;
  35. }
  36. File::rmdir(path('public').'bundles'.DS.$bundle);
  37. echo "Assets deleted for bundle [$bundle].".PHP_EOL;
  38. }
  39. /**
  40. * Copy the contents of a bundle's assets to the public folder.
  41. *
  42. * @param string $source
  43. * @param string $destination
  44. * @return void
  45. */
  46. protected function move($source, $destination)
  47. {
  48. File::cpdir($source, $destination);
  49. }
  50. /**
  51. * Get the "to" location of the bundle's assets.
  52. *
  53. * @param string $bundle
  54. * @return string
  55. */
  56. protected function to($bundle)
  57. {
  58. return path('public').'bundles'.DS.$bundle.DS;
  59. }
  60. /**
  61. * Get the "from" location of the bundle's assets.
  62. *
  63. * @param string $bundle
  64. * @return string
  65. */
  66. protected function from($bundle)
  67. {
  68. return Bundle::path($bundle).'public';
  69. }
  70. }