本文整理汇总了PHP中ReflectionFunctionAbstract::getParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunctionAbstract::getParameters方法的具体用法?PHP ReflectionFunctionAbstract::getParameters怎么用?PHP ReflectionFunctionAbstract::getParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunctionAbstract
的用法示例。
在下文中一共展示了ReflectionFunctionAbstract::getParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(\ReflectionFunctionAbstract $Reflection, callable $SourceLoader)
{
$this->Reflection = $Reflection;
$this->Parameters = $this->Reflection->getParameters();
$this->UsedVariablesMap = $this->Reflection->getStaticVariables();
$this->SourceLoader = $SourceLoader;
}
示例2: collect
/**
* @inheritdoc
*/
public function collect()
{
$requirements = array();
foreach ($this->reflection->getParameters() as $parameter) {
$requirement = $this->createRequirement($parameter);
$resourceName = $requirement->getResourceName();
$requirements[$resourceName] = $requirement;
}
return $requirements;
}
示例3: getCallArgs
/**
* Python-style args/kwargs argument arrays. Creates an indexed
* argument list to use with reflection::
*
* class Pants {
* function doPants($arg1, $arg2, $arg3=null, $foo=>null) {
* }
* }
*
* $args = ['arg1', 'arg2', 'foo'=>'bar'];
* $rm = (new ReflectionClass('Pants'))->getMethod('doPants');
* $return = $rm->invokeArgs(func_get_call_args($rm), $args);
*/
public static function getCallArgs(\ReflectionFunctionAbstract $rm, $args, $ignoreUnknown = false)
{
if (!$args) {
$args = [];
}
$callArgs = [];
$inArgs = true;
foreach ($rm->getParameters() as $idx => $param) {
$paramFound = false;
if ($inArgs && ($inArgs = isset($args[$idx]))) {
$callArgs[] = $args[$idx];
$paramFound = true;
unset($args[$idx]);
} else {
if (array_key_exists($param->name, $args)) {
$paramFound = true;
$callArgs[] = $args[$param->name];
unset($args[$param->name]);
}
}
if (!$paramFound) {
if ($param->isDefaultValueAvailable()) {
$callArgs[] = $param->getDefaultValue();
} else {
throw new \UnexpectedValueException("No value for argument {$param->name} for function {$rm->getName()}");
}
}
}
if ($args && !$ignoreUnknown) {
throw new \UnexpectedValueException("Unknown keyword arguments: " . implode(", ", array_keys($args)));
}
return $callArgs;
}
示例4: __construct
public function __construct(ReflectionFunctionAbstract $method)
{
$this->name = $method->getShortName();
$this->filename = $method->getFilename();
$this->startline = $method->getStartLine();
$this->endline = $method->getEndLine();
$this->docstring = $method->getDocComment();
$this->operator = $this->static ? Kint_Object::OPERATOR_STATIC : Kint_Object::OPERATOR_OBJECT;
$this->access = Kint_Object::ACCESS_PUBLIC;
if ($method instanceof ReflectionMethod) {
$this->static = $method->isStatic();
$this->abstract = $method->isAbstract();
$this->final = $method->isFinal();
$this->owner_class = $method->getDeclaringClass()->name;
if ($method->isProtected()) {
$this->access = Kint_Object::ACCESS_PROTECTED;
} elseif ($method->isPrivate()) {
$this->access = Kint_Object::ACCESS_PRIVATE;
}
}
foreach ($method->getParameters() as $param) {
$this->parameters[] = new Kint_Object_Parameter($param);
}
if ($this->docstring) {
if (preg_match('/@return\\s+(.*)\\r?\\n/m', $this->docstring, $matches)) {
if (!empty($matches[1])) {
$this->returntype = $matches[1];
}
}
}
$docstring = new Kint_Object_Representation_Docstring($this->docstring, $this->filename, $this->startline);
$docstring->implicit_label = true;
$this->addRepresentation($docstring);
}
示例5: dumpMethodParameters
private function dumpMethodParameters(FunctionCallDefinition $definition, \ReflectionFunctionAbstract $functionReflection)
{
$args = array();
foreach ($functionReflection->getParameters() as $index => $parameter) {
if ($definition && $definition->hasParameter($index)) {
$value = $definition->getParameter($index);
if ($value instanceof EntryReference) {
$args[] = sprintf('$%s = link(%s)', $parameter->getName(), $value->getName());
} else {
$args[] = sprintf('$%s = %s', $parameter->getName(), var_export($value, true));
}
continue;
}
// If the parameter is optional and wasn't specified, we take its default value
if ($parameter->isOptional()) {
try {
$value = $parameter->getDefaultValue();
$args[] = sprintf('$%s = (default value) %s', $parameter->getName(), var_export($value, true));
continue;
} catch (\ReflectionException $e) {
// The default value can't be read through Reflection because it is a PHP internal class
}
}
$args[] = sprintf('$%s = #UNDEFINED#', $parameter->getName());
}
return implode(PHP_EOL . ' ', $args);
}
示例6: getInjections
/**
* Get the list of injectable arguments for a function or method.
*
* The returned array can be used with `call_user_func_array()` or
* `invokeArgs()`.
*
* @param \ReflectionFunctionAbstract $method
* @return array List of arguments
* @throws \RuntimeException When an argument cannot be found
*/
public function getInjections(\ReflectionFunctionAbstract $method)
{
$injections = [];
$parameters = $method->getParameters();
foreach ($parameters as $param) {
$found = false;
$injection = null;
try {
$injection = $this->findKey($param->getName());
$found = true;
} catch (\RuntimeException $e) {
}
if ($paramType = $param->getType()) {
try {
$injection = $this->findKey($paramType);
$found = true;
} catch (\RuntimeException $e) {
}
}
if (!$found && $param->isDefaultValueAvailable()) {
$injection = $param->getDefaultValue();
$found = true;
}
if (!$found) {
$paramName = $param->getName() . ' (' . $param->getType() . ')';
throw new \RuntimeException("Could not find a definition for {$paramName}.");
}
$injections[] = $injection;
}
return $injections;
}
示例7: determineRequestObjectClass
/**
* @param \ReflectionFunctionAbstract $reflectionFunction
*
* @return string
*/
private function determineRequestObjectClass(\ReflectionFunctionAbstract $reflectionFunction)
{
$reflectionParameters = $reflectionFunction->getParameters();
/** @var \ReflectionParameter $reflectionParameter */
$reflectionParameter = reset($reflectionParameters);
return $reflectionParameter->getClass()->name;
}
示例8: getParameters
protected function getParameters(\ReflectionFunctionAbstract $ref = null, array $userParams = [])
{
$parameters = [];
$expectedParameters = $ref->getParameters();
foreach ($expectedParameters as $parameter) {
$name = $parameter->getName();
$class = $parameter->getClass();
if ($parameter->isVariadic()) {
return array_merge($parameters, array_values($userParams));
}
if (isset($userParams[$name])) {
$parameters[] = $userParams[$name];
unset($userParams[$name]);
} elseif ($parameter->isDefaultValueAvailable()) {
$parameters[] = $parameter->getDefaultValue();
} elseif ($this->has($name)) {
$parameters[] = $this->get($name);
} elseif ($class) {
$parameters[] = $this->get($class->name);
} else {
throw new InjectorException("Unable to resolve parameter '{$name}'");
}
}
return $parameters;
}
示例9: resolveParameters
/**
* @param MethodInjection $definition
* @param \ReflectionFunctionAbstract $functionReflection
* @param array $parameters
*
* @throws DefinitionException A parameter has no value defined or guessable.
* @return array Parameters to use to call the function.
*/
public function resolveParameters(MethodInjection $definition = null, \ReflectionFunctionAbstract $functionReflection = null, array $parameters = [])
{
$args = [];
if (!$functionReflection) {
return $args;
}
$definitionParameters = $definition ? $definition->getParameters() : array();
foreach ($functionReflection->getParameters() as $index => $parameter) {
if (array_key_exists($parameter->getName(), $parameters)) {
// Look in the $parameters array
$value =& $parameters[$parameter->getName()];
} elseif (array_key_exists($index, $definitionParameters)) {
// Look in the definition
$value =& $definitionParameters[$index];
} else {
// If the parameter is optional and wasn't specified, we take its default value
if ($parameter->isOptional()) {
$args[] = $this->getParameterDefaultValue($parameter, $functionReflection);
continue;
}
throw new DefinitionException(sprintf("The parameter '%s' of %s has no value defined or guessable", $parameter->getName(), $this->getFunctionName($functionReflection)));
}
if ($value instanceof DefinitionHelper) {
$nestedDefinition = $value->getDefinition('');
// If the container cannot produce the entry, we can use the default parameter value
if ($parameter->isOptional() && !$this->definitionResolver->isResolvable($nestedDefinition)) {
$value = $this->getParameterDefaultValue($parameter, $functionReflection);
} else {
$value = $this->definitionResolver->resolve($nestedDefinition);
}
}
$args[] =& $value;
}
return $args;
}
示例10: resolveParameters
/**
* @param AbstractFunctionCallDefinition $definition
* @param \ReflectionFunctionAbstract $functionReflection
* @param array $parameters
*
* @throws DefinitionException A parameter has no value defined or guessable.
* @return array Parameters to use to call the function.
*/
public function resolveParameters(AbstractFunctionCallDefinition $definition = null, \ReflectionFunctionAbstract $functionReflection = null, array $parameters = array())
{
$args = array();
if (!$functionReflection) {
return $args;
}
foreach ($functionReflection->getParameters() as $index => $parameter) {
if (array_key_exists($parameter->getName(), $parameters)) {
// Look in the $parameters array
$value = $parameters[$parameter->getName()];
} elseif ($definition && $definition->hasParameter($index)) {
// Look in the definition
$value = $definition->getParameter($index);
} else {
// If the parameter is optional and wasn't specified, we take its default value
if ($parameter->isOptional()) {
$args[] = $this->getParameterDefaultValue($parameter, $functionReflection);
continue;
}
throw new DefinitionException(sprintf("The parameter '%s' of %s has no value defined or guessable", $parameter->getName(), $this->getFunctionName($functionReflection)));
}
if ($value instanceof EntryReference) {
// If the container cannot produce the entry, we can use the default parameter value
if (!$this->container->has($value->getName()) && $parameter->isOptional()) {
$value = $this->getParameterDefaultValue($parameter, $functionReflection);
} else {
$value = $this->container->get($value->getName());
}
}
$args[] = $value;
}
return $args;
}
示例11: getParameter
private function getParameter(\ReflectionFunctionAbstract $reflectionFunction, $name)
{
foreach ($reflectionFunction->getParameters() as $parameter) {
if ($parameter->getName() === $name) {
return $parameter;
}
}
}
示例12: setOrderArguments
/**
* Set correct order of arguments
*
* @param MethodDefinition $methodDefinition
* @param \ReflectionFunctionAbstract $reflectionMethod
* @throws \InvalidArgumentException
*/
public function setOrderArguments(MethodDefinition $methodDefinition, \ReflectionFunctionAbstract $reflectionMethod)
{
$parameters = [];
// Get parameter names
foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
$parameters[] = $reflectionParameter->getName();
}
$methodDefinition->setParametersCollectionOrder($parameters);
}
示例13: __construct
/**
* @param string $type
* @param mixed $value
* @param integer $position
* @param \ReflectionFunctionAbstract $func
*/
public function __construct($type, $value, $position, \ReflectionFunctionAbstract $func)
{
$this->type = $type;
$this->value = $value;
$this->position = $position;
$this->func = $func;
$params = $func->getParameters();
$this->reflection = isset($params[$position]) ? $params[$position] : null;
}
示例14: loadArguments
/**
* Populates arguments assembled from the event and the given target function.
*
* @param \ReflectionFunctionAbstract $ref
* @param EventParamResolverInterface $resolver
* @return array
*/
protected function loadArguments(\ReflectionFunctionAbstract $ref, EventParamResolverInterface $resolver)
{
$args = [];
if ($ref->getNumberOfParameters() > 1) {
foreach (array_slice($ref->getParameters(), 1) as $param) {
$args[] = $resolver->resolve($param->getClass(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : false);
}
}
return $args;
}
示例15: injectPaginatedRequest
/**
* @param \ReflectionFunctionAbstract $r
* @param Request $request
*
* @return void
*/
private function injectPaginatedRequest(\ReflectionFunctionAbstract $r, Request $request)
{
$paginatedRequest = new PaginatedRequest($request, $this->pagePath, $this->pageDefaultValue, $this->maxResultsPath, $this->maxResultsDefaultValue);
foreach ($r->getParameters() as $param) {
if (!$param->getClass() || !$param->getClass()->isInstance($paginatedRequest)) {
continue;
}
$request->attributes->set($param->getName(), $paginatedRequest);
}
}