First stable version and the future of the library #265
Replies: 3 comments 2 replies
-
Hi, as far as I can tell the only big missing piece of the current Valinor is a |
Beta Was this translation helpful? Give feedback.
-
First, congrats for the stable release ! This is an awesome work that you've done 😉. |
Beta Was this translation helpful? Give feedback.
-
I was thinking about allowing registration of additional “string types” that would desugar into plain PHP strings after validation, somewhat similarly to custom constructors. Possible use cases include:
Example of a workaround that technically more-or-less works, but isn't great, because <?php declare(strict_types=1);
use CuyZ\Valinor\Mapper\Source\Source;
use CuyZ\Valinor\MapperBuilder;
require('vendor/autoload.php');
final class B64String {
private string $s;
public function __construct(string $s) {
$this->s = base64_decode($s);
}
public function __toString()
{
return $this->s;
}
}
final class Target {
public function __construct(
public B64String $b64,
public string $hex,
public string $trim,
) {
}
}
$rawJson = <<<'EOT'
{
"b64": "dGVzdA==",
"hex": "74657374",
"trim": " test "
}
EOT;
$result = (new MapperBuilder())
->mapper()
->map(
Target::class,
Source::json($rawJson)
);
var_dump(strtoupper($result->b64)); |
Beta Was this translation helpful? Give feedback.
-
This topic aims to centralize discussions about the release of the first stable version (check the release notes here).
If you have ideas about missing features, please do not hesitate to comment, I'll be glad to read and answer.
Beta Was this translation helpful? Give feedback.
All reactions