Download the PHP package kenny1911/populate without Composer
On this page you can find all versions of the php package kenny1911/populate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package populate
PHP Populate
PHP Populate
is a library for fill attributes from source object to destination object.
For example, you can use this library to automatic fill properties from DTO to ORM entity.
Install
Usage
Simple usage
To fill in an object's fields with values from another object, use method
Kenny1911\Populate\PopulateInterface::populate()
. Arguments of method:
$src
- Source array or object from which values will be taken.$dest
- Destination object.$properties
- Array of allowed properties to be updated.$ignoreProperties
- Array of denied properties not to be updated.$mapping
- Key-value map to match property names from source object ($src
) and destination object ($dest
). Key - property name in$src
, value - in$dest
.
Use PopulateBuilder
for creating new PopulateInterface
instance:
Advanced usage
You may need to use it with preset settings of arguments $properties
, $ignoreProperties
and $mapping
. You can use
AdvancedPopulate
for it:
Preset settings won't use if you will use
$properties
and$ignoreProperties
arguments.If you set
$mapping
argument, it will merge with preset mapping.
Integrate with Symfony
-
Register bundle in
config/bundles.php
: - Create file
config/packages/populate.yaml
. Example:
Now, you can inject PopulateInterface
to your own services.
Also, you can use public symfony service populate
:
All versions of populate with dependencies
symfony/property-access Version ^4.0.0|^5.0.0
symfony/property-info Version ^4.0.0|^5.0.0