Added lang and view loader events.
Added lang and view loader events similar to the configuration loader. Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
parent
32d4eeff14
commit
2331ae18cf
|
@ -47,6 +47,41 @@
|
||||||
|
|
||||||
Laravel\Autoloader::$aliases = $aliases;
|
Laravel\Autoloader::$aliases = $aliases;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Laravel View Loader
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The Laravel view loader is responsible for returning the full file path
|
||||||
|
| for the given bundle and view. Of course, a default implementation is
|
||||||
|
| provided to load views according to typical Laravel conventions but
|
||||||
|
| you may change this to customize how your views are organized.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
Event::listen(View::loader, function($bundle, $view)
|
||||||
|
{
|
||||||
|
return View::file($bundle, $view);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Laravel Language Loader
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The Laravel language loader is responsible for returning the array of
|
||||||
|
| language lines for a given bundle, language, and "file". A default
|
||||||
|
| implementation has been provided which uses the default language
|
||||||
|
| directories included with Laravel. However, you may tweak this
|
||||||
|
| method to laad your language arrays however you wish.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
Event::listen(Lang::loader, function($bundle, $language, $file)
|
||||||
|
{
|
||||||
|
return Lang::file($bundle, $language, $file);
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Set The Default Timezone
|
| Set The Default Timezone
|
||||||
|
|
|
@ -12,7 +12,7 @@ public static function exception($exception)
|
||||||
{
|
{
|
||||||
static::log($exception);
|
static::log($exception);
|
||||||
|
|
||||||
ob_end_clean();
|
ob_get_level() and ob_end_clean();
|
||||||
|
|
||||||
// If detailed errors are enabled, we'll just format the exception into
|
// If detailed errors are enabled, we'll just format the exception into
|
||||||
// a simple error message and display it on the screen. We don't use a
|
// a simple error message and display it on the screen. We don't use a
|
||||||
|
|
|
@ -32,6 +32,13 @@ class Lang {
|
||||||
*/
|
*/
|
||||||
protected static $lines = array();
|
protected static $lines = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The language loader event name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const loader = 'laravel.language.loader';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Lang instance.
|
* Create a new Lang instance.
|
||||||
*
|
*
|
||||||
|
@ -179,6 +186,26 @@ public static function load($bundle, $language, $file)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We use a "loader" event to delegate the loading of the language
|
||||||
|
// array, which allows the develop to organize the language line
|
||||||
|
// arrays for their application however they wish.
|
||||||
|
$lines = Event::first(static::loader, func_get_args());
|
||||||
|
|
||||||
|
static::$lines[$bundle][$language][$file] = $lines;
|
||||||
|
|
||||||
|
return count($lines) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a language array from a language file.
|
||||||
|
*
|
||||||
|
* @param string $bundle
|
||||||
|
* @param string $language
|
||||||
|
* @param string $file
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function file($bundle, $language, $file)
|
||||||
|
{
|
||||||
$lines = array();
|
$lines = array();
|
||||||
|
|
||||||
// Language files can belongs to the application or to any bundle
|
// Language files can belongs to the application or to any bundle
|
||||||
|
@ -191,12 +218,7 @@ public static function load($bundle, $language, $file)
|
||||||
$lines = require $path;
|
$lines = require $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All of the language lines are cached in an array so we can
|
return $lines;
|
||||||
// quickly look them up on subsequent reqwuests for the line.
|
|
||||||
// This keeps us from loading files each time.
|
|
||||||
static::$lines[$bundle][$language][$file] = $lines;
|
|
||||||
|
|
||||||
return count($lines) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -51,6 +51,13 @@ class View implements ArrayAccess {
|
||||||
*/
|
*/
|
||||||
public static $paths = array(DEFAULT_BUNDLE => array(''));
|
public static $paths = array(DEFAULT_BUNDLE => array(''));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Laravel view loader event name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const loader = 'laravel.view.loader';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Laravel view engine event name.
|
* The Laravel view engine event name.
|
||||||
*
|
*
|
||||||
|
@ -106,28 +113,40 @@ public function __construct($view, $data = array())
|
||||||
*/
|
*/
|
||||||
protected function path($view)
|
protected function path($view)
|
||||||
{
|
{
|
||||||
|
list($bundle, $view) = Bundle::parse($view);
|
||||||
|
|
||||||
$view = str_replace('.', '/', $view);
|
$view = str_replace('.', '/', $view);
|
||||||
|
|
||||||
$root = Bundle::path(Bundle::name($view)).'views/';
|
// We delegate the determination of view paths to the view loader
|
||||||
|
// event so that the developer is free to override and manage
|
||||||
|
// the loading views in any way they see fit.
|
||||||
|
$path = Event::first(static::loader, array($bundle, $view));
|
||||||
|
|
||||||
// We need to make sure that the view exists. If it doesn't, we will
|
if ( ! is_null($path))
|
||||||
// throw an exception since there is not any point in going further.
|
|
||||||
// If it does, we can just return the full view path.
|
|
||||||
$paths = array_get(static::$paths, Bundle::name($view), array(''));
|
|
||||||
|
|
||||||
foreach ($paths as $path)
|
|
||||||
{
|
{
|
||||||
foreach (static::$extensions as $ext)
|
return $path;
|
||||||
{
|
|
||||||
$file = $root.$path.Bundle::element($view).$ext;
|
|
||||||
|
|
||||||
if (file_exists($file)) return $file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception("View [$view] doesn't exist.");
|
throw new \Exception("View [$view] doesn't exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path to a view using the default folder convention.
|
||||||
|
*
|
||||||
|
* @param string $bundle
|
||||||
|
* @param string $view
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function file($bundle, $view)
|
||||||
|
{
|
||||||
|
$root = Bundle::path($bundle).'views/';
|
||||||
|
|
||||||
|
if (file_exists($path = $root.$view.EXT))
|
||||||
|
{
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new view instance.
|
* Create a new view instance.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue