Created
June 27, 2011 17:05
-
-
Save bshaffer/1049286 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SN_SoapClient extends SoapClient | |
{ | |
// ... | |
protected function fixArgs($function_name, $arguments) | |
{ | |
// get the arguments for the function | |
$parameters = array_flip($this->getFunctionArguments($function_name)); | |
if ($invalidParameters = array_diff_key($arguments, $parameters)) { | |
throw new Exception("Soap function $function_name does not support the following parameters: ". implode(', ', array_keys($invalidParameters))); | |
} | |
//Use the parameter names as keys | |
$orderedArguments = array_merge($parameters, $arguments); | |
return $orderedArguments; | |
} | |
protected function getFunctionArguments($function_name) | |
{ | |
$functions = $this->__getFunctions(); | |
$listRegex = '/list\(([^)]+)\) ([^(]+)\(([^)]+)/'; | |
$singleRegex = '/([^ ]+) ([^(]+)\(([^)]+)/'; | |
foreach ($functions as $function) { | |
$regex = ('list(' === substr($function, 0, 5)) ? $listRegex : $singleRegex; | |
preg_match($regex, $function, $matches); | |
if ($matches[2] === $function_name) { | |
$output = explode(', ', $matches[1]); // not being used, but maybe later | |
$input = explode(', ', $matches[3]); | |
$orderedParameters = array(); | |
foreach ($input as $key => $value) { | |
$orderedParameters[] = substr($value, strpos($value, '$') + 1); | |
} | |
return $orderedParameters; | |
} | |
} | |
throw new Exception("Soap function $function_name does not exist"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment