本文整理汇总了PHP中ReflectionFunction::getNumberOfRequiredParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::getNumberOfRequiredParameters方法的具体用法?PHP ReflectionFunction::getNumberOfRequiredParameters怎么用?PHP ReflectionFunction::getNumberOfRequiredParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunction
的用法示例。
在下文中一共展示了ReflectionFunction::getNumberOfRequiredParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: getReflectedMinimumParams
function getReflectedMinimumParams($name)
{
// Reflection gets this one wrong.
if (strcasecmp($name, 'define') == 0) {
return 2;
}
if (strcasecmp($name, 'strtok') == 0) {
return 1;
}
if (strcasecmp($name, 'implode') == 0) {
return 1;
}
if (strcasecmp($name, "sprintf") == 0) {
return 1;
}
if (strcasecmp($name, "array_merge") == 0) {
return 1;
}
if (strcasecmp($name, "stream_set_timeout") == 0) {
return 2;
}
try {
$func = new \ReflectionFunction($name);
return $func->getNumberOfRequiredParameters();
} catch (\ReflectionException $e) {
return -1;
}
}
示例3: evaluate
/**
* Evaluate
*
* @param \Closure $other
* @param string $description Additional information about the test
* @param bool $returnResult Whether to return a result or throw an exception
* @return boolean
*/
public function evaluate($other, $description = '', $returnResult = FALSE)
{
if (!$other instanceof \Closure) {
$this->_cause = 'Variable must be a Closure';
if ($returnResult) {
return FALSE;
}
$this->fail($other, $description);
}
$reflection = new \ReflectionFunction($other);
$requiredParameters = new \PHPUnit_Framework_Constraint_IsEqual(1);
if (false === $requiredParameters->evaluate($reflection->getNumberOfRequiredParameters(), $description, true)) {
$this->_cause = 'Closure does not have 1 required parameter';
if ($returnResult) {
return FALSE;
}
$this->fail($other, $description);
}
$params = $reflection->getParameters();
$tokenParameter = $params[0];
/* @var $tokenParameter \ReflectionParameter */
$parameterType = new \PHPUnit_Framework_Constraint_IsEqual('PHP\\Manipulator\\Token');
if (false === $parameterType->evaluate($tokenParameter->getClass()->name, $description, true)) {
$this->_cause = 'Closures Token-Parameter has wrong Typehint';
if ($returnResult) {
return FALSE;
}
$this->fail($other, $description);
}
return true;
}
示例4: 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);
}
foreach (get_declared_traits() as $class_name) {
add_class($class_name);
}
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', 'namespace' => $function->getNamespaceName(), '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);
}
}
示例5: getNumberOfRequiredParameters
/**
* Returns the number of required parameters
*
* @return integer The number of required parameters
* @since PHP 5.0.3
*/
public function getNumberOfRequiredParameters()
{
if ($this->reflectionSource instanceof ReflectionFunction) {
return $this->reflectionSource->getNumberOfRequiredParameters();
} else {
return parent::getNumberOfRequiredParameters();
}
}
示例6: 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());
}
示例7: foreach
function __invoke()
{
$args = func_get_args();
foreach ($this->cases as $k => $v) {
if (is_callable($v->condition)) {
$vc = new \ReflectionFunction($v->condition);
// reduce mistaken hits by only calling the condition on cases when there aren't too many or too few args
// the || 0 case is a special one when the condition function hasn't taken any paramenters. Then we should always invoke the function to check because it is presumably using func_get_args() or is our $always condition
if ($vc->getNumberOfParameters() <= count($args) && ($vc->getNumberOfRequiredParameters() == 0 || $vc->getNumberOfRequiredParameters() >= count($args)) && $vc->invokeArgs($args)) {
$vf = new \ReflectionFunction($v->f);
return $vf->invokeArgs($args);
}
} elseif ($v->condition === $args || count($args) === 1 && $v->condition === $args[0]) {
$vf = new \ReflectionFunction($v->f);
return $vf->invokeArgs($args);
}
}
throw new \UnexpectedValueException("No conditions matched the given input:" . $args);
}
示例8: onCreate
public function onCreate()
{
$this->closed = false;
if (!is_callable($this->params)) {
throw new InvalidArgumentException('No valid callback parameter given to stream_filter_(append|prepend)');
}
$this->callback = $this->params;
// callback supports end event if it accepts invocation without arguments
$ref = new ReflectionFunction($this->callback);
$this->supportsClose = $ref->getNumberOfRequiredParameters() === 0;
return true;
}
示例9: array
function __construct($callable, $argumentCommands = array())
{
if (!is_callable($callable)) {
throw new \InvalidArgumentException();
}
$this->callable = $callable;
foreach ($argumentCommands as $argumentCommand) {
if (!$argumentCommand instanceof CommandInterface) {
throw new \InvalidArgumentException();
}
}
$reflection = new \ReflectionFunction($this->callable);
if (sizeof($argumentCommands) < $reflection->getNumberOfRequiredParameters()) {
throw new \FormulaInterpreter\Exception\NotEnoughArgumentsException();
}
$this->argumentCommands = $argumentCommands;
}
示例10: getNumberOfRequiredParametersForRule
/**
* Get all rules
*
* @return Integer
*/
public function getNumberOfRequiredParametersForRule($ruleName)
{
$rc = new \ReflectionClass($this->RuleList);
try {
$rm = $rc->getMethod($ruleName);
} catch (\Exception $e) {
}
if (isset($rm)) {
return $rm->getNumberOfRequiredParameters();
} else {
if (isset($this->RuleList->closures[$ruleName])) {
$rf = new \ReflectionFunction($this->RuleList->closures[$ruleName]);
return $rf->getNumberOfRequiredParameters();
}
}
return 0;
}
示例11: validateCallback
/**
* Ensure that this callback takes no arguments
*
* @param callable $cb
*/
public static function validateCallback(callable $cb)
{
if (is_string($cb) and strpos($cb, "::") !== false) {
$cb = explode("::", $cb);
}
if (is_string($cb) or $cb instanceof \Closure) {
$function = new \ReflectionFunction($cb);
if ($function->getNumberOfRequiredParameters() > 0) {
throw new \InvalidArgumentException("Callable requires parameters");
}
} elseif (is_array($cb)) {
list($ctx, $m) = $cb;
$method = new \ReflectionMethod($ctx, $m);
if ($method->getNumberOfRequiredParameters() > 0) {
throw new \InvalidArgumentException("Callable requires parameters");
}
}
}
示例12: testManuallyDb
/**
* @dataProvider getFunctions
*
* @param string $functionName
*/
public function testManuallyDb($functionName)
{
$reflection = $this->getReflector()->getFunction($functionName);
if ($reflection) {
try {
$standardFunctionReflection = new \ReflectionFunction($functionName);
} catch (\ReflectionException $e) {
parent::markTestSkipped('Function doest not exist');
return;
}
parent::assertSame($standardFunctionReflection->getNumberOfRequiredParameters(), $reflection->getNumberOfRequiredParameters());
parent::assertSame($standardFunctionReflection->getNumberOfParameters(), $reflection->getNumberOfParameters());
if ($reflection->getNumberOfParameters()) {
foreach ($reflection->getParameters() as $key => $parameter) {
parent::assertSame($parameter, $reflection->getParameter($key));
parent::assertNotEmpty($parameter->getName());
parent::assertInternalType('integer', $parameter->getType());
parent::assertInternalType('boolean', $parameter->isRequired());
}
}
return;
}
parent::markTestSkipped('Unknown manually reflection for function: ' . $functionName);
}
示例13: ignore_err
<?php
$funcs = get_extension_funcs("intl");
function ignore_err()
{
}
set_error_handler("ignore_err");
$arg = new stdClass();
foreach ($funcs as $func) {
$rfunc = new ReflectionFunction($func);
if ($rfunc->getNumberOfRequiredParameters() == 0) {
continue;
}
try {
$res = $func($arg);
} catch (Exception $e) {
continue;
}
if ($res != false) {
echo "{$func}: ";
var_dump($res);
}
}
echo "OK!\n";
示例14: getEndLine
var_dump($rf->getStartLine());
print "\n";
print "--- getEndLine(\"f\") ---\n";
var_dump($rf->getEndLine());
print "\n";
print "--- getFileName(\"f\") ---\n";
var_dump($rf->getFileName());
print "\n";
print "--- getName(\"f\") ---\n";
var_dump($rf->getName());
print "\n";
print "--- getNumberOfParameters(\"f\") ---\n";
var_dump($rf->getNumberOfParameters());
print "\n";
print "--- getNumberOfRequiredParameters(\"f\") ---\n";
var_dump($rf->getNumberOfRequiredParameters());
print "\n";
print "--- getParameters(\"f\") ---\n";
var_dump($rf->getParameters());
print "\n";
print "--- getStaticVariables(\"f\") ---\n";
var_dump($rf->getStaticVariables());
print "\n";
print "--- isInternal(\"f\") ---\n";
var_dump($rf->isInternal());
print "\n";
print "--- isUserDefined(\"f\") ---\n";
var_dump($rf->isUserDefined());
print "\n";
print "--- returnsReference(\"f\") ---\n";
var_dump($rf->returnsReference());
示例15: n_required_args
/**
* Uses reflection to determine the number of required arguements for a callable
*
* NOTE: This will only consider *required* arguments, i.e. optional and variadic
* arguments do *not* contribute to the count
*/
function n_required_args(callable $f)
{
/*
* Get an appropriate reflector
*
* If we have some kind of method (static or instance), this should be a
* ReflectionMethod
*
* If we have a function name or closure, this should be a ReflectionFunction
*/
$reflector = null;
if (is_array($f)) {
// If we have an array, that is a method
$reflector = new \ReflectionMethod($f[0], $f[1]);
} elseif (is_string($f) && strpos($f, '::') !== false) {
// If we have a string containing '::', that is a static method
$reflector = new \ReflectionMethod($f);
} else {
// Otherwise, we have some kind of function
$reflector = new \ReflectionFunction($f);
}
return $reflector->getNumberOfRequiredParameters();
}