blue-twilight/app/Providers/AppServiceProvider.php

76 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Providers;
use App\Album;
use App\Facade\Theme;
use App\Facade\UserConfig;
use App\Helpers\ConfigHelper;
use App\Helpers\ImageHelper;
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('image', function($app)
{
return new ImageHelper();
});
$this->app->singleton('theme', function($app)
{
return new ThemeHelper();
});
$this->app->singleton('user_config', function($app)
{
return new ConfigHelper();
});
// When running migrations or CLI tasks, don't need to add things to the view
if (php_sapi_name() != 'cli')
{
$this->addThemeInfoToView();
$this->addAlbumsToView();
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
private function addAlbumsToView()
{
$albums = Album::all()->sortBy('name');
View::share('albums', $albums);
}
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()));
}
}