Cleanup service providers

This commit is contained in:
Graham Campbell
2015-05-28 19:46:54 +01:00
parent 5540a50fae
commit 3f9ebb8abf
13 changed files with 116 additions and 219 deletions
+3 -16
View File
@@ -16,25 +16,12 @@ use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
/** /**
* Bootstrap any application services. * Register the service provider.
*/
public function boot()
{
//
}
/**
* Register any application services.
* *
* This service provider is a great spot to register your various container * @return void
* bindings with the application. As you can see, we are registering our
* "Registrar" implementation here. You can add your own bindings too!
*/ */
public function register() public function register()
{ {
$this->app->bind( $this->app->bind('Illuminate\Contracts\Auth\Registrar', 'CachetHQ\Cachet\Services\Registrar');
'Illuminate\Contracts\Auth\Registrar',
'CachetHQ\Cachet\Services\Registrar'
);
} }
} }
+7 -5
View File
@@ -17,21 +17,23 @@ use Illuminate\Support\ServiceProvider;
class BusServiceProvider extends ServiceProvider class BusServiceProvider extends ServiceProvider
{ {
/** /**
* Bootstrap any application services. * Boot the service provider.
* *
* @param \Illuminate\Bus\Dispatcher $dispatcher * @param \Illuminate\Bus\Dispatcher $dispatcher
*
* @return void
*/ */
public function boot(Dispatcher $dispatcher) public function boot(Dispatcher $dispatcher)
{ {
$dispatcher->mapUsing(function ($command) { $dispatcher->mapUsing(function ($command) {
return Dispatcher::simpleMapping( return Dispatcher::simpleMapping($command, 'CachetHQ\Cachet\Commands', 'CachetHQ\Cachet\Handlers\Commands');
$command, 'CachetHQ\Cachet\Commands', 'CachetHQ\Cachet\Handlers\Commands'
);
}); });
} }
/** /**
* Register any application services. * Register the service provider.
*
* @return void
*/ */
public function register() public function register()
{ {
+36
View File
@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Providers;
use CachetHQ\Cachet\Composers\DashboardComposer;
use CachetHQ\Cachet\Composers\IndexComposer;
use CachetHQ\Cachet\Composers\LoggedUserComposer;
use CachetHQ\Cachet\Composers\TimezoneLocaleComposer;
use CachetHQ\Cachet\Composers\ThemeComposer;
use Illuminate\Support\ServiceProvider;
class ComposerServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->view->composer('*', LoggedUserComposer::class);
$this->app->view->composer('index', IndexComposer::class);
$this->app->view->composer('index', ThemeComposer::class);
$this->app->view->composer('dashboard.*', DashboardComposer::class);
$this->app->view->composer(['setup', 'dashboard.settings.app-setup'], TimezoneLocaleComposer::class);
}
}
+54 -7
View File
@@ -11,21 +11,68 @@
namespace CachetHQ\Cachet\Providers; namespace CachetHQ\Cachet\Providers;
use CachetHQ\Cachet\Config\Repository;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Setting as SettingModel;
use Exception;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class ConfigServiceProvider extends ServiceProvider class ConfigServiceProvider extends ServiceProvider
{ {
/** /**
* Overwrite any vendor / package configuration. * Boot the service provider.
* *
* This service provider is intended to provide a convenient location for you * @return void
* to overwrite any "vendor" or package configuration that you may want to */
* modify before the application handles the incoming request / command. public function boot()
{
try {
// Get app custom configuration.
$appDomain = Setting::get('app_domain');
$appLocale = Setting::get('app_locale');
// Set the Segment.com settings.
if (Setting::get('app_track')) {
$segmentRepository = $this->app->make('CachetHQ\Cachet\Segment\RepositoryInterface');
$this->app->config->set('segment.write_key', $segmentRepository->fetch());
}
// Setup Cors.
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
$allowedOrigins[] = Setting::get('app_domain');
// Add our allowed domains too.
if ($allowedDomains = Setting::get('allowed_domains')) {
$domains = explode(',', $allowedDomains);
foreach ($domains as $domain) {
$allowedOrigins[] = $domain;
}
} else {
$allowedOrigins[] = env('APP_URL');
}
$this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins);
} catch (Exception $e) {
// Don't throw any errors, we may not be setup yet.
}
// Override default app values.
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale'));
// Set custom lang.
$this->app->translator->setLocale($appLocale);
}
/**
* Register the service provider.
*
* @return void
*/ */
public function register() public function register()
{ {
config([ $this->app->bindShared('setting', function () {
// return new Repository(new SettingModel());
]); });
} }
} }
+2 -8
View File
@@ -16,16 +16,10 @@ use Illuminate\Support\ServiceProvider;
class ConsoleServiceProvider extends ServiceProvider class ConsoleServiceProvider extends ServiceProvider
{ {
/**
* Boot the service provider.
*/
public function boot()
{
//
}
/** /**
* Register the service provider. * Register the service provider.
*
* @return void
*/ */
public function register() public function register()
{ {
-12
View File
@@ -26,16 +26,4 @@ class EventServiceProvider extends ServiceProvider
'EventListener', 'EventListener',
], ],
]; ];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
//
}
} }
@@ -1,72 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Providers;
use CachetHQ\Cachet\Facades\Setting;
use Exception;
use Illuminate\Support\ServiceProvider;
class LoadConfigServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*/
public function boot()
{
$appDomain = $appLocale = null;
try {
// Get app custom configuration.
$appDomain = Setting::get('app_domain');
$appLocale = Setting::get('app_locale');
// Set the Segment.com settings.
if (Setting::get('app_track')) {
$segmentRepository = $this->app->make('CachetHQ\Cachet\Segment\RepositoryInterface');
$this->app->config->set('segment.write_key', $segmentRepository->fetch());
}
// Setup Cors.
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
$allowedOrigins[] = Setting::get('app_domain');
// Add our allowed domains too.
if ($allowedDomains = Setting::get('allowed_domains')) {
$domains = explode(',', $allowedDomains);
foreach ($domains as $domain) {
$allowedOrigins[] = $domain;
}
} else {
$allowedOrigins[] = env('APP_URL');
}
$this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins);
} catch (Exception $e) {
// Don't throw any errors, we may not be setup yet.
}
// Override default app values.
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale'));
// Set custom lang.
$this->app->translator->setLocale($appLocale);
}
/**
* Register the service provider.
*/
public function register()
{
//
}
}
+2 -8
View File
@@ -15,16 +15,10 @@ use Illuminate\Support\ServiceProvider;
class RepositoryServiceProvider extends ServiceProvider class RepositoryServiceProvider extends ServiceProvider
{ {
/**
* Boot the service provider.
*/
public function boot()
{
//
}
/** /**
* Register the service provider. * Register the service provider.
*
* @return void
*/ */
public function register() public function register()
{ {
+7 -1
View File
@@ -26,9 +26,11 @@ class RouteServiceProvider extends ServiceProvider
protected $namespace = 'CachetHQ\Cachet\Http\Controllers'; protected $namespace = 'CachetHQ\Cachet\Http\Controllers';
/** /**
* Define your route model bindings, pattern filters, etc. * Define the route model bindings, pattern filters, etc.
* *
* @param \Illuminate\Routing\Router $router * @param \Illuminate\Routing\Router $router
*
* @return void
*/ */
public function boot(Router $router) public function boot(Router $router)
{ {
@@ -39,6 +41,8 @@ class RouteServiceProvider extends ServiceProvider
/** /**
* Register model bindings. * Register model bindings.
*
* @return void
*/ */
protected function registerBindings() protected function registerBindings()
{ {
@@ -56,6 +60,8 @@ class RouteServiceProvider extends ServiceProvider
* Define the routes for the application. * Define the routes for the application.
* *
* @param \Illuminate\Routing\Router $router * @param \Illuminate\Routing\Router $router
*
* @return void
*/ */
public function map(Router $router) public function map(Router $router)
{ {
@@ -16,18 +16,12 @@ use CachetHQ\Cachet\Segment\HttpRepository;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class SegmentApiServiceProvider extends ServiceProvider class SegmentServiceProvider extends ServiceProvider
{ {
/**
* Boot the service provider.
*/
public function boot()
{
//
}
/** /**
* Register the service provider. * Register the service provider.
*
* @return void
*/ */
public function register() public function register()
{ {
-37
View File
@@ -1,37 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Providers;
use CachetHQ\Cachet\Config\Repository;
use CachetHQ\Cachet\Models\Setting as SettingModel;
use Illuminate\Support\ServiceProvider;
class SettingsServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*/
public function boot()
{
//
}
/**
* Register the service provider.
*/
public function register()
{
$this->app->bindShared('setting', function () {
return new Repository(new SettingModel());
});
}
}
@@ -1,40 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Providers;
use Illuminate\Support\ServiceProvider;
class ViewComposerServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*/
public function boot()
{
//
}
/**
* Register the service provider.
*/
public function register()
{
$this->app->view->composer('*', 'CachetHQ\Cachet\Composers\LoggedUserComposer');
$this->app->view->composer('index', 'CachetHQ\Cachet\Composers\IndexComposer');
$this->app->view->composer('index', 'CachetHQ\Cachet\Composers\ThemeComposer');
$this->app->view->composer('dashboard.*', 'CachetHQ\Cachet\Composers\DashboardComposer');
$this->app->view->composer([
'setup',
'dashboard.settings.app-setup',
], 'CachetHQ\Cachet\Composers\TimezoneLocaleComposer');
}
}
+2 -4
View File
@@ -165,15 +165,13 @@ return [
*/ */
'CachetHQ\Cachet\Providers\AppServiceProvider', 'CachetHQ\Cachet\Providers\AppServiceProvider',
'CachetHQ\Cachet\Providers\BusServiceProvider', 'CachetHQ\Cachet\Providers\BusServiceProvider',
'CachetHQ\Cachet\Providers\ComposerServiceProvider',
'CachetHQ\Cachet\Providers\ConfigServiceProvider', 'CachetHQ\Cachet\Providers\ConfigServiceProvider',
'CachetHQ\Cachet\Providers\ConsoleServiceProvider', 'CachetHQ\Cachet\Providers\ConsoleServiceProvider',
'CachetHQ\Cachet\Providers\EventServiceProvider', 'CachetHQ\Cachet\Providers\EventServiceProvider',
'CachetHQ\Cachet\Providers\RepositoryServiceProvider', 'CachetHQ\Cachet\Providers\RepositoryServiceProvider',
'CachetHQ\Cachet\Providers\RouteServiceProvider', 'CachetHQ\Cachet\Providers\RouteServiceProvider',
'CachetHQ\Cachet\Providers\SettingsServiceProvider', 'CachetHQ\Cachet\Providers\SegmentServiceProvider',
'CachetHQ\Cachet\Providers\SegmentApiServiceProvider',
'CachetHQ\Cachet\Providers\ViewComposerServiceProvider',
'CachetHQ\Cachet\Providers\LoadConfigServiceProvider',
'CachetHQ\Segment\SegmentServiceProvider', 'CachetHQ\Segment\SegmentServiceProvider',
], ],