2015-03-20 18:30:45 -06:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* 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;
|
2016-05-05 16:47:41 +01:00
|
|
|
use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions;
|
2017-01-30 13:30:45 +00:00
|
|
|
use CachetHQ\Cachet\Services\Dates\DateFactory;
|
2017-06-13 19:24:21 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
2017-07-08 11:01:22 +01:00
|
|
|
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
|
|
|
|
2016-05-05 16:47:41 +01:00
|
|
|
/**
|
|
|
|
* This is the app service provider.
|
|
|
|
*
|
|
|
|
* @author James Brooks <james@alt-three.com>
|
2016-10-07 12:25:40 +01:00
|
|
|
* @author Joseph Cohen <joe@alt-three.com>
|
2016-05-05 16:47:41 +01:00
|
|
|
* @author Graham Campbell <graham@alt-three.com>
|
|
|
|
*/
|
2015-03-20 18:30:45 -06:00
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
2015-06-12 22:37:46 +01:00
|
|
|
/**
|
|
|
|
* Boot the service provider.
|
|
|
|
*
|
2015-12-24 15:44:06 +00:00
|
|
|
* @param \AltThree\Bus\Dispatcher $dispatcher
|
2015-06-12 22:37:46 +01:00
|
|
|
*/
|
|
|
|
public function boot(Dispatcher $dispatcher)
|
|
|
|
{
|
2017-07-08 16:20:02 +01:00
|
|
|
Schema::defaultStringLength(191);
|
2017-07-08 11:01:22 +01:00
|
|
|
|
2015-06-12 22:37:46 +01:00
|
|
|
$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:37:46 +01:00
|
|
|
});
|
2015-06-12 22:46:41 +01:00
|
|
|
|
2016-05-05 16:47: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-06-12 22:37:46 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2016-05-25 09:52:44 +01:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|