Commit a1131886 authored by Taylor Otwell's avatar Taylor Otwell

improving bundle workflow.

parent aa53dc70
...@@ -21,7 +21,6 @@ return array( ...@@ -21,7 +21,6 @@ return array(
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| If you are including the "index.php" in your URLs, you can ignore this. | If you are including the "index.php" in your URLs, you can ignore this.
|
| However, if you are using mod_rewrite to get cleaner URLs, just set | However, if you are using mod_rewrite to get cleaner URLs, just set
| this option to an empty string and we'll take care of the rest. | this option to an empty string and we'll take care of the rest.
| |
...@@ -73,13 +72,13 @@ return array( ...@@ -73,13 +72,13 @@ return array(
| SSL Link Generation | SSL Link Generation
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Many sites use SSL to protect their users data. However, you may not | Many sites use SSL to protect their users data. However, you may not be
| always be able to use SSL on your development machine, meaning all HTTPS | able to use SSL on your development machine, meaning all HTTPS will be
| will be broken during development. | broken during development.
| |
| For this reason, you may wish to disable the generation of HTTPS links | For this reason, you may wish to disable the generation of HTTPS links
| throughout your application. This option does just that. All attempts to | throughout your application. This option does just that. All attempts
| generate HTTPS links will generate regular HTTP links instead. | to generate HTTPS links will generate regular HTTP links instead.
| |
*/ */
...@@ -90,7 +89,7 @@ return array( ...@@ -90,7 +89,7 @@ return array(
| Application Timezone | Application Timezone
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| The default timezone of your application. This timezone will be used when | The default timezone of your application. The timezone will be used when
| Laravel needs a date, such as when writing to a log file or travelling | Laravel needs a date, such as when writing to a log file or travelling
| to a distant star at warp speed. | to a distant star at warp speed.
| |
...@@ -98,20 +97,41 @@ return array( ...@@ -98,20 +97,41 @@ return array(
'timezone' => 'UTC', 'timezone' => 'UTC',
/*
|--------------------------------------------------------------------------
| Bundle Options
|--------------------------------------------------------------------------
|
| Here you may specify options related to application bundles, such as the
| amount of time the bundle manifest is cached. Each option is detailed
| below with suggestions for sensible values.
|
| Cache:
|
| All bundles have a "bundle.info" file which contains information such
| as the name of a bundle and the URIs it responds to. This value is
| the number of that bundle info is cached.
|
*/
'bundle' => array(
'cache' => 0,
),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Class Aliases | Class Aliases
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Here, you can specify any class aliases that you would like registered | Here, you can specify any class aliases that you would like registered
| when Laravel loads. Aliases are lazy-loaded, so add as many as you want. | when Laravel loads. Aliases are lazy-loaded, so feel free to add!
| |
| Aliases make it more convenient to use namespaced classes. Instead of | Aliases make it more convenient to use namespaced classes. Instead of
| referring to the class using its full namespace, you may simply use | referring to the class using its full namespace, you may simply use
| the alias defined here. | the alias defined here.
| |
| We have already aliased common Laravel classes to make life easier.
|
*/ */
'aliases' => array( 'aliases' => array(
......
<?php namespace Laravel; defined('DS') or die('No direct script access.'); <?php namespace Laravel; defined('DS') or die('No direct script access.');
use FilesystemIterator as fIterator;
class Bundle { class Bundle {
/** /**
...@@ -31,43 +33,74 @@ class Bundle { ...@@ -31,43 +33,74 @@ class Bundle {
public static $routed = array(); public static $routed = array();
/** /**
* Register a bundle for the application. * Detect all of the installed bundles from disk.
* *
* @param string $bundle * @param string $path
* @param mixed $config * @return array
* @return void
*/ */
public static function register($bundle, $config = array()) public static function detect($path)
{ {
$defaults = array('handles' => null, 'auto' => false); $bundles = array();
// If the given config is actually a string, we will assume it is a location $items = new fIterator($path);
// 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);
}
if ( ! isset($config['location'])) 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.info';
// 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 return $bundles;
// 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; /**
* 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 // If a handles clause has been specified, we will cap it with a trailing
// that it is not ultra-greedy. Otherwise, bundles that handle "s" // slash so the bundle is not extra greedy with its routes. Otherwise a
// would handle all bundles that start with "s". // bundle that handles "s" would handle all routes beginning with "s".
if (isset($config['handles'])) 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);
} }
/** /**
...@@ -82,7 +115,7 @@ class Bundle { ...@@ -82,7 +115,7 @@ class Bundle {
{ {
if (static::started($bundle)) return; 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."); throw new \Exception("Bundle [$bundle] has not been installed.");
} }
......
...@@ -53,7 +53,7 @@ Autoloader::namespaces(array('Laravel' => path('sys'))); ...@@ -53,7 +53,7 @@ Autoloader::namespaces(array('Laravel' => path('sys')));
*/ */
$bundles = Cache::remember('laravel.bundle.manifest', function() $bundles = Cache::remember('laravel.bundle.manifest', function()
{ {
return Bundle::detect(); return Bundle::detect(path('bundle'));
}, Config::get('application.bundle.cache')); }, Config::get('application.bundle.cache'));
......
...@@ -351,6 +351,18 @@ function str_contains($haystack, $needle) ...@@ -351,6 +351,18 @@ function str_contains($haystack, $needle)
return strpos($haystack, $needle) !== false; return strpos($haystack, $needle) !== false;
} }
/**
* Cap a string with a single instance of the given string.
*
* @param string $value
* @param string $cap
* @return string
*/
function str_finish($value, $cap)
{
return rtrim($value, $cap).$cap;
}
/** /**
* Return the value of the given item. * Return the value of the given item.
* *
......
laravel.bundle.manifest
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment