/** * Sets public attributes on an object to those held in an associative array. * By default does not copy entries in the array that do not correspond * to an attribute in the object. Also takes an optional array * of fields to ignore. * * @param array $array Associative array of values * @param object $object Object to copy to * @param boolean $ignoreMissingAttributes If True does not copy attributes not found * in the object * @param array $ignoreFields Array of fields to ignore */ function bindArrayToObject($array, &$object, $ignoreMissingAttributes = true, $ignoreFields = array()) { $allowedKeys = array_keys($array); $allowedKeys = array_diff($allowedKeys, $ignoreFields); if (true === $ignoreMissingAttributes) { $allowedKeys = array_intersect($allowedKeys, ObjectHelper::getPublicProperties($object)); } if (is_array($array) && is_object($object)) { foreach ($allowedKeys as $key) { $object->{$key} = true === isset($array[$key]) ? $array[$key] : null; } } return true; }
/** * Sets public attributes on an object to those held in another object * By default does not copy entries in the array that do not correspond * to an attribute in the object. Also takes an optional array * of fields to ignore. * * @param object $src Object to copy from * @param object $dest Object to copy to * @param boolean $ignoreObjectsArrays If True objects and arrays are not copied * @param boolean $ignoreMissingAttributes If True does not copy attributes not found * in the object * @param array $ignoreFields Array of fields to ignore */ function shallowCopy(&$src, &$dest, $ignoreObjectsArrays = true, $ignoreMissingAttributes = true, $ignoreFields = array()) { $allowedKeys = ObjectHelper::getPublicProperties($src, $ignoreFields); if (true === $ignoreMissingAttributes) { $allowedKeys = array_intersect($allowedKeys, ObjectHelper::getPublicProperties($dest, $ignoreFields)); } if (true === is_array($allowedKeys) && true === is_object($dest)) { foreach ($allowedKeys as $key) { $value = $src->{$key}; if (true === is_object($value) || true === is_array($value)) { if ($ignoreObjectsArrays) { continue; } else { $dest->{$key} =& $value; } } else { $dest->{$key} = $value; } } } return true; }
/** * Returns a list of columns, one for each public attribute of the delegate * * @access protected * @return array List of columns */ function _getColumns() { return ObjectHelper::getPublicProperties($this); }