blue-twilight/app/Providers/AppServiceProvider.php

60 lines
1.3 KiB
PHP

<?php
namespace App\Providers;
use App\Facade\Theme;
use App\Helpers\ThemeHelper;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->app->singleton('theme', function($app)
{
return new ThemeHelper();
});
try
{
$this->addThemeInfoToView();
}
catch (QueryException $ex)
{
// When running migrations, the configuration table may not exist - so ignore and continue
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
private function addThemeInfoToView()
{
$themeInfo = Theme::info();
// Add each theme info element to the view - prefixing with theme_
// e.g. $themeInfo['name'] becomes $theme_name in the view
foreach ($themeInfo as $key => $value)
{
View::share('theme_' . $key, $value);
}
// Also add a theme_url key
View::share('theme_url', sprintf('themes/%s', Theme::current()));
}
}