From 26f8628e287630dcdf9d650d7f8b75d07a2ec8d5 Mon Sep 17 00:00:00 2001 From: Matt Gatner Date: Tue, 2 Jul 2019 15:03:39 +0000 Subject: [PATCH 1/2] Move example config to bin, implement new config() --- Alerts.php.example => bin/Alerts.php | 6 ++---- src/Alerts.php | 10 +++++----- src/Config/Services.php | 12 ++++-------- 3 files changed, 11 insertions(+), 17 deletions(-) rename Alerts.php.example => bin/Alerts.php (80%) diff --git a/Alerts.php.example b/bin/Alerts.php similarity index 80% rename from Alerts.php.example rename to bin/Alerts.php index b087379..b09cba2 100644 --- a/Alerts.php.example +++ b/bin/Alerts.php @@ -2,16 +2,14 @@ /*** * -* This file contains example values to override or augment default library behavior. +* This file contains example values to change the default library behavior. * Recommended usage: * 1. Copy the file to app/Config/Alerts.php * 2. Set any override variables -* 3. Remove any lines to fallback to defaults +* 3. Remove any lines to fallback to library defaults * ***/ -use CodeIgniter\Config\BaseConfig; - class Alerts extends \Tatter\Alerts\Config\Alerts { // prefix for SESSION variables and HTML classes, to prevent collision diff --git a/src/Alerts.php b/src/Alerts.php index ee4bcc8..5444c73 100644 --- a/src/Alerts.php +++ b/src/Alerts.php @@ -1,8 +1,8 @@ public function css() { - return $this->view->setVar('prefix', $this->config->prefix)->render("Tatter\Alerts\Views\css"); + return $this->view->setVar('prefix', $this->config->prefix)->render('Tatter\Alerts\Views\css'); } } diff --git a/src/Config/Services.php b/src/Config/Services.php index b40283e..75aa049 100644 --- a/src/Config/Services.php +++ b/src/Config/Services.php @@ -11,14 +11,10 @@ public static function alerts(BaseConfig $config = null, RendererInterface $view return static::getSharedInstance('alerts', $config, $view); endif; - // prioritizes user config in app/Config if found - if (empty($config)): - if (class_exists('\Config\Alerts')): - $config = new \Config\Alerts(); - else: - $config = new \Tatter\Alerts\Config\Alerts(); - endif; - endif; + // If no config was injected then load one + // Prioritizes app/Config if found + if (empty($config)) + $config = config('Alerts'); return new \Tatter\Alerts\Alerts($config, $view); } From 8ee531759df9898c00570cf2ab316ae857d6fdfc Mon Sep 17 00:00:00 2001 From: Matt Gatner Date: Tue, 2 Jul 2019 15:09:08 +0000 Subject: [PATCH 2/2] Move exception strings to Language/ --- src/Exceptions/AlertsException.php | 4 ++-- src/Language/en/Alerts.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/Language/en/Alerts.php diff --git a/src/Exceptions/AlertsException.php b/src/Exceptions/AlertsException.php index f1f1ebd..c8336f6 100644 --- a/src/Exceptions/AlertsException.php +++ b/src/Exceptions/AlertsException.php @@ -7,10 +7,10 @@ class AlertsException extends FrameworkException implements ExceptionInterface { public static function forInvalidTemplate(string $template = null) { - return new static("'{$template}' is not a valid Alerts template."); + return new static(lang('Alerts.invalidTemplate', [$template])); } public static function forMissingTemplateView(string $template = null) { - return new static("Could not find template view file: '{$template}'."); + return new static(lang('Alerts.missingTemplateView', [$template])); } } diff --git a/src/Language/en/Alerts.php b/src/Language/en/Alerts.php new file mode 100644 index 0000000..e1e9d66 --- /dev/null +++ b/src/Language/en/Alerts.php @@ -0,0 +1,6 @@ + '"{0}" is not a valid Alerts template.', + 'missingTemplateView' => 'Could not find template view file: "{0}".', +]; \ No newline at end of file