本文整理汇总了PHP中ReflectionFunctionAbstract类的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunctionAbstract类的具体用法?PHP ReflectionFunctionAbstract怎么用?PHP ReflectionFunctionAbstract使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReflectionFunctionAbstract类的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: 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;
}
示例3: determineRequestObjectClass
/**
* @param \ReflectionFunctionAbstract $reflectionFunction
*
* @return string
*/
private function determineRequestObjectClass(\ReflectionFunctionAbstract $reflectionFunction)
{
$reflectionParameters = $reflectionFunction->getParameters();
/** @var \ReflectionParameter $reflectionParameter */
$reflectionParameter = reset($reflectionParameters);
return $reflectionParameter->getClass()->name;
}
示例4: 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;
}
示例5: 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;
}
示例6: getClassName
/**
* Helper class for getFunctionName().
*
* @param \ReflectionFunctionAbstract $function
* @return string
*/
private static function getClassName(\ReflectionFunctionAbstract $function)
{
if ($function instanceof \ReflectionMethod) {
return $function->getDeclaringClass()->getName() . '::';
}
return '';
}
示例7: getReflectionFunctionName
/**
* Helper method to retrieve the name of a ReflectionFunctionAbstract
* @param \ReflectionFunctionAbstract $reflection
* @return string
*/
protected function getReflectionFunctionName(\ReflectionFunctionAbstract $reflection)
{
// Class method
if ($reflection instanceof \ReflectionMethod) {
return $reflection->getDeclaringClass()->getName() . '::' . $reflection->getName();
}
return $reflection->getName();
}
示例8: getParameter
private function getParameter(\ReflectionFunctionAbstract $reflectionFunction, $name)
{
foreach ($reflectionFunction->getParameters() as $parameter) {
if ($parameter->getName() === $name) {
return $parameter;
}
}
}
示例9: fetchFunctionIdentifier
private function fetchFunctionIdentifier(\ReflectionFunctionAbstract $function)
{
$functionIdentifier = $function->getName();
if ($function instanceof \ReflectionMethod) {
$functionIdentifier = sprintf('%s::%s', $function->getDeclaringClass()->getName(), $function->getName());
}
return $functionIdentifier;
}
示例10: getFunctionName
/**
* @param \ReflectionFunctionAbstract $reflection
*
* @return string
*/
protected static function getFunctionName(\ReflectionFunctionAbstract $reflection)
{
$name = $reflection->name . '()';
if ($reflection instanceof \ReflectionMethod) {
$name = $reflection->getDeclaringClass()->name . '::' . $name;
}
return $name;
}
示例11: __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;
}
示例12: fetchCode
/**
* @param \ReflectionFunctionAbstract $reflection
*
* @return string
*/
protected function fetchCode(\ReflectionFunctionAbstract $reflection)
{
$file = $reflection->getFileName();
if (!file_exists($file)) {
return '';
}
$startLine = $reflection->getStartLine();
return implode('', array_slice(file($file), $startLine, $reflection->getEndLine() - $startLine - 1));
}
示例13: generateForParameter
/**
* Generate key for parameter
*
* @param \ReflectionParameter $parameter
* @param \ReflectionFunctionAbstract $method
*
* @return string
*/
public static function generateForParameter(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $method)
{
if ($method instanceof \ReflectionMethod) {
$key = $method->getDeclaringClass()->getName() . '::' . $method->getName() . ':' . $parameter->getName();
} else {
$key = 'function::' . $method->getName() . ':' . $parameter->getName();
}
return $key;
}
示例14: 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);
}
示例15: getAttributeName
/**
* Get the attribute name for ParamFetcher injection
*
* @param \ReflectionFunctionAbstract $controllerReflector
*
* @return null|string
*/
private function getAttributeName(\ReflectionFunctionAbstract $controllerReflector)
{
foreach ($controllerReflector->getParameters() as $parameter) {
$hintedClass = $parameter->getClass();
if ($hintedClass !== null && $hintedClass->implementsInterface(ParamFetcherInterface::class)) {
return $parameter->getName();
}
}
return null;
}