/searchPattern/replace/ * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public static function bind($source, $target, $propertyPattern = null) { $binderObject = new BinderObject(); $binderObject->bindObjectInternal($source, $target, $propertyPattern); } /** * Bind the properties from a source object to the properties matching to a target object * * @param mixed $source * @param mixed $target * @param string $propertyPattern Regular Expression -> /searchPattern/replace/ * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ protected function bindObjectInternal($source, $target, $propertyPattern = null) { if (is_array($target) || !is_object($target)) { throw new InvalidArgumentException('Target object must have to be an object instance'); } $sourceArray = SerializerObject::instance($source) ->withStopAtFirstLevel() ->serialize(); foreach ($sourceArray as $propName => $value) { if (!is_null($propertyPattern)) { $propAr = explode($propertyPattern[0], $propertyPattern); $propName = preg_replace( $propertyPattern[0] . $propAr[1] . $propertyPattern[0], $propAr[2], $propName ); } $this->setPropValue($target, $propName, $value); } } /** * Set the property value * * @param mixed $obj * @param string $propName * @param string $value */ protected function setPropValue($obj, $propName, $value) { if (method_exists($obj, 'set' . $propName)) { $obj->{'set' . $propName}($value); } elseif (isset($obj->{$propName}) || $obj instanceof stdClass) { $obj->{$propName} = $value; } else { // Check if source property have property case name different from target $className = get_class($obj); if (!isset($this->propNameLower[$className])) { $this->propNameLower[$className] = []; $classVars = get_class_vars($className); foreach ($classVars as $varKey => $varValue) { $this->propNameLower[$className][strtolower($varKey)] = $varKey; } } $propLower = strtolower($propName); if (isset($this->propNameLower[$className][$propLower])) { $obj->{$this->propNameLower[$className][$propLower]} = $value; } } } } __halt_compiler();----SIGNATURE:----VfXaCeAgD8lxleL29PJzLZGx6OmzG04j/fD0JJc9Nzg4upGjMmmmT/odZhZWbi/5QvHsxTjQ6AKB7xOlPBZrK4SLN8Knk9KiFzmOmCqJ6iyqYC3IIHT6cItuDGqRVEb7Vk0Of9F5cFC3b8tdYvKKg6F711F5rw528WBWevgnGqHtc+ag0kgmFq2a6psJvQfPcAGSDPXQj4AhnSpgl//o2Uyota13v1c0AeCVqOIVT+vYu4ImSfGPxrNeAzRnqcnRKe+aBsnrdEhWkE/MdESTL14toYNnd/y2DItiSEISpcIfp6iWaqUd1CAuwFR9mLLPXPNzfYf5zlsNAeAQ4OY+fYAaWD1iYPMcM92ZgOdoOSrPL/Q6HDIb049hf3FiBTEa6KyQyi9ebv00WyoWxZ/NmyecgabyVmGUT0Z8XKWF3be+ifUW4Kpv4Nh3/MvwafRwxOrn4mJyhsXnk7vWMGgIb3OLk0JIUutur5AO/3Fc/AWaRrhLkuDSCvMc4TrWD2GuOzmN4aPjnG2E3I2uYMnbO3Yr4xlD5j2MxOZQ/cKxbLUwHXqQwY0Mhx9O8DVR7lqP/K8T8iMZqsj3YImi7f4LfVYxStAVKanzmLjBeh6lX2RMIW0va9Uhnw8MzlZfoELBsMuY9SfCLoAOit1tweH6LiZcDW2o6Dl2DozBFDzRkzo=----ATTACHMENT:----NzI4MTA1MTg0NjgyMjQyNSA0MDU1OTM4MDg0NDgxNzU0IDQ0NTg3Mzc0ODIzMzY3MzQ=