tweaking github provider.

This commit is contained in:
Taylor Otwell 2012-02-02 13:46:33 -06:00
parent a6c083f311
commit 14ab7c4e05
2 changed files with 61 additions and 13 deletions

View File

@ -1,6 +1,6 @@
<?php namespace Laravel\CLI\Tasks\Bundle\Providers;
class Github implements Provider {
class Github extends Provider {
/**
* Install the given bundle into the application.
@ -9,18 +9,36 @@ class Github implements Provider {
* @return void
*/
public function install($bundle)
{
$method = (Request::server('cli.zip')) ? 'zipball' : 'submodule';
$this->$method($bundle);
}
/**
* Install a Github hosted bundle from Zip.
*
* @param string $bundle
* @return void
*/
protected function zipball($bundle)
{
$zip = "https://github.com/{$bundle['location']}/zipball/master";
parent::zipball($zip, true);
}
/**
* Install a Github hosted bundle using submodules.
*
* @param string $bundle
* @return void
*/
protected function submodule($bundle)
{
$repository = "git@github.com:{$bundle['location']}.git";
$path = array_get($bundle, 'path', $bundle['name']);
// If the installation target directory doesn't exist, we will create
// it recursively so that we can properly add the Git submodule for
// the bundle when we install.
if ( ! is_dir($target = dirname(path('bundle').$path)))
{
mkdir($target, 0777, true);
}
$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
@ -28,7 +46,7 @@ public function install($bundle)
// the full bundle path.
$root = basename(path('bundle')).'/';
passthru('git submodule add '.$repository.' '.$root.$path);
passthru('git submodule add '.$repository.' '.$root.$this->path($bundle));
passthru('git submodule update');
}

View File

@ -1,6 +1,6 @@
<?php namespace Laravel\CLI\Tasks\Bundle\Providers;
interface Provider {
abstract class Provider {
/**
* Install the given bundle into the application.
@ -8,6 +8,36 @@ interface Provider {
* @param string $bundle
* @return void
*/
public function install($bundle);
abstract public function install($bundle);
/**
* 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);
}
}
/**
* Return the path for a given bundle.
*
* @param array $bundle
* @return string
*/
protected function path($bundle)
{
return array_get($bundle, 'path', $bundle['name']);
}
}