本文整理汇总了PHP中ReflectionFunctionAbstract::getDeclaringClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunctionAbstract::getDeclaringClass方法的具体用法?PHP ReflectionFunctionAbstract::getDeclaringClass怎么用?PHP ReflectionFunctionAbstract::getDeclaringClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunctionAbstract
的用法示例。
在下文中一共展示了ReflectionFunctionAbstract::getDeclaringClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isResourceType
/**
* Check if the target action is declared the given type or sub type (checking for
* interfaces is also supported).
*
* @param string $typeName
* @return boolean
*/
public function isResourceType($typeName)
{
if ($typeName instanceof \ReflectionClass) {
$typeName = $typeName->name;
}
if (!$this->target instanceof \ReflectionMethod) {
return false;
}
if (class_exists($typeName)) {
$lookup = strtolower($typeName);
$ref = $this->target->getDeclaringClass();
if (strtolower($ref->name) == $lookup) {
return true;
}
$next = $ref;
while ($next = $next->getParentClass()) {
if (strtolower($next->name) == $lookup) {
return true;
}
}
return false;
}
if (interface_exists($typeName, false)) {
return $this->target->getDeclaringClass()->implementsInterface($typeName);
}
return false;
}
示例2: __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);
}
示例3: 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 '';
}
示例4: getDeclaringClass
/**
* {@inheritDoc}
*/
public function getDeclaringClass()
{
if ($this->declaringFunction instanceof \ReflectionMethod) {
return $this->declaringFunction->getDeclaringClass();
}
return null;
}
示例5: fetchFunctionIdentifier
private function fetchFunctionIdentifier(\ReflectionFunctionAbstract $function)
{
$functionIdentifier = $function->getName();
if ($function instanceof \ReflectionMethod) {
$functionIdentifier = sprintf('%s::%s', $function->getDeclaringClass()->getName(), $function->getName());
}
return $functionIdentifier;
}
示例6: 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;
}
示例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: 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;
}
示例9: getFunctionName
private function getFunctionName(\ReflectionFunctionAbstract $reflectionFunction)
{
if ($reflectionFunction->isClosure()) {
return sprintf('closure defined in %s at line %d', $reflectionFunction->getFileName(), $reflectionFunction->getStartLine());
} elseif ($reflectionFunction instanceof \ReflectionMethod) {
return sprintf('%s::%s', $reflectionFunction->getDeclaringClass()->getName(), $reflectionFunction->getName());
}
return $reflectionFunction->getName();
}
示例10: autowireArguments
/**
* Generates list of arguments using autowiring.
* @return array
*/
public static function autowireArguments(\ReflectionFunctionAbstract $method, array $arguments, $container)
{
$optCount = 0;
$num = -1;
$res = array();
$methodName = ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName() . '()';
foreach ($method->getParameters() as $num => $parameter) {
if (array_key_exists($num, $arguments)) {
$res[$num] = $arguments[$num];
unset($arguments[$num]);
$optCount = 0;
} elseif (array_key_exists($parameter->getName(), $arguments)) {
$res[$num] = $arguments[$parameter->getName()];
unset($arguments[$parameter->getName()]);
$optCount = 0;
} elseif (($class = PhpReflection::getParameterType($parameter)) && !PhpReflection::isBuiltinType($class)) {
$res[$num] = $container->getByType($class, FALSE);
if ($res[$num] === NULL) {
if ($parameter->allowsNull()) {
$optCount++;
} elseif (class_exists($class) || interface_exists($class)) {
$rc = new \ReflectionClass($class);
if ($class !== ($hint = $rc->getName())) {
throw new ServiceCreationException("Service of type {$class} needed by {$methodName} not found, did you mean {$hint}?");
}
throw new ServiceCreationException("Service of type {$class} needed by {$methodName} not found. Did you register it in configuration file?");
} else {
throw new ServiceCreationException("Class {$class} needed by {$methodName} not found. Check type hint and 'use' statements.");
}
} else {
if ($container instanceof ContainerBuilder) {
$res[$num] = '@' . $res[$num];
}
$optCount = 0;
}
} elseif ($parameter->isOptional() || $parameter->isDefaultValueAvailable()) {
// !optional + defaultAvailable = func($a = NULL, $b) since 5.3.17 & 5.4.7
// optional + !defaultAvailable = i.e. Exception::__construct, mysqli::mysqli, ...
$res[$num] = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : NULL;
$optCount++;
} else {
throw new ServiceCreationException("Parameter \${$parameter->getName()} in {$methodName} has no class type hint or default value, so its value must be specified.");
}
}
// extra parameters
while (array_key_exists(++$num, $arguments)) {
$res[$num] = $arguments[$num];
unset($arguments[$num]);
$optCount = 0;
}
if ($arguments) {
throw new ServiceCreationException("Unable to pass specified arguments to {$methodName}.");
}
return $optCount ? array_slice($res, 0, -$optCount) : $res;
}
示例11: fromReflection
/**
* Creates a function location instance from the supplied reflection.
*
* @param \ReflectionFunctionAbstract $reflection
*
* @return self
*/
public static function fromReflection(\ReflectionFunctionAbstract $reflection)
{
if ($reflection instanceof \ReflectionFunction) {
$namespace = $reflection->getNamespaceName();
} elseif ($reflection instanceof \ReflectionMethod) {
$namespace = $reflection->getDeclaringClass()->getNamespaceName();
} else {
$namespace = null;
}
return new self($reflection->getFileName(), $namespace, $reflection->getStartLine(), $reflection->getEndLine());
}
示例12: getReturnType
/**
* @return string|NULL
*/
public static function getReturnType(\ReflectionFunctionAbstract $func)
{
if (PHP_VERSION_ID >= 70000 && $func->hasReturnType()) {
$type = PHP_VERSION_ID >= 70100 ? $func->getReturnType()->getName() : (string) $func->getReturnType();
return strtolower($type) === 'self' ? $func->getDeclaringClass()->getName() : $type;
}
$type = preg_replace('#[|\\s].*#', '', (string) self::parseAnnotation($func, 'return'));
if ($type) {
return $func instanceof \ReflectionMethod ? self::expandClassName($type, $func->getDeclaringClass()) : ltrim($type, '\\');
}
}
示例13: getFunctionName
/**
* @param \ReflectionFunctionAbstract $reflection
*
* @return string
*/
protected static function getFunctionName(\ReflectionFunctionAbstract $reflection)
{
if (!$reflection instanceof \ReflectionMethod) {
return $reflection->name;
}
$class = $reflection->getDeclaringClass()->name;
// see https://github.com/facebook/hhvm/issues/3874
if (0 === strpos($class, 'Closure')) {
$class = 'Closure';
}
return $class . '::' . $reflection->name;
}
示例14: fromReflection
/**
* Creates a function scope instance from the supplied reflection and callable.
*
* @param \ReflectionFunctionAbstract $reflection
* @param callable $callable
*
* @return self
*/
public static function fromReflection(\ReflectionFunctionAbstract $reflection, callable $callable)
{
if (is_array($callable)) {
/** @var $reflection \ReflectionMethod */
$thisObject = is_object($callable[0]) ? $callable[0] : null;
$scopeType = $reflection->getDeclaringClass()->getName();
} elseif (is_object($callable) && !$callable instanceof \Closure) {
/** @var $reflection \ReflectionMethod */
$thisObject = $callable;
$scopeType = $reflection->getDeclaringClass()->getName();
} elseif ($reflection->isClosure()) {
$thisObject = $reflection->getClosureThis();
$scopeClass = $reflection->getClosureScopeClass();
$scopeType = $scopeClass === null ? null : $scopeClass->getName();
} else {
$thisObject = null;
$scopeType = null;
}
$variableTable = $reflection->getStaticVariables();
return new self($thisObject, $scopeType, $variableTable);
}
示例15: processFunctionOrMethod
/**
* @param \ReflectionFunctionAbstract $functionOrMethod
*/
private function processFunctionOrMethod(\ReflectionFunctionAbstract $functionOrMethod)
{
if ($functionOrMethod->isInternal()) {
return;
}
$name = $functionOrMethod->getName();
if ($functionOrMethod instanceof \ReflectionMethod) {
$name = $functionOrMethod->getDeclaringClass()->getName() . '::' . $name;
}
if (!isset($this->lookupTable[$functionOrMethod->getFileName()])) {
$this->lookupTable[$functionOrMethod->getFileName()] = [];
}
foreach (range($functionOrMethod->getStartLine(), $functionOrMethod->getEndLine()) as $line) {
$this->lookupTable[$functionOrMethod->getFileName()][$line] = $name;
}
}