/** * initializes instance properties from the keys/values of an array * @ignore * @access protected * @param array $attributes array of properties to set - single level * @return void */ private function _initializeFromArray($attributes) { foreach ($attributes as $name => $value) { $varName = "_{$name}"; $this->{$varName} = Util::delimiterToCamelCase($value, '_'); } }
/** * return errors for the passed html field. * For example, $result->errors->onHtmlField("transaction[customer][last_name]") * * @param string $field * @return array */ public function onHtmlField($field) { $pieces = preg_split("/[\\[\\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY); $errors = $this; foreach (array_slice($pieces, 0, -1) as $key) { $errors = $errors->forKey(Util::delimiterToCamelCase($key)); if (!isset($errors)) { return []; } } $finalKey = Util::delimiterToCamelCase(end($pieces)); return $errors->onAttribute($finalKey); }
/** * return original value for a field * For example, if a user tried to submit 'invalid-email' in the html field transaction[customer][email], * $result->valueForHtmlField("transaction[customer][email]") would yield "invalid-email" * * @param string $field * @return string */ public function valueForHtmlField($field) { $pieces = preg_split("/[\\[\\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY); $params = $this->params; foreach (array_slice($pieces, 0, -1) as $key) { $params = $params[Util::delimiterToCamelCase($key)]; } if ($key != 'custom_fields') { $finalKey = Util::delimiterToCamelCase(end($pieces)); } else { $finalKey = end($pieces); } $fieldValue = isset($params[$finalKey]) ? $params[$finalKey] : null; return $fieldValue; }