Files
librenms-librenms/app/Providers/AppServiceProvider.php
T

112 lines
3.7 KiB
PHP
Raw Normal View History

2018-05-09 08:05:17 -05:00
<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Relations\Relation;
2018-05-09 08:05:17 -05:00
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use LibreNMS\Config;
use LibreNMS\Exceptions\DatabaseConnectException;
2018-09-11 07:51:35 -05:00
use Request;
2018-05-09 08:05:17 -05:00
include_once __DIR__ . '/../../includes/dbFacile.php';
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2018-08-17 15:29:20 -05:00
// Install legacy dbFacile fetch mode listener
\LibreNMS\DB\Eloquent::initLegacyListeners();
2018-05-09 08:05:17 -05:00
// load config
Config::load();
// replace early boot logging redirect log to config location, unless APP_LOG is set
2018-07-13 17:08:00 -05:00
Log::getMonolog()->popHandler(); // remove existing errorlog logger
Log::useFiles(config('app.log') ?: Config::get('log_file', base_path('logs/librenms.log')), 'error');
2018-05-09 08:05:17 -05:00
// Blade directives (Yucky because of < L5.5)
Blade::directive('config', function ($key) {
return "<?php if (\LibreNMS\Config::get(($key))): ?>";
});
Blade::directive('notconfig', function ($key) {
return "<?php if (!\LibreNMS\Config::get(($key))): ?>";
});
Blade::directive('endconfig', function () {
return "<?php endif; ?>";
});
Blade::directive('admin', function () {
return "<?php if (auth()->check() && auth()->user()->isAdmin()): ?>";
});
Blade::directive('endadmin', function () {
return "<?php endif; ?>";
});
$this->configureMorphAliases();
2018-05-09 08:05:17 -05:00
// Development service providers
if ($this->app->environment() !== 'production') {
if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
if (config('app.debug') && class_exists(\Barryvdh\Debugbar\ServiceProvider::class)) {
2018-09-11 07:51:35 -05:00
// disable debugbar for api routes
if (!Request::is('api/*')) {
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
}
2018-05-09 08:05:17 -05:00
}
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->registerGeocoder();
2018-05-09 08:05:17 -05:00
}
private function configureMorphAliases()
{
Relation::morphMap([
'interface' => \App\Models\Port::class,
'sensor' => \App\Models\Sensor::class,
2019-01-03 16:42:12 -06:00
'device' => \App\Models\Device::class,
'device_group' => \App\Models\DeviceGroup::class,
]);
}
private function registerGeocoder()
{
$this->app->alias(\LibreNMS\Interfaces\Geocoder::class, 'geocoder');
$this->app->bind(\LibreNMS\Interfaces\Geocoder::class, function ($app) {
$engine = Config::get('geoloc.engine');
switch ($engine) {
case 'mapquest':
Log::debug('MapQuest geocode engine');
return $app->make(\App\ApiClients\MapquestApi::class);
case 'bing':
Log::debug('Bing geocode engine');
return $app->make(\App\ApiClients\BingApi::class);
case 'openstreetmap':
Log::debug('OpenStreetMap geocode engine');
return $app->make(\App\ApiClients\NominatimApi::class);
default:
case 'google':
Log::debug('Google Maps geocode engine');
return $app->make(\App\ApiClients\GoogleMapsApi::class);
}
});
}
2018-05-09 08:05:17 -05:00
}