blue-twilight/app/Providers/AppServiceProvider.php

80 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Providers;
use App\Album;
use App\Helpers\ConfigHelper;
use App\Helpers\ImageHelper;
use App\Helpers\MiscHelper;
use App\Helpers\ThemeHelper;
use App\Helpers\ValidationHelper;
use App\Label;
use App\ModelObservers\AlbumObserver;
use App\ModelObservers\LabelObserver;
use Illuminate\Database\QueryException;
2016-09-06 14:19:16 +01:00
use Illuminate\Mail\Mailer;
2017-04-19 08:52:05 +01:00
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2017-04-19 08:52:05 +01:00
$themeHelper = new ThemeHelper();
$this->app->singleton('image', function ($app)
{
return new ImageHelper();
});
2017-04-19 08:52:05 +01:00
$this->app->singleton('theme', function ($app) use ($themeHelper)
{
2017-04-19 08:52:05 +01:00
return $themeHelper;
});
$this->app->singleton('user_config', function ($app)
{
return new ConfigHelper();
});
Validator::extend('is_dir', (ValidationHelper::class . '@directoryExists'));
Validator::extend('dir_empty', (ValidationHelper::class . '@isDirectoryEmpty'));
Validator::extend('is_writeable', (ValidationHelper::class . '@isPathWriteable'));
// Model observers
Album::observe(AlbumObserver::class);
Label::observe(LabelObserver::class);
2017-04-19 08:52:05 +01:00
// Configure our default pager
if (MiscHelper::isAppInstalled())
{
LengthAwarePaginator::defaultView($themeHelper->viewName('partials.pager_links'));
}
// Set base URL variable (used in both the main app and the installer)
$baseUrl = url('/');
if (!substr($baseUrl, strlen($baseUrl) - 1, 1) != '/')
{
$baseUrl .= '/';
}
View::share('appBaseUrl', $baseUrl);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}