From 88a57252edd614ab0eaf34af0795475ddceec52b Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 26 Jun 2024 14:47:49 +0200 Subject: [PATCH] Fix Exception handling errors --- components/EventManager.php | 8 ++++---- exceptions/ComponentException.php | 2 +- support/FetchSingleEvent.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/EventManager.php b/components/EventManager.php index 377389b..1d14061 100644 --- a/components/EventManager.php +++ b/components/EventManager.php @@ -114,10 +114,10 @@ abstract class EventManager extends ComponentBase private function getPageFromProperty(string $property): Page { - throw_if(!$this->property('indexPage') || !$this->property('singlePage') || !$this->property('registerPage'), ComponentException::class, 'silva.adrema::lang.not_all_pages_set'); + throw_if(!$this->property('indexPage') || !$this->property('singlePage') || !$this->property('registerPage'), ComponentException::class, 'not_all_pages_set'); $page = Page::find($this->property($property)); - throw_if($page === null, ComponentException::class, 'silva.adrema::lang.page_not_found'); + throw_if($page === null, ComponentException::class, 'page_not_found'); return $page; } @@ -131,8 +131,8 @@ abstract class EventManager extends ComponentBase $singlePage = $this->getPageFromProperty('singlePage'); $registerPage = $this->getPageFromProperty('registerPage'); - throw_if(!str($singlePage->url)->contains(':slug'), ComponentException::class, 'silva.adrema::lang.slug_not_found'); - throw_if(!str($registerPage->url)->contains(':slug'), ComponentException::class, 'silva.adrema::lang.slug_not_found'); + throw_if(!str($singlePage->url)->contains(':slug'), ComponentException::class, 'slug_not_found'); + throw_if(!str($registerPage->url)->contains(':slug'), ComponentException::class, 'slug_not_found'); return [ 'indexUrl' => $indexPage->url, diff --git a/exceptions/ComponentException.php b/exceptions/ComponentException.php index dae8629..d83e285 100644 --- a/exceptions/ComponentException.php +++ b/exceptions/ComponentException.php @@ -12,7 +12,7 @@ class ComponentException extends ApplicationException public function __construct($message = "", $code = 0, Throwable $previous = null) { - $translations = json_decode(file_get_contents(__DIR__ . '/../lang/en.json'), true); + $translations = include(__DIR__ . '/../lang/en/lang.php'); parent::__construct($translations['errors.' . $message] ?? $message, $code, $previous); } diff --git a/support/FetchSingleEvent.php b/support/FetchSingleEvent.php index b302b40..99ed9af 100644 --- a/support/FetchSingleEvent.php +++ b/support/FetchSingleEvent.php @@ -7,7 +7,7 @@ class FetchSingleEvent public function run(string $slug): ?array { $events = data_get(app(FetchAllEvents::class)->run(), 'data'); - throw_if(is_null($events), ComponentException::class, 'silva.adrema::lang.event_fetching_failed'); + throw_if(is_null($events), ComponentException::class, 'event_fetching_failed'); return collect($events)->first(fn ($event) => $event['slug'] === $slug); }