Cachet/app/Foundation/Providers/AppServiceProvider.php

84 lines
2.3 KiB
PHP
Raw Normal View History

2015-03-20 18:30:45 -06:00
<?php
/*
* This file is part of Cachet.
*
2015-07-06 17:37:01 +01:00
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2015-12-07 22:12:45 +00:00
namespace CachetHQ\Cachet\Foundation\Providers;
2015-03-20 18:30:45 -06:00
2015-12-24 15:44:06 +00:00
use AltThree\Bus\Dispatcher;
use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions;
use CachetHQ\Cachet\Services\Dates\DateFactory;
2017-06-13 19:24:21 +01:00
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Schema;
2015-03-20 18:30:45 -06:00
use Illuminate\Support\ServiceProvider;
2015-06-12 22:44:57 +01:00
use Illuminate\Support\Str;
2015-03-20 18:30:45 -06:00
/**
* This is the app service provider.
*
* @author James Brooks <james@alt-three.com>
* @author Joseph Cohen <joe@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
2015-03-20 18:30:45 -06:00
class AppServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*
2015-12-24 15:44:06 +00:00
* @param \AltThree\Bus\Dispatcher $dispatcher
*/
public function boot(Dispatcher $dispatcher)
{
2017-07-08 16:20:02 +01:00
Schema::defaultStringLength(191);
$dispatcher->mapUsing(function ($command) {
2016-01-05 02:38:07 +00:00
return Dispatcher::simpleMapping($command, 'CachetHQ\Cachet\Bus', 'CachetHQ\Cachet\Bus\Handlers');
});
2015-06-12 22:46:41 +01:00
$dispatcher->pipeThrough([UseDatabaseTransactions::class]);
2015-06-12 22:44:57 +01:00
Str::macro('canonicalize', function ($url) {
return preg_replace('/([^\/])$/', '$1/', $url);
});
2017-06-13 19:24:21 +01:00
Relation::morphMap([
'components' => \CachetHQ\Cachet\Models\Component::class,
'incidents' => \CachetHQ\Cachet\Models\Incident::class,
'metrics' => \CachetHQ\Cachet\Models\Metric::class,
'schedules' => \CachetHQ\Cachet\Models\Schedule::class,
'subscriber' => \CachetHQ\Cachet\Models\Subscriber::class,
]);
}
2015-03-20 18:30:45 -06:00
/**
2015-05-28 19:46:54 +01:00
* Register the service provider.
2015-08-30 22:42:38 +01:00
*
* @return void
2015-03-20 18:30:45 -06:00
*/
public function register()
{
2015-11-07 13:15:28 +00:00
$this->registerDateFactory();
}
/**
* Register the date factory.
*
* @return void
*/
protected function registerDateFactory()
{
$this->app->singleton(DateFactory::class, function ($app) {
$appTimezone = $app['config']->get('app.timezone');
$cacheTimezone = $app['config']->get('cachet.timezone');
2015-11-07 13:15:28 +00:00
return new DateFactory($appTimezone, $cacheTimezone);
});
2015-03-20 18:30:45 -06:00
}
}