Reflection > setPropertiesValues() method > sets values of properties in given object

This commit is contained in:
Meritoo
2018-11-03 08:51:22 +01:00
parent 06fbf63e09
commit 8e9dcb3206
2 changed files with 158 additions and 0 deletions

View File

@@ -692,4 +692,25 @@ class Reflection
$reflectionProperty->setAccessible(false);
}
}
/**
* Sets values of properties in given object
*
* @param mixed $object Object that should contains given property
* @param array $propertiesValues Key-value pairs, where key - name of the property, value - value of the property
*/
public static function setPropertiesValues($object, array $propertiesValues)
{
/*
* No properties?
* Nothing to do
*/
if (empty($propertiesValues)) {
return;
}
foreach ($propertiesValues as $property => $value) {
static::setPropertyValue($object, $property, $value);
}
}
}