Takes an object and converts its properties => values to an associative
array of $Array[Property] => Value sets.
public static objectAsArray ( object $Object ) : unknown | ||
$Object | object | The object to be converted to an array. |
return | unknown |
/** * * * @param $Var * @param array $BlackList */ function cleanErrorArguments(&$Var, $BlackList = array('configuration', 'config', 'database', 'password')) { if (is_array($Var)) { foreach ($Var as $Key => $Value) { if (in_array(strtolower($Key), $BlackList)) { $Var[$Key] = 'SECURITY'; } else { if (is_object($Value)) { $Value = Gdn_Format::objectAsArray($Value); $Var[$Key] = $Value; } if (is_array($Value)) { cleanErrorArguments($Var[$Key], $BlackList); } } } } }
/** * Assign a set of data to be displayed in the form elements. * * @param array $Data A result resource or associative array containing data to be filled in */ public function setData($Data) { if (is_object($Data) === true) { // If this is a result object (/garden/library/database/class.dataset.php) // retrieve it's values as arrays if ($Data instanceof DataSet) { $ResultSet = $Data->resultArray(); if (count($ResultSet) > 0) { $this->_DataArray = $ResultSet[0]; } } else { // Otherwise assume it is an object representation of a data row. $this->_DataArray = Gdn_Format::objectAsArray($Data); } } elseif (is_array($Data)) { $this->_DataArray = $Data; } }
/** * Adds values to the $this->_Sets collection. Allows for the inserting * and updating of values to the db. * * @param mixed $Field The name of the field to save value as. Alternately this can be an array * of $FieldName => $Value pairs, or even an object of $DataSet->Field properties containing one rowset. * @param string $Value The value to be set in $Field. Ignored if $Field was an array or object. * @param boolean $EscapeString A boolean value indicating if the $Value(s) should be escaped or not. * @param boolean $CreateNewNamedParameter A boolean value indicating that if (a) a named parameter is being * created, and (b) that name already exists in $this->_NamedParameters * collection, then a new one should be created rather than overwriting the * existing one. * @return Gdn_SQLDriver $this Returns this for fluent calls * @throws \Exception Throws an exception if an invalid type is passed for {@link $Value}. */ public function set($Field, $Value = '', $EscapeString = true, $CreateNewNamedParameter = true) { $Field = Gdn_Format::objectAsArray($Field); if (!is_array($Field)) { $Field = array($Field => $Value); } foreach ($Field as $f => $v) { if (is_array($v) || is_object($v)) { throw new Exception('Invalid value type (' . gettype($v) . ') in INSERT/UPDATE statement.', 500); } else { if (in_array(substr($f, -1), ['+', '-'], true)) { // This is an increment/decrement. $op = substr($f, -1); $f = substr($f, 0, -1); $parameter = $this->namedParameter($f, $CreateNewNamedParameter); $this->_NamedParameters[$parameter] = $v; $this->_Sets[$this->escapeIdentifier($f)] = $this->escapeIdentifier($f) . " {$op} " . $parameter; } elseif ($EscapeString) { $NamedParameter = $this->namedParameter($f, $CreateNewNamedParameter); $this->_NamedParameters[$NamedParameter] = $v; $this->_Sets[$this->escapeIdentifier($f)] = $NamedParameter; } else { $this->_Sets[$this->escapeIdentifier($f)] = $v; } } } return $this; }