From ff9eb123c66f0111a7d7ac00a9b3e045c45ef295 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Wed, 13 Jul 2016 14:38:36 +0100 Subject: [PATCH] Don't use the Config facade in any composers --- app/Composers/AppComposer.php | 56 ++++++++++++++++++------------- app/Composers/MetricsComposer.php | 23 +++++++++++-- app/Composers/ThemeComposer.php | 45 ++++++++++++++++++------- 3 files changed, 85 insertions(+), 39 deletions(-) diff --git a/app/Composers/AppComposer.php b/app/Composers/AppComposer.php index cc3a83e0..d8a4aa5f 100644 --- a/app/Composers/AppComposer.php +++ b/app/Composers/AppComposer.php @@ -14,7 +14,6 @@ namespace CachetHQ\Cachet\Composers; use CachetHQ\Cachet\Dates\DateFactory; use GrahamCampbell\Markdown\Facades\Markdown; use Illuminate\Contracts\View\View; -use Illuminate\Support\Facades\Config; class AppComposer { @@ -25,16 +24,25 @@ class AppComposer */ protected $dates; + /** + * The illuminate config instance. + * + * @var \Illuminate\Contracts\Config\Repository + */ + protected $config; + /** * Create a new app composer instance. * * @param \CachetHQ\Cachet\Dates\DateFactory $dates + * @param \Illuminate\Contracts\Config\Repository $config * * @return void */ - public function __construct(DateFactory $dates) + public function __construct(DateFactory $dates, Repository $config) { $this->dates = $dates; + $this->config = $config; } /** @@ -46,28 +54,28 @@ class AppComposer */ public function compose(View $view) { - $view->withAboutApp(Markdown::convertToHtml(Config::get('setting.app_about'))); - $view->withAppAnalytics(Config::get('setting.app_analytics')); - $view->withAppAnalyticsGoSquared(Config::get('setting.app_analytics_gs')); - $view->withAppAnalyticsPiwikUrl(Config::get('setting.app_analytics_piwik_url')); - $view->withAppAnalyticsPiwikSiteId(Config::get('setting.app_analytics_piwik_site_id')); - $view->withAppBanner(Config::get('setting.app_banner')); - $view->withAppBannerStyleFullWidth(Config::get('setting.style_fullwidth_header')); - $view->withAppBannerType(Config::get('setting.app_banner_type')); - $view->withAppDomain(Config::get('setting.app_domain')); - $view->withAppGraphs(Config::get('setting.display_graphs')); - $view->withAppLocale(Config::get('setting.app_locale')); - $view->withAppStylesheet(Config::get('setting.stylesheet')); - $view->withAppUrl(Config::get('app.url')); - $view->withAppHeader(Config::get('setting.header')); - $view->withAppFooter(Config::get('setting.footer')); - $view->withAppName(Config::get('setting.app_name')); - $view->withShowSupport(Config::get('setting.show_support')); - $view->withAutomaticLocalization(Config::get('setting.automatic_localization')); - $view->withEnableExternalDependencies(Config::get('setting.enable_external_dependencies')); - $view->withShowTimezone(Config::get('setting.show_timezone')); + $view->withAboutApp(Markdown::convertToHtml($this->config->get('setting.app_about'))); + $view->withAppAnalytics($this->config->get('setting.app_analytics')); + $view->withAppAnalyticsGoSquared($this->config->get('setting.app_analytics_gs')); + $view->withAppAnalyticsPiwikUrl($this->config->get('setting.app_analytics_piwik_url')); + $view->withAppAnalyticsPiwikSiteId($this->config->get('setting.app_analytics_piwik_site_id')); + $view->withAppBanner($this->config->get('setting.app_banner')); + $view->withAppBannerStyleFullWidth($this->config->get('setting.style_fullwidth_header')); + $view->withAppBannerType($this->config->get('setting.app_banner_type')); + $view->withAppDomain($this->config->get('setting.app_domain')); + $view->withAppGraphs($this->config->get('setting.display_graphs')); + $view->withAppLocale($this->config->get('setting.app_locale')); + $view->withAppStylesheet($this->config->get('setting.stylesheet')); + $view->withAppUrl($this->config->get('app.url')); + $view->withAppHeader($this->config->get('setting.header')); + $view->withAppFooter($this->config->get('setting.footer')); + $view->withAppName($this->config->get('setting.app_name')); + $view->withShowSupport($this->config->get('setting.show_support')); + $view->withAutomaticLocalization($this->config->get('setting.automatic_localization')); + $view->withEnableExternalDependencies($this->config->get('setting.enable_external_dependencies')); + $view->withShowTimezone($this->config->get('setting.show_timezone')); $view->withTimezone($this->dates->getTimezone()); - $view->withSiteTitle(Config::get('setting.app_name')); - $view->withFontSubset(Config::get('langs.'.Config::get('app.locale').'.subset', 'latin')); + $view->withSiteTitle($this->config->get('setting.app_name')); + $view->withFontSubset($this->config->get('langs.'.$this->config->get('app.locale').'.subset', 'latin')); } } diff --git a/app/Composers/MetricsComposer.php b/app/Composers/MetricsComposer.php index 4f6696db..90b69135 100644 --- a/app/Composers/MetricsComposer.php +++ b/app/Composers/MetricsComposer.php @@ -12,11 +12,30 @@ namespace CachetHQ\Cachet\Composers; use CachetHQ\Cachet\Models\Metric; +use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\View\View; -use Illuminate\Support\Facades\Config; 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. * @@ -27,7 +46,7 @@ class MetricsComposer public function compose(View $view) { $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(); } diff --git a/app/Composers/ThemeComposer.php b/app/Composers/ThemeComposer.php index 5f608a0a..191b8946 100644 --- a/app/Composers/ThemeComposer.php +++ b/app/Composers/ThemeComposer.php @@ -11,11 +11,30 @@ namespace CachetHQ\Cachet\Composers; +use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\View\View; -use Illuminate\Support\Facades\Config; 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. * @@ -26,17 +45,17 @@ class ThemeComposer public function compose(View $view) { // Theme colors. - $view->withThemeBackgroundColor(Config::get('setting.style_background_color', '#F0F3F4')); - $view->withThemeBackgroundFills(Config::get('setting.style_background_fills', '#FFFFFF')); - $view->withThemeBannerBackgroundColor(Config::get('setting.style_banner_background_color', '')); - $view->withThemeBannerPadding(Config::get('setting.style_banner_padding', '40px 0')); - $view->withThemeTextColor(Config::get('setting.style_text_color', '#333333')); - $view->withThemeReds(Config::get('setting.style_reds', '#ff6f6f')); - $view->withThemeBlues(Config::get('setting.style_blues', '#3498db')); - $view->withThemeGreens(Config::get('setting.style_greens', '#7ED321')); - $view->withThemeYellows(Config::get('setting.style_yellows', '#F7CA18')); - $view->withThemeOranges(Config::get('setting.style_oranges', '#FF8800')); - $view->withThemeMetrics(Config::get('setting.style_metrics', '#0dccc0')); - $view->withThemeLinks(Config::get('setting.style_links', '#7ED321')); + $view->withThemeBackgroundColor($this->config->get('setting.style_background_color', '#F0F3F4')); + $view->withThemeBackgroundFills($this->config->get('setting.style_background_fills', '#FFFFFF')); + $view->withThemeBannerBackgroundColor($this->config->get('setting.style_banner_background_color', '')); + $view->withThemeBannerPadding($this->config->get('setting.style_banner_padding', '40px 0')); + $view->withThemeTextColor($this->config->get('setting.style_text_color', '#333333')); + $view->withThemeReds($this->config->get('setting.style_reds', '#ff6f6f')); + $view->withThemeBlues($this->config->get('setting.style_blues', '#3498db')); + $view->withThemeGreens($this->config->get('setting.style_greens', '#7ED321')); + $view->withThemeYellows($this->config->get('setting.style_yellows', '#F7CA18')); + $view->withThemeOranges($this->config->get('setting.style_oranges', '#FF8800')); + $view->withThemeMetrics($this->config->get('setting.style_metrics', '#0dccc0')); + $view->withThemeLinks($this->config->get('setting.style_links', '#7ED321')); } }