本文整理汇总了PHP中ReflectionFunction::getNumberOfParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::getNumberOfParameters方法的具体用法?PHP ReflectionFunction::getNumberOfParameters怎么用?PHP ReflectionFunction::getNumberOfParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunction
的用法示例。
在下文中一共展示了ReflectionFunction::getNumberOfParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: XLLoop_reflection_handler
function XLLoop_reflection_handler()
{
try {
$input = file_get_contents('php://input');
$value = json_decode($input);
if ($value != NULL) {
$argc = count($value->args);
$args = array();
for ($i = 0; $i < $argc; $i++) {
$args[$i] = XLLoop_decode($value->args[$i]);
}
$function = new ReflectionFunction($value->name);
if ($function->isUserDefined()) {
$reqArgc = $function->getNumberOfParameters();
for ($i = $argc; $i < $reqArgc; $i++) {
$args[$i] = 0;
}
$result = $function->invokeArgs($args);
$enc = XLLoop_encode($result);
print json_encode($enc);
} else {
print json_encode(XLLoop_encode("#Function " . $value->name . "() does not exist"));
}
} else {
print "<html><body><code>XLLoop function handler alive</code></body></html>";
}
} catch (Exception $e) {
print json_encode(XLLoop_encode("#" . $e->getMessage()));
}
}
示例2: shouldRun
private function shouldRun($callback, $controllerResult)
{
if (is_array($callback)) {
$callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
$callbackReflection = new \ReflectionObject($callback);
$callbackReflection = $callbackReflection->getMethod('__invoke');
} else {
$callbackReflection = new \ReflectionFunction($callback);
}
if ($callbackReflection->getNumberOfParameters() > 0) {
$parameters = $callbackReflection->getParameters();
$expectedControllerResult = $parameters[0];
if ($expectedControllerResult->getClass() && (!is_object($controllerResult) || !$expectedControllerResult->getClass()->isInstance($controllerResult))) {
return false;
}
if ($expectedControllerResult->isArray() && !is_array($controllerResult)) {
return false;
}
if (method_exists($expectedControllerResult, 'isCallable') && $expectedControllerResult->isCallable() && !is_callable($controllerResult)) {
return false;
}
}
return true;
}
示例3: add_internal
function add_internal($internal_classes)
{
global $functions, $internal_arginfo;
foreach ($internal_classes as $class_name) {
add_class($class_name, 0);
}
foreach (get_declared_interfaces() as $class_name) {
add_class($class_name, \ast\flags\CLASS_INTERFACE);
}
foreach (get_declared_traits() as $class_name) {
add_class($class_name, \ast\flags\CLASS_TRAIT);
}
foreach (get_defined_functions()['internal'] as $function_name) {
$function = new \ReflectionFunction($function_name);
$required = $function->getNumberOfRequiredParameters();
$optional = $function->getNumberOfParameters() - $required;
$functions[strtolower($function_name)] = ['file' => 'internal', 'avail' => true, 'conditional' => false, 'flags' => 0, 'lineno' => 0, 'endLineno' => 0, 'name' => $function_name, 'docComment' => '', 'required' => $required, 'optional' => $optional, 'ret' => null, 'params' => []];
add_param_info($function_name);
}
foreach (array_keys($internal_arginfo) as $function_name) {
if (strpos($function_name, ':') !== false) {
continue;
}
$ln = strtolower($function_name);
$functions[$ln] = ['file' => 'internal', 'avail' => false, 'conditional' => false, 'flags' => 0, 'lineno' => 0, 'endLineno' => 0, 'name' => $function_name, 'docComment' => '', 'ret' => null, 'params' => []];
add_param_info($function_name);
}
}
示例4: getNumberOfParameters
/**
* Returns the number of parameters
*
* @return integer The number of parameters
* @since PHP 5.0.3
*/
public function getNumberOfParameters()
{
if ($this->reflectionSource instanceof ReflectionFunction) {
return $this->reflectionSource->getNumberOfParameters();
} else {
return parent::getNumberOfParameters();
}
}
示例5: testClosureHasSameParameters
public function testClosureHasSameParameters()
{
$expected = new \ReflectionFunction($this->closure);
$actual = new \ReflectionFunction($this->unserializeClosure()->getClosure());
$this->assertEquals($expected->getNumberOfRequiredParameters(), $actual->getNumberOfRequiredParameters());
$this->assertEquals($expected->getNumberOfParameters(), $actual->getNumberOfParameters());
$this->assertEquals($expected->getParameters(), $actual->getParameters());
}
示例6: hash
/**
* Hash anything, return the unique identity.
*
* @param $object
* @return string
*/
protected function hash($object)
{
array_walk_recursive($object, function (&$item) {
if ($item instanceof \Closure) {
$reflection = new \ReflectionFunction($item);
$item = serialize($reflection->getClosureScopeClass()) . $reflection->getNumberOfParameters() . $reflection->getNamespaceName() . $reflection->getStartLine() . $reflection->getEndLine();
}
});
return md5(serialize($object));
}
示例7: displayGridValue
public function displayGridValue($row, Field $field)
{
$value = null;
$fieldName = $field->getFieldName();
if (array_key_exists($fieldName, $row)) {
$value = $row[$fieldName];
}
// real treatment
if (is_callable($field->getFormatValueCallback())) {
$callback = $field->getFormatValueCallback();
$reflection = new \ReflectionFunction($callback);
if ($reflection->getNumberOfParameters() == 1) {
$value = $callback($value);
} elseif ($reflection->getNumberOfParameters() == 2) {
$value = $callback($value, $row);
} else {
throw new DataGridException("Wrong number of parameters in the callback for field " . $field->getFieldName());
}
}
// send event for changing grid query builder
$event = new DataGridEvent();
$event->set("value", $value);
$event->set("row", $row);
$event->set("field", $field);
$this->dispatcher->dispatch(KitpagesDataGridEvents::ON_DISPLAY_GRID_VALUE_CONVERSION, $event);
if (!$event->isDefaultPrevented()) {
$value = $event->get("value");
if ($value instanceof \DateTime) {
$returnValue = $value->format("Y-m-d H:i:s");
} else {
$returnValue = $value;
}
$event->set("returnValue", $returnValue);
}
$this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_DISPLAY_GRID_VALUE_CONVERSION, $event);
$returnValue = $event->get("returnValue");
// auto escape ? (if null, return null, without autoescape...)
if ($field->getAutoEscape() && !is_null($returnValue)) {
$returnValue = htmlspecialchars($returnValue);
}
return $returnValue;
}
示例8: getBasicFunctionRenamesTest
public function getBasicFunctionRenamesTest()
{
$functs = $this->getBasicFunctionRenames();
foreach ($functs as $oldFunct => $newFunct) {
$oldFunctReflection = new ReflectionFunction($oldFunct);
$newFunctReflection = new ReflectionFunction($newFunct);
if ($oldFunctReflection->getNumberOfParameters() != $newFunctReflection->getNumberOfParameters()) {
var_dump($oldFunct);
}
}
}
示例9: executeClosure
/**
* Execute the closure, passing in the additional data as arguments
*
* @param Closure $value Closure to execute
* @throws \Psecio\PropAuth\Exception\MissingParametersException If not enough params were given for the closure
* @return boolean Pass/fail of evaluation
*/
private function executeClosure($value)
{
$addl = $this->getAdditional();
// Inspect the closure and ensure we have enough parameters
$info = new \ReflectionFunction($value);
$required = $info->getNumberOfParameters();
if (count($addl) < $required) {
// Here we subtract 1 because the first param (subject) is forcefully injected
throw new MissingParametersException('Not enough parameters provided for the check. (' . ($required - 1) . ' required)');
}
return call_user_func_array($value, $addl);
}
示例10: functionListFromReflectionFunction
/**
* @return Func[]
* One or more (alternate) methods begotten from
* reflection info and internal method data
*/
public static function functionListFromReflectionFunction(CodeBase $code_base, \ReflectionFunction $reflection_function) : array
{
$context = new Context();
$parts = explode('\\', $reflection_function->getName());
$method_name = array_pop($parts);
$namespace = '\\' . implode('\\', $parts);
$fqsen = FullyQualifiedFunctionName::make($namespace, $method_name);
$function = new Func($context, $fqsen->getName(), new UnionType(), 0, $fqsen);
$function->setNumberOfRequiredParameters($reflection_function->getNumberOfRequiredParameters());
$function->setNumberOfOptionalParameters($reflection_function->getNumberOfParameters() - $reflection_function->getNumberOfRequiredParameters());
return self::functionListFromFunction($function, $code_base);
}
示例11: arity
/**
* Returns an indication of the number of arguments accepted by a callable.
*
* @param callable $callback
* @return int
*/
public static function arity(callable $callback)
{
if (is_array($callback) || is_string($callback) && strpos($callback, '::') !== false) {
list($class, $method) = is_string($callback) ? explode('::', $callback) : $callback;
$reflection = (new \ReflectionClass($class))->getMethod($method);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
$reflection = (new \ReflectionClass($callback))->getMethod('__invoke');
} else {
$reflection = new \ReflectionFunction($callback);
}
return $reflection->getNumberOfParameters();
}
示例12: fresh
/**
* Introduces any number of fresh variables into scope.
*/
function fresh($f)
{
$reflection = new \ReflectionFunction($f);
$argCount = $reflection->getNumberOfParameters();
if ($argCount === 0) {
return $f();
} else {
return callFresh(function ($x) use($f, $argCount) {
return collectArgs($f, $argCount, array(), $x);
});
}
}
示例13: hash
/**
* Hash anything (except PDO connection stuff, for now).
*
* @param mixed $object
* @return string
*/
public static function hash($object)
{
$object = is_array($object) ? $object : [$object];
array_walk_recursive($object, function ($item) {
if ($item instanceof \Closure) {
$reflection = new \ReflectionFunction($item);
// Unique and fast.
$item = serialize($reflection->getClosureScopeClass()) . $reflection->getNumberOfParameters() . $reflection->getNamespaceName() . $reflection->getStartLine() . $reflection->getEndLine();
}
});
return md5(serialize($object));
}
示例14: displayGridValue
public function displayGridValue($row, Field $field)
{
// parse field name and get value after the dot
$fieldNameTab = explode('.', $field->getFieldName());
if (in_array($fieldNameTab[0], $this->rootAliases)) {
array_shift($fieldNameTab);
}
$value = $row;
while (count($fieldNameTab) > 0) {
$fieldName = array_shift($fieldNameTab);
// get parameter in the $row
$value = $value[$fieldName];
}
// $fieldName = array_shift($fieldNameTab);
// $value = $row[$fieldNameTab];
// real treatment
if (is_callable($field->getFormatValueCallback())) {
$callback = $field->getFormatValueCallback();
$reflection = new \ReflectionFunction($callback);
if ($reflection->getNumberOfParameters() == 1) {
$returnValue = $callback($value);
} elseif ($reflection->getNumberOfParameters() == 2) {
$returnValue = $callback($value, $row);
} else {
throw new DataGridException("Wrong number of parameters in the callback for field " . $field->getFieldName());
}
} elseif (is_scalar($value)) {
$returnValue = $value;
} elseif ($value instanceof \DateTime) {
$returnValue = $value->format("Y-m-d H:i:s");
} else {
$returnValue = $value;
}
// auto escape ?
if ($field->getAutoEscape()) {
$returnValue = htmlspecialchars($returnValue);
}
return $returnValue;
}
示例15: __construct
public function __construct($function)
{
parent::__construct();
try {
$ref = new ReflectionFunction($function);
$this->_function = $ref;
$this->_args = $ref->getParameters();
$this->_args_cnt = $ref->getNumberOfParameters();
$this->_available = true;
} catch (Exception $ex) {
$this->_function = $function;
$this->_available = false;
}
}