2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2016-09-03 22:13:05 +01:00
|
|
|
use App\Album;
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-03 17:09:49 +01:00
|
|
|
use App\Helpers\ImageHelper;
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Helpers\ThemeHelper;
|
2016-09-02 21:27:50 +01:00
|
|
|
use Illuminate\Database\QueryException;
|
2016-09-02 10:42:05 +01:00
|
|
|
use Illuminate\Support\Facades\View;
|
2016-09-01 16:23:39 +01:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2016-09-03 17:09:49 +01:00
|
|
|
$this->app->singleton('image', function($app)
|
|
|
|
{
|
|
|
|
return new ImageHelper();
|
|
|
|
});
|
2016-09-02 10:42:05 +01:00
|
|
|
$this->app->singleton('theme', function($app)
|
|
|
|
{
|
|
|
|
return new ThemeHelper();
|
|
|
|
});
|
|
|
|
|
2016-09-03 22:13:05 +01:00
|
|
|
// When running migrations or CLI tasks, don't need to add things to the view
|
|
|
|
if (php_sapi_name() != 'cli')
|
2016-09-02 21:27:50 +01:00
|
|
|
{
|
|
|
|
$this->addThemeInfoToView();
|
2016-09-03 22:13:05 +01:00
|
|
|
$this->addAlbumsToView();
|
2016-09-02 21:27:50 +01:00
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
2016-09-02 10:42:05 +01:00
|
|
|
|
2016-09-03 22:13:05 +01:00
|
|
|
private function addAlbumsToView()
|
|
|
|
{
|
|
|
|
$albums = Album::all()->sortBy('name');
|
|
|
|
View::share('albums', $albums);
|
|
|
|
}
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
private function addThemeInfoToView()
|
|
|
|
{
|
|
|
|
$themeInfo = Theme::info();
|
|
|
|
|
2016-09-02 10:56:07 +01:00
|
|
|
// Add each theme info element to the view - prefixing with theme_
|
2016-09-02 10:42:05 +01:00
|
|
|
// e.g. $themeInfo['name'] becomes $theme_name in the view
|
2016-09-02 10:56:07 +01:00
|
|
|
foreach ($themeInfo as $key => $value)
|
2016-09-02 10:42:05 +01:00
|
|
|
{
|
2016-09-02 10:56:07 +01:00
|
|
|
View::share('theme_' . $key, $value);
|
2016-09-02 10:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Also add a theme_url key
|
|
|
|
View::share('theme_url', sprintf('themes/%s', Theme::current()));
|
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|