本文整理汇总了PHP中ReflectionParameter::getDeclaringFunction方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::getDeclaringFunction方法的具体用法?PHP ReflectionParameter::getDeclaringFunction怎么用?PHP ReflectionParameter::getDeclaringFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::getDeclaringFunction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTypeOfParameter
private function getTypeOfParameter(\ReflectionParameter $param)
{
if ($class = $param->getClass()) {
return $class->name;
}
$paramName = $param->name;
if (preg_match('/^[\\s\\/*]*@param\\s+(\\S+)\\s+\\$' . preg_quote($paramName, '/') . '\\W/m', $param->getDeclaringFunction()->getDocComment(), $matches)) {
return $this->getFullNameOfType($matches[1], $param->getDeclaringFunction()->getDeclaringClass());
}
return;
}
示例2: __construct
public function __construct(\ReflectionParameter $parameter, array $classConfig, \rg\injektor\Configuration $config, \rg\injektor\DependencyInjectionContainer $dic, $mode)
{
$this->parameter = $parameter;
$this->classConfig = $classConfig;
$this->config = $config;
$this->dic = $dic;
$this->name = $parameter->name;
$this->nameForAnnotationParsing = $parameter->name;
$this->docComment = $this->parameter->getDeclaringFunction()->getDocComment();
$this->additionalArguments = $this->dic->getParamsFromTypeHint($this->parameter);
$this->mode = $mode;
$this->analyze();
}
示例3: __construct
public function __construct(\ReflectionParameter $parameter, $message = null, $code = null, \Exception $previous = null)
{
if (null === $message) {
$message = sprintf('Unable to resolve argument $%s (#%d) of %s.', $parameter->name, $parameter->getPosition(), static::getFunctionName($parameter->getDeclaringFunction()));
}
parent::__construct($message, $code, $previous);
}
示例4: getArgumentMock
/**
* @param \ReflectionParameter $parameter
* @return mixed
*/
private function getArgumentMock(\ReflectionParameter $parameter)
{
if ($parameter->getClass() !== null) {
return $this->testCase->getMockBuilder($parameter->getClass()->getName())->disableOriginalConstructor()->getMock();
}
throw new \Mocktainer\UnmockableMethodArgumentException($parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $parameter->getName());
}
示例5: getParameterAnnotations
public function getParameterAnnotations(\ReflectionParameter $parameter)
{
$class = $parameter->getDeclaringClass() ?: 'Closure';
$method = $parameter->getDeclaringFunction();
if (!$method->isUserDefined()) {
return array();
}
$context = 'parameter ' . ($class === 'Closure' ? $class : $class->getName()) . '::' . $method->getName() . '($' . $parameter->getName() . ')';
if ($class === 'Closure') {
$this->parser->setImports($this->getClosureImports($method));
} else {
$this->parser->setImports($this->getImports($class));
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
}
$lines = file($method->getFileName());
$lines = array_slice($lines, $start = $method->getStartLine() - 1, $method->getEndLine() - $start);
$methodBody = Implode($lines);
$methodBody = str_replace("\n", null, $methodBody);
$signature = preg_split('/\\)\\s*\\{/', $methodBody);
$signature = $signature[0];
$signature = substr($signature, strpos($signature, "function"));
if (preg_match_all('/\\/\\*\\*(.*?)\\*\\/' . '.*?\\$(\\w+)/', $signature, $matches)) {
$docComments = $matches[1];
$names = $matches[2];
for ($i = 0, $len = count($names); $i < $len; ++$i) {
if ($names[$i] === $parameter->name) {
return $this->parser->parse($docComments[$i], $context);
}
}
}
return array();
}
示例6: fromReflection
/**
* Creates a PHP parameter from reflection
*
* @param \ReflectionParameter $ref
* @return PhpParameter
*/
public static function fromReflection(\ReflectionParameter $ref)
{
$parameter = new static();
$parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference());
if ($ref->isDefaultValueAvailable()) {
$parameter->setDefaultValue($ref->getDefaultValue());
}
// find type and description in docblock
$docblock = new Docblock($ref->getDeclaringFunction());
$params = $docblock->getTags('param');
$tag = $params->find($ref->name, function (ParamTag $t, $name) {
return $t->getVariable() == '$' . $name;
});
if ($tag !== null) {
$parameter->setType($tag->getType(), $tag->getDescription());
}
// set type if not found in comment
if ($parameter->getType() === null) {
if ($ref->isArray()) {
$parameter->setType('array');
} elseif ($class = $ref->getClass()) {
$parameter->setType($class->getName());
} elseif (method_exists($ref, 'isCallable') && $ref->isCallable()) {
$parameter->setType('callable');
}
}
return $parameter;
}
示例7: getDeclaringFunction
/**
* Get this parameters declaring (@see Nerd\Source\Funktion) object
*
* @return Nerd\Source\Funktion
*/
public function getDeclaringFunction()
{
$function = parent::getDeclaringFunction();
if ($function instanceof \ReflectionMethod) {
return new Method($this->getDeclaringClass()->getName(), $function->getName());
}
return new Funktion($function->getName());
}
示例8: getParameterAnnotations
function getParameterAnnotations(\ReflectionParameter $parameter)
{
$key = "@[Annot]" . $parameter->getDeclaringClass() . "#" . $parameter->getDeclaringFunction() . "#" . $parameter->name;
if (($annotations = $this->cache->fetch($key)) === false) {
$annotations = $this->reader->getParameterAnnotations($parameter);
$this->cache->save($key, $annotations);
}
return $annotations;
}
示例9: getParameterTypeFromDoc
protected static function getParameterTypeFromDoc(\ReflectionParameter $parameter)
{
$constructor = $parameter->getDeclaringFunction();
$docComment = $constructor->getDocComment();
if (!preg_match('#@inject(?<target>.+)\\$' . $parameter->getName() . '#', $docComment, $match)) {
return null;
}
return str_replace(' ', '', $match['target']);
}
示例10: getDeclaringFunction
public function getDeclaringFunction()
{
$phpReflection = parent::getDeclaringFunction();
if ($phpReflection instanceof ReflectionMethod) {
$zendReflection = new ZendL_Reflection_Method($this->getDeclaringClass()->getName(), $phpReflection->getName());
} else {
$zendReflection = new ZendL_Reflection_Function($phpReflection->getName());
}
unset($phpReflection);
return $zendReflection;
}
示例11: getArgumentType
private static function getArgumentType(ReflectionParameter $parameter)
{
$comment = $parameter->getDeclaringFunction()->getDocComment();
if (!$comment) {
return null;
}
$matches = null;
if (!preg_match("/@param\\s+([^\\s]+)\\s+\\\${$parameter->name}/", $comment, $matches)) {
return null;
}
return $matches[1];
}
示例12: getDeclaringFunction
/**
* Returns the function or method declaring this parameter
* @return ezcReflectionFunction|ezcReflectionMethod
* @since PHP 5.2.3
*/
public function getDeclaringFunction()
{
if ($this->parameter instanceof parent) {
$func = $this->parameter->getDeclaringFunction();
} else {
$func = parent::getDeclaringFunction();
}
if ($func instanceof ReflectionMethod) {
return new ezcReflectionMethod($func->getDeclaringClass(), $func->getName());
} else {
return new ezcReflectionFunction($func->getName());
}
}
示例13: getParameterKey
/**
* {@inheritdoc}
*/
public function getParameterKey(\ReflectionParameter $parameter)
{
$function = $parameter->getDeclaringFunction();
if ($function instanceof \ReflectionMethod) {
foreach ($this->reader->getMethodAnnotations($function) as $annotation) {
if ($annotation instanceof Inject) {
$value = $annotation->getValue($parameter->getName());
if ($value !== null) {
return $value;
}
}
}
}
return null;
}
示例14: analyze
/**
* {@inheritdoc}
* @throws ParameterDefinitionAlreadyExistsException
* @throws ReferenceNotImplementsException
* @throws MethodDefinitionNotFoundException
* @throws ParameterDefinitionNotFoundException
* @throws \InvalidArgumentException
*/
public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionParameter $reflectionParameter)
{
$methodName = $reflectionParameter->getDeclaringFunction()->getName();
$parameterName = $reflectionParameter->getName();
// Define parameter only if method definition is available
if ($classDefinition->hasMethod($methodName)) {
$methodDefinition = $classDefinition->getMethod($methodName);
// Define parameter definition if not exists
$parameterDefinition = $methodDefinition->setupParameter($parameterName);
$this->setReflectionMetadata($parameterDefinition, $reflectionParameter);
$dependency = $parameterDefinition->getDependency();
// If dependency was not set
// UndefinedReference is the default value of dependency which was not use before
if (!$dependency || $dependency instanceof UndefinedReference) {
$this->setDependencyByReflection($parameterDefinition, $reflectionParameter);
}
$this->setOrderArguments($methodDefinition, $reflectionParameter->getDeclaringFunction());
}
}
示例15: denormalizeParameter
/**
* Denormalize a method parameter value.
*
* @param \ReflectionParameter $reflectionParameter
* @param mixed $value Parameter value to denormalize
* @return mixed
*/
protected function denormalizeParameter(\ReflectionParameter $reflectionParameter, $value)
{
if ($reflectionParameter->getClass() === null && !$reflectionParameter->isArray()) {
return $value;
}
if (!$this->serializer instanceof DenormalizerInterface) {
throw new LogicException('Cannot denormalize because injected serializer is not a denormalizer');
}
if ($reflectionParameter->getClass() !== null) {
return $this->serializer->denormalize($value, $reflectionParameter->getClass()->name);
}
if ($reflectionParameter->isArray()) {
$className = $reflectionParameter->getDeclaringClass()->getName();
$methodName = $reflectionParameter->getDeclaringFunction()->getName();
$parameterName = $reflectionParameter->getName();
return $this->serializer->denormalize($value, $className . '::' . $methodName . '(' . $parameterName . ')');
}
return $value;
}