From 3b61ad52ff3b69ce505a5ce9277f6daa86b7bc8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 3 Mar 2023 15:45:57 +0100 Subject: [PATCH] Add config check on route binder --- src/Traits/SitemapRouteBinder.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Traits/SitemapRouteBinder.php b/src/Traits/SitemapRouteBinder.php index 1dedcb1..2793957 100644 --- a/src/Traits/SitemapRouteBinder.php +++ b/src/Traits/SitemapRouteBinder.php @@ -7,7 +7,6 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Schema; use Kwaadpepper\Enum\BaseEnumRoutable; use Kwaadpepper\RefreshSitemap\Exceptions\SitemapException; -use ReflectionClass; trait SitemapRouteBinder { @@ -26,7 +25,21 @@ trait SitemapRouteBinder */ private static function initConfigBinder(): void { - self::$routesBinder = \config('refresh-sitemap.routesBinder', self::$routesBinder); + self::$routesBinder = \collect(\config('refresh-sitemap.routesBinder', self::$routesBinder)) + ->filter()->mapWithKeys(function ($value, $key) { + return [ + \strval($key) => \collect($value)->filter()->mapWithKeys(function ($value, $key) { + return [ + \strval($key) => \collect($value)->filter()->map(function ($value) { + if (!\is_string($value) and !\is_int($value)) { + throw new \Error('Wrong configuration on sitemap routesBinder'); + } + return $value; + })->all() + ]; + })->all() + ]; + })->all(); } /** @@ -107,7 +120,7 @@ trait SitemapRouteBinder } try { /** @var object */ - $rfCls = (new ReflectionClass($p[0]))->newInstanceWithoutConstructor(); + $rfCls = (new \ReflectionClass($p[0]))->newInstanceWithoutConstructor(); if (is_subclass_of($rfCls, BaseEnumRoutable::class)) { return; }