Skip to content

Commit

Permalink
Remove symfony/serializer and symfony/property-access dependencies (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Feb 27, 2024
1 parent a2e7507 commit c54064d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 1 addition & 3 deletions composer.json
Expand Up @@ -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,
Expand Down
18 changes: 6 additions & 12 deletions src/Pkl.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/PklTest.php
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit c54064d

Please sign in to comment.