orisai / nette-object-mapper

[WIP] Orisai Object Mapper integration for Nette

download-cloud-line composer require orisai/nette-object-mapper

Nette Object Mapper

Orisai Object Mapper integration for Nette

📄 Check out our documentation.

💸 If you like Orisai, please make a donation. Thank you!

use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Attributes\Expect\MappedObjectValue;
use Orisai\ObjectMapper\Attributes\Expect\StringValue;

final class UserInput implements MappedObject

	/** @StringValue(notEmpty=true) */
	public string $firstName;

	/** @StringValue(notEmpty=true) */
	public string $lastName;

	/** @MappedObjectValue(UserAddressInput::class) */
	public UserAddressInput $address;

use Orisai\ObjectMapper\MappedObject;

final class UserAddressInput implements MappedObject
	// ...
use Orisai\ObjectMapper\Exception\InvalidData;
use Orisai\ObjectMapper\Printers\ErrorVisualPrinter;
use Orisai\ObjectMapper\Printers\TypeToStringConverter;
use Orisai\ObjectMapper\Processing\DefaultProcessor;

$processor = new DefaultProcessor(...);
$errorPrinter = new ErrorVisualPrinter(new TypeToStringConverter());

$data = [
	'firstName' => 'Willy',
	'lastName' => 'Wonka',
	'address' => [],

try {
	$user = $processor->process($data, UserInput::class);
} catch (InvalidData $exception) {
	$error = $errorPrinter->printError($exception);

	throw new Exception("Validation failed due to following error:\n$error");

echo "User name is: {$user->firstName} {$user->lastName}";

No release at this moment. Try to create first one.

Componette Componette