From ea42fe75f26dc74cc713cdfef725cc93637e7d86 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 3 Feb 2012 14:54:23 -0600 Subject: [PATCH] working on bundle upgrade routine. --- laravel/cli/dependencies.php | 4 +- laravel/cli/tasks/bundle/bundler.php | 106 ++++++++++++++++-- laravel/cli/tasks/bundle/providers/github.php | 66 +---------- .../cli/tasks/bundle/providers/provider.php | 27 ++--- 4 files changed, 113 insertions(+), 90 deletions(-) diff --git a/laravel/cli/dependencies.php b/laravel/cli/dependencies.php index 2a665b8e..3c6acc49 100644 --- a/laravel/cli/dependencies.php +++ b/laravel/cli/dependencies.php @@ -22,7 +22,9 @@ */ IoC::register('task: bundle', function() { - return new Tasks\Bundle\Bundler; + $repository = IoC::resolve('bundle.repository'); + + return new Tasks\Bundle\Bundler($repository); }); /** diff --git a/laravel/cli/tasks/bundle/bundler.php b/laravel/cli/tasks/bundle/bundler.php index b154fd11..937c0a81 100644 --- a/laravel/cli/tasks/bundle/bundler.php +++ b/laravel/cli/tasks/bundle/bundler.php @@ -6,6 +6,24 @@ class Bundler extends Task { + /** + * The bundle API repository. + * + * @var Repository + */ + protected $repository; + + /** + * Create a new bundle manager task. + * + * @param Repository $repository + * @return void + */ + public function __construct($repository) + { + $this->repository = $repository; + } + /** * Install the given bundles into the application. * @@ -30,9 +48,41 @@ public function install($bundles) // Each bundle provider implements the Provider interface and // is repsonsible for retrieving the bundle source from its // hosting party and installing it into the application. - $provider = "bundle.provider: {$bundle['provider']}"; + $this->download($bundle, $this->path($bundle)); - IoC::resolve($provider)->install($bundle); + echo "Bundle [{$bundle['name']}] has been installed!".PHP_EOL; + } + } + + /** + * Upgrade the given bundles for the application. + * + * @param array $bundles + * @return void + */ + public function upgrade($bundles) + { + foreach ($bundles as $name) + { + $bundle = Bundle::get($name); + + if (is_nulL($bundle)) + { + throw new \Exception("Bundle [{$name}] is not installed!"); + } + + $data = $this->retrieve($bundle); + + if ($response['status'] == 'not-found') + { + continue; + } + + File::rmdir($bundle->location); + + $this->download($bundle, $bundle->location); + + echo "Bundle [{$bundle['name']}] has been upgraded!".PHP_EOL; } } @@ -67,20 +117,13 @@ protected function get($bundles) { $responses = array(); - $repository = IoC::resolve('bundle.repository'); - foreach ($bundles as $bundle) { // First we'll call the bundle repository to gather the bundle data // array, which contains all of the information needed to install // the bundle into the application. We'll verify that the bundle // exists and the API is responding for each bundle. - $response = $repository->get($bundle); - - if ( ! $response) - { - throw new \Exception("The bundle API is not responding."); - } + $response = $this->retrieve($bundle); if ($response['status'] == 'not-found') { @@ -101,4 +144,47 @@ protected function get($bundles) return $responses; } + /** + * Install a bundle using a provider. + * + * @param string $bundle + * @param string $path + * @return void + */ + protected function download($bundlem, $path) + { + $provider = "bundle.provider: {$bundle['provider']}"; + + IoC::resolve($provider)->install($bundle, $path); + } + + /** + * Retrieve a bundle from the repository. + * + * @param string $bundle + * @return array + */ + protected function retrieve($bundle) + { + $response = $this->repository->get($bundle); + + if ( ! $response) + { + throw new \Exception("The bundle API is not responding."); + } + + return $response; + } + + /** + * Return the path for a given bundle. + * + * @param array $bundle + * @return string + */ + protected function path($bundle) + { + return array_get($bundle, 'path', $bundle['name']); + } + } \ No newline at end of file diff --git a/laravel/cli/tasks/bundle/providers/github.php b/laravel/cli/tasks/bundle/providers/github.php index 79e9df70..7aa34623 100644 --- a/laravel/cli/tasks/bundle/providers/github.php +++ b/laravel/cli/tasks/bundle/providers/github.php @@ -1,6 +1,4 @@ -$method($bundle); - } - - /** - * Install a Github hosted bundle from Zip. - * - * @param string $bundle - * @return void - */ - protected function zipball($bundle) + public function install($bundle, $path) { $url = "http://nodeload.github.com/{$bundle['location']}/zipball/master"; - parent::zipball($bundle, $url, true); - - echo "Bundle [{$bundle['name']}] has been installed!".PHP_EOL; - } - - /** - * Install a Github hosted bundle using submodules. - * - * @param string $bundle - * @return void - */ - protected function submodule($bundle) - { - $repository = "git@github.com:{$bundle['location']}.git"; - - $this->directory($bundle); - - // We need to just extract the basename of the bundle path when - // adding the submodule. Of course, we can't add a submodule to - // a location outside of the Git repository, so we don't need - // the full bundle path. - $root = basename(path('bundle')).'/'; - - passthru('git submodule add '.$repository.' '.$root.$this->path($bundle)); - - passthru('git submodule update'); - } - - /** - * Create the path to the bundle's dirname. - * - * @param array $bundle - * @return void - */ - protected function directory($bundle) - { - // If the installation target directory doesn't exist, we will create - // it recursively so that we can properly install the bundle to the - // correct path in the application. - $target = dirname(path('bundle').$this->path($bundle)); - - if ( ! is_dir($target)) - { - mkdir($target, 0777, true); - } + parent::zipball($url, $bundle, $path); } } \ No newline at end of file diff --git a/laravel/cli/tasks/bundle/providers/provider.php b/laravel/cli/tasks/bundle/providers/provider.php index d6a011ea..ffccf796 100644 --- a/laravel/cli/tasks/bundle/providers/provider.php +++ b/laravel/cli/tasks/bundle/providers/provider.php @@ -8,23 +8,27 @@ abstract class Provider { * Install the given bundle into the application. * * @param string $bundle + * @param string $path * @return void */ - abstract public function install($bundle); + abstract public function install($bundle, $path); /** * Install a bundle from by downloading a Zip. * - * @param array $bundle * @param string $url + * @param array $bundle + * @param string $path * @return void */ - protected function zipball($bundle, $url) + protected function zipball($url, $bundle, $path) { + $work = path('storage').'work/'; + // When installing a bundle from a Zip archive, we'll first clone // down the bundle zip into the bundles "working" directory so // we have a spot to do all of our bundle extration work. - $target = path('storage').'work/laravel-bundle.zip'; + $target = $work.'laravel-bundle.zip'; File::put($target, file_get_contents($url)); @@ -36,9 +40,9 @@ protected function zipball($bundle, $url) // into the working directory. By convention, we expect the // archive to contain one root directory, and all of the // bundle contents should be stored in that directory. - $zip->extractTo(path('storage').'work'); + $zip->extractTo($work); - $latest = File::latest(dirname($target))->getRealPath(); + $latest = File::latest($work)->getRealPath(); @chmod($latest, 0777); @@ -52,15 +56,4 @@ protected function zipball($bundle, $url) @unlink($target); } - /** - * Return the path for a given bundle. - * - * @param array $bundle - * @return string - */ - protected function path($bundle) - { - return array_get($bundle, 'path', $bundle['name']); - } - } \ No newline at end of file