orisai/nextras-object-mapper

orisai/object-mapper extension for nextras/orm

v1.x-dev 2023-07-07 17:31 UTC

This package is auto-updated.

Last update: 2024-05-07 19:22:32 UTC


README

orisai/object-mapper extension for nextras/orm

📄 Check out our documentation.

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

badge.svg 68747470733a2f2f62616467656e2e6e65742f636f766572616c6c732f632f6769746875622f6f72697361692f6e6578747261732d6f626a6563742d6d61707065722f76312e783f63616368653d333030 68747470733a2f2f62616467652e737472796b65722d6d757461746f722e696f2f6769746875622e636f6d2f6f72697361692f6e6578747261732d6f626a6563742d6d61707065722f76312e78 68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f64742f6f72697361692f6e6578747261732d6f626a6563742d6d61707065723f63616368653d33363030 68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f6f72697361692f6e6578747261732d6f626a6563742d6d61707065723f63616368653d33363030 68747470733a2f2f62616467656e2e6e65742f62616467652f6c6963656e73652f4d504c2d322e302f626c75653f63616368653d33363030

use App\User\DB\User;
use OriNextras\ObjectMapper\Rules\EntityFromId;
use Orisai\ObjectMapper\Attributes\Expect\IntValue;
use Orisai\ObjectMapper\Attributes\Modifiers\FieldName;
use Orisai\ObjectMapper\MappedObject;

final class EntityFetchingInput implements MappedObject
{

	/**
	 * @FieldName("userId")
	 * @EntityFromId(
	 *     name="userId"
	 *     entity=User::class
	 *     idRule=@IntValue(unsigned=true, castNumericString=true)
	 * )
	 */
	public User $user;

}
$data = [
	'userId' => 666,
];
$input = $processor->process($data, EntityFetchingInput::class);
// $input == EntityFetchingInput(user: User(id: 666, /* ... */))