Skip to content

Commit

Permalink
Upgraded laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlbarnes committed Feb 6, 2012
1 parent 513dd89 commit cc4d457
Show file tree
Hide file tree
Showing 44 changed files with 515 additions and 211 deletions.
1 change: 0 additions & 1 deletion laravel/asset.php
Expand Up @@ -78,7 +78,6 @@ class Asset_Container {
* Create a new asset container instance.
*
* @param string $name
* @param HTML $html
* @return void
*/
public function __construct($name)
Expand Down
4 changes: 2 additions & 2 deletions laravel/autoloader.php
Expand Up @@ -183,8 +183,8 @@ public static function psr($directory)
/**
* Map namespaces to directories.
*
* @param string $namespace
* @param string $path
* @param array $mappings
* @return void
*/
public static function namespaces($mappings)
{
Expand Down
5 changes: 2 additions & 3 deletions laravel/bundle.php
Expand Up @@ -27,8 +27,7 @@ class Bundle {
* Register a bundle for the application.
*
* @param string $bundle
* @param string $location
* @param string $handles
* @param mixed $config Array of 'location', 'handles' and 'auto'; or string of location.
* @return void
*/
public static function register($bundle, $config = array())
Expand Down Expand Up @@ -111,7 +110,7 @@ public static function routes($bundle)
*
* If no bundle is assigned to handle the URI, the default bundle is returned.
*
* @param string $bundle
* @param string $uri
* @return string
*/
public static function handles($uri)
Expand Down
4 changes: 2 additions & 2 deletions laravel/cache.php
Expand Up @@ -23,7 +23,7 @@ class Cache {
* </code>
*
* @param string $driver
* @return Cache\Driver
* @return Cache\Drivers\Driver
*/
public static function driver($driver = null)
{
Expand All @@ -41,7 +41,7 @@ public static function driver($driver = null)
* Create a new cache driver instance.
*
* @param string $driver
* @return Driver
* @return Cache\Drivers\Driver
*/
protected static function factory($driver)
{
Expand Down
2 changes: 1 addition & 1 deletion laravel/cache/drivers/database.php
Expand Up @@ -101,7 +101,7 @@ public function forget($key)
/**
* Get a query builder for the database table.
*
* @return Query
* @return Laravel\Database\Query
*/
protected function table()
{
Expand Down
1 change: 0 additions & 1 deletion laravel/cache/drivers/driver.php
Expand Up @@ -23,7 +23,6 @@ abstract public function has($key);
*
* @param string $key
* @param mixed $default
* @param string $driver
* @return mixed
*/
public function get($key, $default = null)
Expand Down
4 changes: 2 additions & 2 deletions laravel/cache/drivers/redis.php
Expand Up @@ -5,14 +5,14 @@ class Redis extends Driver {
/**
* The Redis database instance.
*
* @var Redis
* @var Laravel\Redis
*/
protected $redis;

/**
* Create a new Redis cache driver instance.
*
* @param Redis $redis
* @param Laravel\Redis $redis
* @return void
*/
public function __construct(\Laravel\Redis $redis)
Expand Down
2 changes: 1 addition & 1 deletion laravel/cli/console.php
Expand Up @@ -6,7 +6,7 @@ class Console {
* Parse the command line arguments and return the results.
*
* @param array $argv
* @param array
* @return array
*/
public static function options($argv)
{
Expand Down
4 changes: 3 additions & 1 deletion laravel/cli/dependencies.php
Expand Up @@ -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);
});

/**
Expand Down
136 changes: 121 additions & 15 deletions laravel/cli/tasks/bundle/bundler.php
@@ -1,11 +1,30 @@
<?php namespace Laravel\CLI\Tasks\Bundle; defined('DS') or die('No direct script access.');

use Laravel\IoC;
use Laravel\File;
use Laravel\Bundle;
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.
*
Expand All @@ -16,7 +35,7 @@ public function install($bundles)
{
foreach ($this->get($bundles) as $bundle)
{
if (is_dir(path('bundle').$bundle['name']))
if (Bundle::exists($bundle['name']))
{
echo "Bundle {$bundle['name']} is already installed.";

Expand All @@ -30,9 +49,58 @@ 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']}";
$path = path('bundle').$this->path($bundle);

$this->download($bundle, $path);

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)
{
if (count($bundles) == 0) $bundles = Bundle::names();

foreach ($bundles as $name)
{
if ( ! Bundle::exists($name))
{
echo "Bundle [{$name}] is not installed!";

continue;
}

// First we want to retrieve the information for the bundle,
// such as where it is currently installed. This will let
// us upgrade the bundle into the same path in which it
// is already installed.
$bundle = Bundle::get($name);

// If the bundle exists, we will grab the data about the
// bundle from the API so we can make the right bundle
// provider for the bundle, since we have no way of
// knowing which provider was used to install.
$response = $this->retrieve($name);

if ($response['status'] == 'not-found')
{
continue;
}

// Once we have the bundle information from the API,
// we'll simply recursively delete the bundle and
// then re-download it using the provider.
File::rmdir($bundle->location);

IoC::resolve($provider)->install($bundle);
$this->download($response['bundle'], $bundle->location);

echo "Bundle [{$name}] has been upgraded!".PHP_EOL;
}
}

Expand All @@ -44,9 +112,9 @@ public function install($bundles)
*/
public function publish($bundles)
{
// If no bundles are passed to the command, we'll just gather all
// of the installed bundle names and publish the assets for each
// of the bundles to the public directory.
// If no bundles are passed to the command, we'll just gather
// all of the installed bundle names and publish the assets
// for each of the bundles to the public directory.
if (count($bundles) == 0) $bundles = Bundle::names();

$publisher = IoC::resolve('bundle.publisher');
Expand All @@ -67,20 +135,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')
{
Expand All @@ -95,10 +156,55 @@ protected function get($bundles)

$responses[] = $bundle;

$responses = array_merge($responses, $this->get($bundle['dependencies']));
$dependencies = $this->get($bundle['dependencies']);

$responses = array_merge($responses, $dependencies);
}

return $responses;
}

/**
* Install a bundle using a provider.
*
* @param string $bundle
* @param string $path
* @return void
*/
protected function download($bundle, $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']);
}

}
66 changes: 4 additions & 62 deletions laravel/cli/tasks/bundle/providers/github.php
@@ -1,77 +1,19 @@
<?php namespace Laravel\CLI\Tasks\Bundle\Providers;

use Laravel\Request;
<?php namespace Laravel\CLI\Tasks\Bundle\Providers; use Laravel\Request;

class Github extends Provider {

/**
* Install the given bundle into the application.
*
* @param string $bundle
* @param string $path
* @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)
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);
}

}

0 comments on commit cc4d457

Please sign in to comment.