Skip to content

Commit

Permalink
Fix PHP 5.3 compatibility issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Aug 30, 2016
1 parent 9e7f298 commit 5bf39f1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,23 @@ abstract class AbstractRequest extends OmnipayAbstractRequest
*/
protected function filterHashFields($data)
{
$hash_data = array_filter($data, function($key) {
// If the key is an array element then normalise it, e.g. pr[1] => px[x]
foreach($data as $key => $value) {
// If the key is an array element then normalise it, e.g. pr[1] => pr[x]
if (strpos($key, '[')) {
$key = preg_replace('/\[[0-9]*\]/', '[x]', $key);
$normalised_key = preg_replace('/\[[0-9]*\]/', '[x]', $key);
} else {
$normalised_key = $key;
}

return in_array($key, $this->hash_fields);
}, ARRAY_FILTER_USE_KEY);
// If the normalised key is not in the list of hashable keys,
// then remove that element from the supplied data.
if (! in_array($normalised_key, $this->hash_fields)) {
unset($data[$key]);
}
}

return $hash_data;
// Return the data array with non-hashable elements removed.
return $data;
}

/**
Expand Down

0 comments on commit 5bf39f1

Please sign in to comment.