mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 00:27:30 +00:00
Make it easier to switch between v1/v2 layout.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
@@ -56,6 +57,7 @@ if (!function_exists('str_is_equal')) {
|
||||
/**
|
||||
* @param string $left
|
||||
* @param string $right
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function str_is_equal(string $left, string $right): bool
|
||||
@@ -64,6 +66,41 @@ if (!function_exists('str_is_equal')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('prefixView')) {
|
||||
/**
|
||||
* Get the evaluated view contents for the given view.
|
||||
*
|
||||
* @param string|null $view
|
||||
* @param \Illuminate\Contracts\Support\Arrayable|array $data
|
||||
* @param array $mergeData
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
function prefixView($view = null, $data = [], $mergeData = [])
|
||||
{
|
||||
$factory = app(ViewFactory::class);
|
||||
|
||||
if (func_num_args() === 0) {
|
||||
return $factory;
|
||||
}
|
||||
$prefixView = $view;
|
||||
if (
|
||||
true === env('APP_DEBUG', false)
|
||||
&& null !== $view
|
||||
&& is_string($view)) {
|
||||
// do something with view:
|
||||
$layout = env('FIREFLY_III_LAYOUT', 'v1');
|
||||
$prefixView = sprintf('%s/%s', $layout, $view);
|
||||
if(false ===$factory->exists($view)) {
|
||||
// fall back to v1.
|
||||
$prefixView = sprintf('%s/%s', 'v1', $view);
|
||||
}
|
||||
}
|
||||
|
||||
return $factory->make($prefixView, $data, $mergeData);
|
||||
}
|
||||
}
|
||||
|
||||
$app = new Illuminate\Foundation\Application(
|
||||
realpath(__DIR__ . '/../')
|
||||
);
|
||||
|
Reference in New Issue
Block a user