Skip to content

Instantly share code, notes, and snippets.

@alnutile
Last active December 25, 2015 06:38
Show Gist options
  • Save alnutile/6933056 to your computer and use it in GitHub Desktop.
Save alnutile/6933056 to your computer and use it in GitHub Desktop.
Services
//protected function resolveController($resource, &$operation)
if ( $request_method == 'POST'
&& $canon_path_count >= 2
&& isset($resource['targeted_actions'][$canonical_path_array[1]])
&& $this->checkNumberOfArguments($canon_path_count, $resource['targeted_actions'][$canonical_path_array[1]], 1)
&& !empty($canonical_path_array[0])
) {
$operation_type = 'targeted_actions';
$operation = $canonical_path_array[1];
}
//This called the arguments I needed to match
/**
* Count possible numbers of 'path' arguments of the method.
*/
protected function checkNumberOfArguments($args_number, $resource_operation, $required_args = 0) {
$not_required_args = 0;
if (isset($resource_operation['args'])) {
foreach ($resource_operation['args'] as $argument) {
if (isset($argument['source']) && is_array($argument['source']) && isset($argument['source']['path'])) {
if (!empty($argument['optional'])) {
$not_required_args++;
}
else {
$required_args++;
}
}
}
}
return $args_number >= $required_args && $args_number <= $required_args + $not_required_args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment