mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
improving bundle workflow.
This commit is contained in:
parent
aa53dc70ce
commit
a11318863a
@ -21,7 +21,6 @@ return array(
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 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
|
||||
| this option to an empty string and we'll take care of the rest.
|
||||
|
|
||||
@ -73,13 +72,13 @@ return array(
|
||||
| SSL Link Generation
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Many sites use SSL to protect their users data. However, you may not
|
||||
| always be able to use SSL on your development machine, meaning all HTTPS
|
||||
| will be broken during development.
|
||||
| Many sites use SSL to protect their users data. However, you may not be
|
||||
| able to use SSL on your development machine, meaning all HTTPS will be
|
||||
| broken during development.
|
||||
|
|
||||
| For this reason, you may wish to disable the generation of HTTPS links
|
||||
| throughout your application. This option does just that. All attempts to
|
||||
| generate HTTPS links will generate regular HTTP links instead.
|
||||
| throughout your application. This option does just that. All attempts
|
||||
| to generate HTTPS links will generate regular HTTP links instead.
|
||||
|
|
||||
*/
|
||||
|
||||
@ -90,7 +89,7 @@ return array(
|
||||
| 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
|
||||
| to a distant star at warp speed.
|
||||
|
|
||||
@ -98,20 +97,41 @@ return array(
|
||||
|
||||
'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
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 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
|
||||
| referring to the class using its full namespace, you may simply use
|
||||
| the alias defined here.
|
||||
|
|
||||
| We have already aliased common Laravel classes to make life easier.
|
||||
|
|
||||
*/
|
||||
|
||||
'aliases' => array(
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php namespace Laravel; defined('DS') or die('No direct script access.');
|
||||
|
||||
use FilesystemIterator as fIterator;
|
||||
|
||||
class Bundle {
|
||||
|
||||
/**
|
||||
@ -30,44 +32,75 @@ class Bundle {
|
||||
*/
|
||||
public static $routed = array();
|
||||
|
||||
/**
|
||||
* Detect all of the installed bundles from disk.
|
||||
*
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
public static function detect($path)
|
||||
{
|
||||
$bundles = array();
|
||||
|
||||
$items = new fIterator($path);
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bundles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a bundle for the application.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @param mixed $config
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function register($bundle, $config = array())
|
||||
public static function register($config)
|
||||
{
|
||||
$defaults = array('handles' => null, 'auto' => false);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
if ( ! isset($config['location']))
|
||||
{
|
||||
$config['location'] = $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.
|
||||
$config['location'] = path('bundle').rtrim($config['location'], DS).DS;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +115,7 @@ class 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.");
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ Autoloader::namespaces(array('Laravel' => path('sys')));
|
||||
*/
|
||||
$bundles = Cache::remember('laravel.bundle.manifest', function()
|
||||
{
|
||||
return Bundle::detect();
|
||||
return Bundle::detect(path('bundle'));
|
||||
|
||||
}, Config::get('application.bundle.cache'));
|
||||
|
||||
|
@ -351,6 +351,18 @@ function str_contains($haystack, $needle)
|
||||
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.
|
||||
*
|
||||
|
1
storage/cache/.gitignore
vendored
1
storage/cache/.gitignore
vendored
@ -0,0 +1 @@
|
||||
laravel.bundle.manifest
|
Loading…
x
Reference in New Issue
Block a user