bundle improvements.
This commit is contained in:
parent
7052c33c37
commit
d76cf4ba23
|
@ -98,21 +98,6 @@
|
|||
|
||||
'timezone' => 'UTC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Bundles
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Bundles can provide a ton of awesome drop-in functionality for your web
|
||||
| application. Everything from Twitter integration to an admin backend.
|
||||
|
|
||||
| Here you may specify the bundles that should be automatically started
|
||||
| on every request to your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'bundles' => array(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Aliases
|
||||
|
|
|
@ -31,11 +31,21 @@ class Bundle {
|
|||
* @param string $handles
|
||||
* @return void
|
||||
*/
|
||||
public static function register($bundle, $location, $handles = null)
|
||||
public static function register($bundle, $config = array())
|
||||
{
|
||||
$location = BUNDLE_PATH.rtrim($location, DS).DS;
|
||||
$defaults = array('handles' => null, 'auto' => false);
|
||||
|
||||
static::$bundles[$bundle] = compact('location', 'handles');
|
||||
if ( ! isset($config['location']))
|
||||
{
|
||||
throw new \Exception("Location not set for bundle [$bundle]");
|
||||
}
|
||||
|
||||
// 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. This makes sure it is always there.
|
||||
$config['location'] = BUNDLE_PATH.rtrim($config['location'], DS).DS;
|
||||
|
||||
static::$bundles[$bundle] = array_merge($defaults, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +108,7 @@ public static function handles($uri)
|
|||
{
|
||||
foreach (static::$bundles as $key => $value)
|
||||
{
|
||||
if (starts_with($value['handles'], $uri)) return $key;
|
||||
if (starts_with($uri, $value['handles'])) return $key;
|
||||
}
|
||||
|
||||
return DEFAULT_BUNDLE;
|
||||
|
@ -112,7 +122,7 @@ public static function handles($uri)
|
|||
*/
|
||||
public static function exists($bundle)
|
||||
{
|
||||
return in_array(strtolower($bundle), static::all());
|
||||
return in_array(strtolower($bundle), static::names());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,11 +306,21 @@ public static function get($bundle)
|
|||
}
|
||||
|
||||
/**
|
||||
* Get all of the installed bundle names.
|
||||
* Get all of the installed bundles for the application.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function all()
|
||||
{
|
||||
return static::$bundles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the installed bundle names.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function names()
|
||||
{
|
||||
return array_keys(static::$bundles);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ 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::all();
|
||||
if (count($bundles) == 0) $bundles = Bundle::names();
|
||||
|
||||
$publisher = IoC::resolve('bundle.publisher');
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public function outstanding($bundle = null)
|
|||
// returned by "all" method on the Bundle class.
|
||||
if (is_null($bundle))
|
||||
{
|
||||
$bundles = array_merge(Bundle::all(), array('application'));
|
||||
$bundles = array_merge(Bundle::names(), array('application'));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -147,9 +147,7 @@
|
|||
*/
|
||||
$bundles = require BUNDLE_PATH.'bundles'.EXT;
|
||||
|
||||
foreach ($bundles as $key => $value)
|
||||
foreach ($bundles as $bundle => $config)
|
||||
{
|
||||
$location = (is_array($value)) ? $value['location'] : $value;
|
||||
|
||||
Bundle::register($key, $location, array_get($value, 'handles'));
|
||||
Bundle::register($bundle, $config);
|
||||
}
|
|
@ -143,9 +143,9 @@
|
|||
* array of auto-loaded bundles. This lets the developer have an
|
||||
* easy way to load bundles for every request.
|
||||
*/
|
||||
foreach (Config::get('application.bundles') as $bundle)
|
||||
foreach (Bundle::all() as $bundle => $config)
|
||||
{
|
||||
Bundle::start($bundle);
|
||||
if ($config['auto']) Bundle::start($bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,7 +101,7 @@ public static function find($name)
|
|||
// the bundle that are installed for the application.
|
||||
if (count(static::$names) == 0)
|
||||
{
|
||||
foreach (Bundle::all() as $bundle)
|
||||
foreach (Bundle::names() as $bundle)
|
||||
{
|
||||
Bundle::routes($bundle);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public static function find($name)
|
|||
}
|
||||
|
||||
/**
|
||||
* Search the routes for the route matching a request method and URI.
|
||||
* Search the routes for the route matching a method and URI.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $uri
|
||||
|
@ -206,13 +206,22 @@ protected static function match($destination)
|
|||
*/
|
||||
protected static function controller($bundle, $method, $destination, $segments)
|
||||
{
|
||||
// If there are no more segments in the URI, we will just create a route
|
||||
// for the default controller of the bundle, which is "home". We'll also
|
||||
// use the default method, which is "index".
|
||||
if (count($segments) == 0)
|
||||
{
|
||||
$uri = ($bundle == DEFAULT_BUNDLE) ? '/' : '/'.Bundle::get($bundle)->handles;
|
||||
$uri = '/';
|
||||
|
||||
// If the bundle is not the default bundle for the application, we'll
|
||||
// set the root URI as the root URI registered with the bundle in the
|
||||
// bundle configuration file for the application. It's registered in
|
||||
// the bundle configuration using the "handles" clause.
|
||||
if ($bundle !== DEFAULT_BUNDLE)
|
||||
{
|
||||
$uri = '/'.Bundle::get($bundle)->handles;
|
||||
}
|
||||
|
||||
// We'll generate a default "uses" clause for the route action that
|
||||
// points to the default controller and method for the bundle so
|
||||
// that the route will execute the default controller method.
|
||||
$action = array('uses' => Bundle::prefix($bundle).'home@index');
|
||||
|
||||
return new Route($method.' '.$uri, $action);
|
||||
|
|
Loading…
Reference in New Issue