working on bundle upgrade routine.
This commit is contained in:
@@ -6,6 +6,24 @@ use Laravel\CLI\Tasks\Task;
|
||||
|
||||
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 @@ class Bundler extends Task {
|
||||
// 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 @@ class Bundler extends Task {
|
||||
{
|
||||
$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 @@ class Bundler extends Task {
|
||||
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']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user