From b19ce4df7ce12809a6baaad2c61fd062119134d5 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 7 Aug 2021 16:00:04 -0700 Subject: [PATCH] Fix transformer handling of closures --- app/Transformers/Api/Transformer.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Transformers/Api/Transformer.php b/app/Transformers/Api/Transformer.php index c3b89b7b6..f35609339 100644 --- a/app/Transformers/Api/Transformer.php +++ b/app/Transformers/Api/Transformer.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Transformers\Api; +use Closure; use DateTimeInterface; use Carbon\CarbonImmutable; use Illuminate\Http\Request; @@ -69,7 +70,9 @@ abstract class Transformer extends TransformerAbstract */ protected function item($data, $transformer, $resourceKey = null) { - self::assertSameNamespace($transformer); + if (!$transformer instanceof Closure) { + self::assertSameNamespace($transformer); + } $item = parent::item($data, $transformer, $resourceKey); @@ -89,7 +92,9 @@ abstract class Transformer extends TransformerAbstract */ protected function collection($data, $transformer, $resourceKey = null) { - self::assertSameNamespace($transformer); + if (!$transformer instanceof Closure) { + self::assertSameNamespace($transformer); + } $collection = parent::collection($data, $transformer, $resourceKey);