Don't use the Config facade in any composers

This commit is contained in:
James Brooks 2016-07-13 14:38:36 +01:00
parent 895d1ea1b6
commit ff9eb123c6
3 changed files with 85 additions and 39 deletions

View File

@ -14,7 +14,6 @@ namespace CachetHQ\Cachet\Composers;
use CachetHQ\Cachet\Dates\DateFactory; use CachetHQ\Cachet\Dates\DateFactory;
use GrahamCampbell\Markdown\Facades\Markdown; use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
class AppComposer class AppComposer
{ {
@ -25,16 +24,25 @@ class AppComposer
*/ */
protected $dates; protected $dates;
/**
* The illuminate config instance.
*
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/** /**
* Create a new app composer instance. * Create a new app composer instance.
* *
* @param \CachetHQ\Cachet\Dates\DateFactory $dates * @param \CachetHQ\Cachet\Dates\DateFactory $dates
* @param \Illuminate\Contracts\Config\Repository $config
* *
* @return void * @return void
*/ */
public function __construct(DateFactory $dates) public function __construct(DateFactory $dates, Repository $config)
{ {
$this->dates = $dates; $this->dates = $dates;
$this->config = $config;
} }
/** /**
@ -46,28 +54,28 @@ class AppComposer
*/ */
public function compose(View $view) public function compose(View $view)
{ {
$view->withAboutApp(Markdown::convertToHtml(Config::get('setting.app_about'))); $view->withAboutApp(Markdown::convertToHtml($this->config->get('setting.app_about')));
$view->withAppAnalytics(Config::get('setting.app_analytics')); $view->withAppAnalytics($this->config->get('setting.app_analytics'));
$view->withAppAnalyticsGoSquared(Config::get('setting.app_analytics_gs')); $view->withAppAnalyticsGoSquared($this->config->get('setting.app_analytics_gs'));
$view->withAppAnalyticsPiwikUrl(Config::get('setting.app_analytics_piwik_url')); $view->withAppAnalyticsPiwikUrl($this->config->get('setting.app_analytics_piwik_url'));
$view->withAppAnalyticsPiwikSiteId(Config::get('setting.app_analytics_piwik_site_id')); $view->withAppAnalyticsPiwikSiteId($this->config->get('setting.app_analytics_piwik_site_id'));
$view->withAppBanner(Config::get('setting.app_banner')); $view->withAppBanner($this->config->get('setting.app_banner'));
$view->withAppBannerStyleFullWidth(Config::get('setting.style_fullwidth_header')); $view->withAppBannerStyleFullWidth($this->config->get('setting.style_fullwidth_header'));
$view->withAppBannerType(Config::get('setting.app_banner_type')); $view->withAppBannerType($this->config->get('setting.app_banner_type'));
$view->withAppDomain(Config::get('setting.app_domain')); $view->withAppDomain($this->config->get('setting.app_domain'));
$view->withAppGraphs(Config::get('setting.display_graphs')); $view->withAppGraphs($this->config->get('setting.display_graphs'));
$view->withAppLocale(Config::get('setting.app_locale')); $view->withAppLocale($this->config->get('setting.app_locale'));
$view->withAppStylesheet(Config::get('setting.stylesheet')); $view->withAppStylesheet($this->config->get('setting.stylesheet'));
$view->withAppUrl(Config::get('app.url')); $view->withAppUrl($this->config->get('app.url'));
$view->withAppHeader(Config::get('setting.header')); $view->withAppHeader($this->config->get('setting.header'));
$view->withAppFooter(Config::get('setting.footer')); $view->withAppFooter($this->config->get('setting.footer'));
$view->withAppName(Config::get('setting.app_name')); $view->withAppName($this->config->get('setting.app_name'));
$view->withShowSupport(Config::get('setting.show_support')); $view->withShowSupport($this->config->get('setting.show_support'));
$view->withAutomaticLocalization(Config::get('setting.automatic_localization')); $view->withAutomaticLocalization($this->config->get('setting.automatic_localization'));
$view->withEnableExternalDependencies(Config::get('setting.enable_external_dependencies')); $view->withEnableExternalDependencies($this->config->get('setting.enable_external_dependencies'));
$view->withShowTimezone(Config::get('setting.show_timezone')); $view->withShowTimezone($this->config->get('setting.show_timezone'));
$view->withTimezone($this->dates->getTimezone()); $view->withTimezone($this->dates->getTimezone());
$view->withSiteTitle(Config::get('setting.app_name')); $view->withSiteTitle($this->config->get('setting.app_name'));
$view->withFontSubset(Config::get('langs.'.Config::get('app.locale').'.subset', 'latin')); $view->withFontSubset($this->config->get('langs.'.$this->config->get('app.locale').'.subset', 'latin'));
} }
} }

View File

@ -12,11 +12,30 @@
namespace CachetHQ\Cachet\Composers; namespace CachetHQ\Cachet\Composers;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
class MetricsComposer class MetricsComposer
{ {
/**
* The illuminate config instance.
*
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* Create a new metrics composer.
*
* @param \Illuminate\Contracts\Config\Repository $config
*
* @return void
*/
public function __construct(Repository $config)
{
$this->config = $config;
}
/** /**
* Metrics view composer. * Metrics view composer.
* *
@ -27,7 +46,7 @@ class MetricsComposer
public function compose(View $view) public function compose(View $view)
{ {
$metrics = null; $metrics = null;
if ($displayMetrics = Config::get('setting.display_graphs')) { if ($displayMetrics = $this->config->get('setting.display_graphs')) {
$metrics = Metric::displayable()->orderBy('order')->orderBy('id')->get(); $metrics = Metric::displayable()->orderBy('order')->orderBy('id')->get();
} }

View File

@ -11,11 +11,30 @@
namespace CachetHQ\Cachet\Composers; namespace CachetHQ\Cachet\Composers;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
class ThemeComposer class ThemeComposer
{ {
/**
* The illuminate config instance.
*
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* Create a new theme composer.
*
* @param \Illuminate\Contracts\Config\Repository $config
*
* @return void
*/
public function __construct(Repository $config)
{
$this->config = $config;
}
/** /**
* Bind data to the view. * Bind data to the view.
* *
@ -26,17 +45,17 @@ class ThemeComposer
public function compose(View $view) public function compose(View $view)
{ {
// Theme colors. // Theme colors.
$view->withThemeBackgroundColor(Config::get('setting.style_background_color', '#F0F3F4')); $view->withThemeBackgroundColor($this->config->get('setting.style_background_color', '#F0F3F4'));
$view->withThemeBackgroundFills(Config::get('setting.style_background_fills', '#FFFFFF')); $view->withThemeBackgroundFills($this->config->get('setting.style_background_fills', '#FFFFFF'));
$view->withThemeBannerBackgroundColor(Config::get('setting.style_banner_background_color', '')); $view->withThemeBannerBackgroundColor($this->config->get('setting.style_banner_background_color', ''));
$view->withThemeBannerPadding(Config::get('setting.style_banner_padding', '40px 0')); $view->withThemeBannerPadding($this->config->get('setting.style_banner_padding', '40px 0'));
$view->withThemeTextColor(Config::get('setting.style_text_color', '#333333')); $view->withThemeTextColor($this->config->get('setting.style_text_color', '#333333'));
$view->withThemeReds(Config::get('setting.style_reds', '#ff6f6f')); $view->withThemeReds($this->config->get('setting.style_reds', '#ff6f6f'));
$view->withThemeBlues(Config::get('setting.style_blues', '#3498db')); $view->withThemeBlues($this->config->get('setting.style_blues', '#3498db'));
$view->withThemeGreens(Config::get('setting.style_greens', '#7ED321')); $view->withThemeGreens($this->config->get('setting.style_greens', '#7ED321'));
$view->withThemeYellows(Config::get('setting.style_yellows', '#F7CA18')); $view->withThemeYellows($this->config->get('setting.style_yellows', '#F7CA18'));
$view->withThemeOranges(Config::get('setting.style_oranges', '#FF8800')); $view->withThemeOranges($this->config->get('setting.style_oranges', '#FF8800'));
$view->withThemeMetrics(Config::get('setting.style_metrics', '#0dccc0')); $view->withThemeMetrics($this->config->get('setting.style_metrics', '#0dccc0'));
$view->withThemeLinks(Config::get('setting.style_links', '#7ED321')); $view->withThemeLinks($this->config->get('setting.style_links', '#7ED321'));
} }
} }