Permalink
Browse files

Upgraded laravel and all the bundles

  • Loading branch information...
ericbarnes committed Feb 8, 2012
1 parent c19f4d8 commit 58b4e1e2e85bd072e3b1fd2220dfd1acb269c376
View
@@ -1,5 +1,4 @@
*.DS_Store
-storage/views/
-storage/sessions/
utilities/
+application/config/staging/
application/config/production/
View
@@ -1,6 +0,0 @@
-[submodule "bundles/laravel-oauth2"]
- path = bundles/laravel-oauth2
- url = git://github.com/taylorotwell/laravel-oauth2.git
-[submodule "bundles/eloquent"]
- path = bundles/eloquent
- url = git://github.com/taylorotwell/eloquent.git
@@ -130,7 +130,10 @@
|
*/
- 'bundles' => array(),
+ 'bundle' => array(
+ 'cache' => 0,
+ 'auto' => array(),
+ ),
/*
|--------------------------------------------------------------------------
File renamed without changes.
View
@@ -1,41 +0,0 @@
-<?php
-
-/*
-|--------------------------------------------------------------------------
-| Bundle Configuration
-|--------------------------------------------------------------------------
-|
-| Bundles allow you to conveniently extend and organize your application.
-| Think of bundles as self-contained applications. They can have routes,
-| controllers, models, views, configuration, etc. You can even create
-| your own bundles to share with the Laravel community.
-|
-| This is a list of the bundles installed for your application and tells
-| Laravel the location of the bundle's root directory, as well as the
-| root URI the bundle responds to.
-|
-| For example, if you have an "admin" bundle located in "bundles/admin"
-| that you want to handle requests with URIs that begin with "admin",
-| simply add it to the array like this:
-|
-| 'admin' => array(
-| 'location' => 'admin',
-| 'handles' => 'admin',
-| ),
-|
-| Note that the "location" is relative to the "bundles" directory.
-| Now the bundle will be recognized by Laravel and will be able
-| to respond to requests beginning with "admin"!
-|
-| Have a bundle that lives in the root of the bundle directory
-| and doesn't respond to any requests? Just add the bundle
-| name to the array and we'll take care of the rest.
-|
-*/
-
-return array(
- 'eloquent',
- 'laravel-oauth2',
- 'github-api',
- 'markdown-extra-extended'
-);
@@ -1,6 +1,2 @@
<?php
-
-// Register the "namespace" with the auto-loader...
-Autoloader::underscored(array(
- 'Github' => __DIR__.DS.'lib'.DS.'Github',
-));
+return array('name' => 'github-api');
@@ -0,0 +1,5 @@
+<?php
+// Register the "namespace" with the auto-loader...
+Autoloader::underscored(array(
+ 'Github' => __DIR__.DS.'lib'.DS.'Github',
+));
View
@@ -1,5 +1,7 @@
<?php namespace Laravel; defined('DS') or die('No direct script access.');
+use FilesystemIterator as fIterator;
+
class Bundle {
/**
@@ -31,43 +33,103 @@ class Bundle {
public static $routed = array();
/**
- * Register a bundle for the application.
+ * The cache key for the bundle manifest.
*
- * @param string $bundle
- * @param mixed $config
- * @return void
+ * @var string
+ */
+ const manifest = 'laravel.bundle.manifest';
+
+ /**
+ * Detect all of the installed bundles from disk.
+ *
+ * @param string $path
+ * @return array
*/
- public static function register($bundle, $config = array())
+ public static function detect($path)
{
- $defaults = array('handles' => null, 'auto' => false);
+ return static::search($path);
+ }
- // If the given config is actually a string, we will assume it is a location
- // and convert it to an array so that the developer may conveniently add
- // bundles to the configuration without making an array for each one.
- if (is_string($config))
- {
- $config = array('location' => $config);
- }
+ /**
+ * Detect all of the installed bundles from disk.
+ *
+ * @param string $path
+ * @return array
+ */
+ protected static function search($path)
+ {
+ $bundles = array();
- if ( ! isset($config['location']))
+ $items = new fIterator($path);
+
+ foreach ($items as $item)
{
- $config['location'] = $bundle;
+ // If the item is a directory, we'll search for a bundle.info file.
+ // If one exists, we will add it to the bundle array. We will set
+ // the location automatically since we know it.
+ if ($item->isDir())
+ {
+ $path = $item->getRealPath().DS.'bundle.php';
+
+ // If we found a file, we'll require in the array it contains
+ // and add it to the directory. The info array will contain
+ // basic info like the bundle name and any URIs it may
+ // handle incoming requests for.
+ if (file_exists($path))
+ {
+ $info = require $path;
+
+ $info['location'] = dirname($path).DS;
+
+ $bundles[$info['name']] = $info;
+
+ continue;
+ }
+ // If a bundle.info file doesn't exist within a directory,
+ // we'll recurse into the directory to keep searching in
+ // the bundle directory for nested bundles.
+ else
+ {
+ $recurse = static::detect($item->getRealPath());
+
+ $bundles = array_merge($bundles, $recurse);
+ }
+ }
}
- // We will trim the trailing slash from the location and add it back so
- // we don't have to worry about the developer adding or not adding it
- // to the location path for the bundle.
- $config['location'] = path('bundle').rtrim($config['location'], DS).DS;
+ return $bundles;
+ }
+
+ /**
+ * Register a bundle for the application.
+ *
+ * @param array $config
+ * @return void
+ */
+ public static function register($config)
+ {
+ $defaults = array('handles' => null, 'auto' => false);
- // If the handles clause is set, we will append a trailing slash so
- // that it is not ultra-greedy. Otherwise, bundles that handle "s"
- // would handle all bundles that start with "s".
+ // If a handles clause has been specified, we will cap it with a trailing
+ // slash so the bundle is not extra greedy with its routes. Otherwise a
+ // bundle that handles "s" would handle all routes beginning with "s".
if (isset($config['handles']))
{
- $config['handles'] = $config['handles'].'/';
+ $config['handles'] = str_finish($config['handles'], '/');
}
- static::$bundles[$bundle] = array_merge($defaults, $config);
+ static::$bundles[$config['name']] = array_merge($defaults, $config);
+ }
+
+ /**
+ * Disable a bundle for the current request.
+ *
+ * @param string $bundle
+ * @return void
+ */
+ public static function disable($bundle)
+ {
+ unset(static::$bundles[$bundle]);
}
/**
@@ -82,7 +144,7 @@ public static function start($bundle)
{
if (static::started($bundle)) return;
- if ($bundle !== DEFAULT_BUNDLE and ! static::exists($bundle))
+ if ( ! static::exists($bundle))
{
throw new \Exception("Bundle [$bundle] has not been installed.");
}
@@ -91,7 +153,7 @@ public static function start($bundle)
// the bundle for use by the application. The start script may register any
// classes the bundle uses with the auto-loader, or perhaps will start any
// dependent bundles so that they are available.
- if (file_exists($path = static::path($bundle).'bundle'.EXT))
+ if (file_exists($path = static::path($bundle).'start'.EXT))
{
require $path;
}
@@ -2,7 +2,9 @@
use Laravel\IoC;
use Laravel\File;
+use Laravel\Cache;
use Laravel\Bundle;
+use Laravel\Request;
use Laravel\CLI\Tasks\Task;
class Bundler extends Task {
@@ -55,6 +57,8 @@ public function install($bundles)
echo "Bundle [{$bundle['name']}] has been installed!".PHP_EOL;
}
+
+ $this->refresh();
}
/**
@@ -76,32 +80,32 @@ public function upgrade($bundles)
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.
+ // First we want to retrieve the information for the bundle, such as
+ // where it is currently installed. This will allow us to upgrade
+ // the bundle into it's current installation path.
$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.
+ // 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 don't know the provider 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.
+ // Once we have the bundle information from the API, we'll simply
+ // recursively delete the bundle and then re-download it using
+ // the correct provider assigned to the bundle.
File::rmdir($bundle->location);
$this->download($response['bundle'], $bundle->location);
echo "Bundle [{$name}] has been upgraded!".PHP_EOL;
}
+
+ $this->refresh();
}
/**
@@ -112,17 +116,71 @@ public function upgrade($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 (count($bundles) == 0) $bundles = Bundle::names();
- $publisher = IoC::resolve('bundle.publisher');
+ array_walk($bundles, array(IoC::resolve('bundle.publisher'), 'publish'));
+ }
- foreach ($bundles as $bundle)
+ /**
+ * Create a new bundle stub.
+ *
+ * @param array $arguments
+ * @return void
+ */
+ public function make($arguments)
+ {
+ if ( ! isset($arguments[0]))
{
- $publisher->publish($bundle);
+ throw new \Exception("We need to know the bundle name!");
}
+
+ // First we'll grab the name from the argument list and make sure a bundle
+ // with that name doesn't already exist. If it does, we'll bomb out and
+ // notify the developer of the problem. Bundle names must be unique
+ // since classes are prefixed with the name.
+ $options['name'] = $name = $arguments[0];
+
+ if (Bundle::exists($name))
+ {
+ throw new \Exception("That bundle already exists!");
+ }
+
+ // The developer may specify a location to which the bundle should be
+ // installed. If a location is not specified, the bundle name will
+ // be used as the default installation location.
+ $location = Request::server('cli.location') ?: $name;
+
+ $location = path('bundle').$location;
+
+ $options['handles'] = Request::server('cli.handles');
+
+ // We'll create the actual PHP that should be inserted into the info
+ // file for the bundle. This contains the bundle's name as well as
+ // any URIs it is setup to handle.
+ $info = '<?php return '.var_export($options, true).';';
+
+ mkdir($location, 0777, true);
+
+ // Finally we can write the file to disk and clear the bundle cache.
+ // We clear the cache so that the new bundle will be recognized
+ // immediately and the developer can start using it.
+ File::put($location.DS.'bundle'.EXT, $info);
+
+ echo "Bundle [{$name}] has been created!".PHP_EOL;
+
+ $this->refresh();
+ }
+
+ /**
+ * Clear the bundle manifest cache.
+ *
+ * @return void
+ */
+ public function refresh()
+ {
+ Cache::forget(Bundle::manifest);
+
+ echo 'Bundle cache cleared!'.PHP_EOL;
}
/**
@@ -139,8 +197,7 @@ protected function get($bundles)
{
// 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.
+ // the bundle into the application.
$response = $this->retrieve($bundle);
if ($response['status'] == 'not-found')
Oops, something went wrong.

0 comments on commit 58b4e1e

Please sign in to comment.