Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
Adds logic to get all ResolveData keys when more then one exists in t…
Browse files Browse the repository at this point in the history
…he response
  • Loading branch information
Craig Paul committed Oct 26, 2016
1 parent efed307 commit c239377
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions src/Preparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,46 @@ protected function prepare($data, array $params)
$key = $param['key'];
$property = $param['property'];

if (is_array($data)) {
$array[$property] = isset($data[$key]) && !is_null($data[$key]) ? $data[$key] : null;
if ($key === 'ResolveData' && count($data->xpath('//ResolveData')) > 1) {
$resolves = $data->xpath('//ResolveData');

foreach($resolves as $index => $resolve) {
$resolves[$index] = array_map('strval', (array)$resolve);
}

$array[$property] = $resolves;
} else {
$array[$property] = isset($data->$key) && !is_null($data->$key) ? $data->$key : null;
}
if (is_array($data)) {
$array[$property] = isset($data[$key]) && !is_null($data[$key]) ? $data[$key] : null;
} else {
$array[$property] = isset($data->$key) && !is_null($data->$key) ? $data->$key : null;
}

if (isset($param['cast'])) {
switch ($param['cast']) {
case 'boolean':
$array[$property] = isset($array[$property]) ? (is_string($array[$property]) ? $array[$property] : $array[$property]->__toString()) : null;
$array[$property] = isset($array[$property]) && !is_null($array[$property]) ? ($array[$property] === 'true' ? true : false) : false;
if (isset($param['cast'])) {
switch ($param['cast']) {
case 'boolean':
$array[$property] = isset($array[$property]) ? (is_string($array[$property]) ? $array[$property] : $array[$property]->__toString()) : null;
$array[$property] = isset($array[$property]) && !is_null($array[$property]) ? ($array[$property] === 'true' ? true : false) : false;

break;
case 'float':
$array[$property] = isset($array[$property]) ? (is_string($array[$property]) ? floatval($array[$property]) : floatval($array[$property]->__toString())) : null;
break;
case 'float':
$array[$property] = isset($array[$property]) ? (is_string($array[$property]) ? floatval($array[$property]) : floatval($array[$property]->__toString())) : null;

break;
case 'string':
$array[$property] = isset($array[$property]) ? (is_string($array[$property]) ? $array[$property] : $array[$property]->__toString()) : null;
break;
case 'string':
$array[$property] = isset($array[$property]) ? (is_string($array[$property]) ? $array[$property] : $array[$property]->__toString()) : null;

break;
case 'array':
$array[$property] = (array)$array[$property];
break;
case 'array':
$array[$property] = (array)$array[$property];
}
}
}

if (isset($param['callback'])) {
$callback = $param['callback'];
if (isset($param['callback'])) {
$callback = $param['callback'];

$array[$property] = $this->$callback($array[$property]);
$array[$property] = $this->$callback($array[$property]);
}
}
}

Expand Down

0 comments on commit c239377

Please sign in to comment.