xakepehok / value-object-builder
This helper can create object from passed classname and value, or return null, if passed value is also null
Installs: 4 986
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.0
This package is auto-updated.
Last update: 2024-10-19 23:25:32 UTC
README
Installation
composer require xakepehok/value-object-builder
Example without VOB:
<?php $value = $_POST['value'] ?? null; $object = $value ? new Object($value) : null;
Example with VOB:
<?php use \XAKEPEHOK\ValueObjectBuilder\VOB; $object = VOB::build(Object::class, $_POST['value'] ?? null);
Example without VOB:
<?php $value_1 = $_POST['value_1'] ?? null; $value_2 = $_POST['value_2'] ?? null; $value_3 = $_POST['value_3'] ?? null; $object = null; if (!is_null($value_1) || !is_null($value_2) || !is_null($value_3)) { $object = new Object($value_1, $value_2, $value_3); }
Example with VOB:
<?php use \XAKEPEHOK\ValueObjectBuilder\VOB; $object = VOB::buildFromValues(Object::class, [$_POST['value_1'] ?? null, $_POST['value_2'] ?? null, $_POST['value_3'] ?? null]);