diff --git a/composer.json b/composer.json index ceb996a..1f208fe 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,7 @@ "psr/simple-cache": "^3.0", "symfony/console": "^6.3|^7.0", "symfony/finder": "^6.3|^7.0", - "symfony/process": "^6.3|^7.0", - "symfony/property-access": "^6.3|^7.0", - "symfony/serializer": "^6.3|^7.0" + "symfony/process": "^6.3|^7.0" }, "config": { "optimize-autoloader": true, diff --git a/src/Pkl.php b/src/Pkl.php index 5016fd9..6ecb271 100644 --- a/src/Pkl.php +++ b/src/Pkl.php @@ -15,11 +15,6 @@ use Symfony\Component\Finder\Finder; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; -use Symfony\Component\Serializer\Encoder\JsonEncoder; -use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; -use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; -use Symfony\Component\Serializer\Normalizer\PropertyNormalizer; -use Symfony\Component\Serializer\Serializer; /** * This is the main class to interact @@ -82,14 +77,13 @@ public static function eval(string $module, string $toClass = PklModule::class): } } - $serializer = new Serializer([ - new GetSetMethodNormalizer(), - new ObjectNormalizer(), - new PropertyNormalizer(), - ], [new JsonEncoder()]); - /** @var PklModule $module */ - $module = $serializer->deserialize($entry->content, PklModule::class, 'json'); + $decoded = \json_decode($entry->content, true); + $module = new PklModule(); + foreach ($decoded as $key => $value) { + $module->__set($key, $value); + } + if ($toClass === PklModule::class) { return $module; } diff --git a/tests/PklTest.php b/tests/PklTest.php index 4d6e755..2adf6fb 100644 --- a/tests/PklTest.php +++ b/tests/PklTest.php @@ -95,6 +95,10 @@ public function testEvalWithCustomClass(): void $this->assertInstanceOf(User::class, $user); $this->assertSame(1, $user->id); $this->assertSame('John Doe', $user->name); + $this->assertSame('123 Main St', $user->address->street); + $this->assertSame('Springfield', $user->address->city); + $this->assertSame('IL', $user->address->state); + $this->assertSame('62701', $user->address->zip); } /**