bundler.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php namespace Laravel\CLI\Tasks\Bundle; isset($GLOBALS['APP_PATH']) or die('No direct script access.');
  2. use Laravel\IoC;
  3. use Laravel\Bundle;
  4. use Laravel\CLI\Tasks\Task;
  5. class Bundler extends Task {
  6. /**
  7. * Install the given bundles into the application.
  8. *
  9. * @param array $bundles
  10. * @return void
  11. */
  12. public function install($bundles)
  13. {
  14. foreach ($this->get($bundles) as $bundle)
  15. {
  16. if (is_dir($GLOBALS['BUNDLE_PATH'].$bundle['name']))
  17. {
  18. echo "Bundle {$bundle['name']} is already installed.";
  19. continue;
  20. }
  21. // Once we have the bundle information, we can resolve an instance
  22. // of a provider and install the bundle into the application and
  23. // all of its registered dependencies as well.
  24. //
  25. // Each bundle provider implements the Provider interface and
  26. // is repsonsible for retrieving the bundle source from its
  27. // hosting party and installing it into the application.
  28. $provider = "bundle.provider: {$bundle['provider']}";
  29. IoC::resolve($provider)->install($bundle);
  30. }
  31. }
  32. /**
  33. * Publish bundle assets to the public directory.
  34. *
  35. * @param array $bundles
  36. * @return void
  37. */
  38. public function publish($bundles)
  39. {
  40. // If no bundles are passed to the command, we'll just gather all
  41. // of the installed bundle names and publish the assets for each
  42. // of the bundles to the public directory.
  43. if (count($bundles) == 0) $bundles = Bundle::names();
  44. $publisher = IoC::resolve('bundle.publisher');
  45. foreach ($bundles as $bundle)
  46. {
  47. $publisher->publish($bundle);
  48. }
  49. }
  50. /**
  51. * Gather all of the bundles from the bundle repository.
  52. *
  53. * @param array $bundles
  54. * @return array
  55. */
  56. protected function get($bundles)
  57. {
  58. $responses = array();
  59. $repository = IoC::resolve('bundle.repository');
  60. foreach ($bundles as $bundle)
  61. {
  62. // First we'll call the bundle repository to gather the bundle data
  63. // array, which contains all of the information needed to install
  64. // the bundle into the application. We'll verify that the bundle
  65. // exists and the API is responding for each bundle.
  66. $response = $repository->get($bundle);
  67. if ( ! $response)
  68. {
  69. throw new \Exception("The bundle API is not responding.");
  70. }
  71. if ($response['status'] == 'not-found')
  72. {
  73. throw new \Exception("There is not a bundle named [$bundle].");
  74. }
  75. // If the bundle was retrieved successfully, we will add it to
  76. // our array of bundles, as well as merge all of the bundle's
  77. // dependencies into the array of responses so that they are
  78. // installed along with the consuming dependency.
  79. $bundle = $response['bundle'];
  80. $responses[] = $bundle;
  81. $responses = array_merge($responses, $this->get($bundle['dependencies']));
  82. }
  83. return $responses;
  84. }
  85. }