/** * @static * * @param string $name * @param Closure $func * @param null|array $provided * * @return bool * @throws TemplateSyntaxError */ public static function argsCheck($name, $func, $provided) { if (!is_array($provided)) { $provided = array($provided); } $plen = count($provided); list($args, $varargs, $varkw, $defaults) = py_inspect_getargspec($func); // First argument is filter input. py_arr_pop($args, 0); if ($defaults) { $nondefs = py_slice($args, null, -count($defaults)); } else { $nondefs = $args; } // Args without defaults must be provided. try { foreach ($nondefs as $arg) { py_arr_pop($provided, 0); } } catch (IndexError $e) { // Not enough throw new TemplateSyntaxError($name . ' requires ' . count($nondefs) . ' arguments, ' . $plen . ' provided'); } // Defaults can be overridden. try { foreach ($provided as $parg) { py_arr_pop($defaults, 0); } } catch (IndexError $e) { // Too many. throw new TemplateSyntaxError($name . ' requires ' . count($nondefs) . ' arguments, ' . $plen . ' provided'); } return True; }
public function __invoke() { $input_args = func_get_args(); $args_exp_ = py_inspect_getargspec(array($this->_obj, $this->_attr)); if (count($args_exp_[0]) > count($input_args)) { // Naive check. throw new TypeError(); // Simulate arguments required type error. } return call_user_func_array(array($this->_obj, $this->_attr), $input_args); }