本文整理汇总了PHP中ReflectionParameter::getClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::getClass方法的具体用法?PHP ReflectionParameter::getClass怎么用?PHP ReflectionParameter::getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::getClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: getParamTypeHint
public function getParamTypeHint(\ReflectionFunctionAbstract $function, \ReflectionParameter $param, array $arguments = [])
{
$lowParam = strtolower($param->name);
if ($function instanceof \ReflectionMethod) {
$lowClass = strtolower($function->class);
$lowMethod = strtolower($function->name);
$paramCacheKey = self::CACHE_KEY_CLASSES . "{$lowClass}.{$lowMethod}.param-{$lowParam}";
} else {
$lowFunc = strtolower($function->name);
$paramCacheKey = $lowFunc !== '{closure}' ? self::CACHE_KEY_FUNCS . ".{$lowFunc}.param-{$lowParam}" : null;
}
$typeHint = $paramCacheKey === null ? false : $this->cache->fetch($paramCacheKey);
if (false !== $typeHint) {
return $typeHint;
}
if ($reflectionClass = $param->getClass()) {
$typeHint = $reflectionClass->getName();
$classCacheKey = self::CACHE_KEY_CLASSES . strtolower($typeHint);
$this->cache->store($classCacheKey, $this->getClass($param->getClass()->getName()));
} elseif ($function instanceof \ReflectionMethod && ($docBlockParams = $this->getDocBlock($function)->getTagsByName('param')) && !empty($docBlockParams)) {
$typeHint = $this->getParamDocBlockHint($docBlockParams, $param, $arguments);
// store the ExtendedReflectionClass in the cache
if ($typeHint !== false) {
$classCacheKey = self::CACHE_KEY_CLASSES . strtolower($typeHint);
$this->cache->store($classCacheKey, $this->getClass($typeHint));
}
} else {
$typeHint = null;
}
$this->cache->store($paramCacheKey, $typeHint);
return $typeHint;
}
示例3: from
/**
* @return self
*/
public static function from(\ReflectionParameter $from)
{
$param = new static($from->getName());
$param->reference = $from->isPassedByReference();
if (PHP_VERSION_ID >= 70000) {
$param->typeHint = $from->hasType() ? (string) $from->getType() : NULL;
} elseif ($from->isArray()) {
$param->typeHint = 'array';
} elseif (PHP_VERSION_ID >= 50400 && $from->isCallable()) {
$param->typeHint = 'callable';
} else {
try {
$param->typeHint = $from->getClass() ? $from->getClass()->getName() : NULL;
} catch (\ReflectionException $e) {
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
$param->typeHint = $m[1];
} else {
throw $e;
}
}
}
$param->optional = PHP_VERSION_ID < 50407 ? $from->isOptional() || $param->typeHint && $from->allowsNull() : $from->isDefaultValueAvailable();
$param->defaultValue = PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable() ? $from->getDefaultValue() : NULL;
return $param;
}
示例4: from
/**
* @return self
*/
public static function from(\ReflectionParameter $from)
{
$param = new static();
$param->name = $from->getName();
$param->reference = $from->isPassedByReference();
if ($from->isArray()) {
$param->typeHint = 'array';
} elseif (PHP_VERSION_ID >= 50400 && $from->isCallable()) {
$param->typeHint = 'callable';
} else {
try {
$param->typeHint = $from->getClass() ? '\\' . $from->getClass()->getName() : NULL;
} catch (\ReflectionException $e) {
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
$param->typeHint = '\\' . $m[1];
} else {
throw $e;
}
}
}
$param->optional = PHP_VERSION_ID < 50407 ? $from->isOptional() || $param->typeHint && $from->allowsNull() : $from->isDefaultValueAvailable();
$param->defaultValue = PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable() ? $from->getDefaultValue() : NULL;
$namespace = $from->getDeclaringClass() ? $from->getDeclaringClass()->getNamespaceName() : NULL;
$namespace = $namespace ? "\\{$namespace}\\" : '\\';
if (Nette\Utils\Strings::startsWith($param->typeHint, $namespace)) {
$param->typeHint = substr($param->typeHint, strlen($namespace));
}
return $param;
}
示例5: getDeclaration
public function getDeclaration()
{
if ($this->reflector->isArray()) {
$code = 'array ';
} else {
$class = $this->reflector->getClass();
if ($class !== null) {
$code = $class->name . ' ';
} else {
$code = '';
}
}
$code .= '$' . $this->reflector->name;
if ($this->reflector->isOptional()) {
$default = $this->reflector->getDefaultValue();
if (is_null($default)) {
$default = 'null';
} elseif (is_bool($default)) {
$default = $default ? 'true' : 'false';
} elseif (is_string($default)) {
$default = "'" . $default . "'";
} elseif (is_numeric($default)) {
$default = strval($default);
} elseif (is_array($default)) {
$default = 'array()';
} else {
echo 'Warning: unknown default type for ' . $this->getMethod()->getFullName() . PHP_EOL;
var_dump($default);
$default = 'null';
}
$code .= ' = ' . $default;
}
return $code;
}
示例6: getArgumentMock
/**
* @param string $className
* @param string $argumentName
* @param \ReflectionParameter $parameter
* @return mixed
*/
private function getArgumentMock(string $className, string $argumentName, \ReflectionParameter $parameter)
{
if ($parameter->getClass() !== null) {
return $this->testCase->getMockBuilder($parameter->getClass()->name)->disableOriginalConstructor()->getMock();
}
throw new \Mocktainer\UnmockableConstructorArgumentException($className, $argumentName);
}
示例7: isGoutte1
private function isGoutte1()
{
$refl = new \ReflectionParameter(array('Goutte\\Client', 'setClient'), 0);
if ($refl->getClass() && 'Guzzle\\Http\\ClientInterface' === $refl->getClass()->getName()) {
return true;
}
return false;
}
示例8: getClass
/**
* @inheritdoc
*/
public function getClass()
{
$class = $this->parameter->getClass();
if ($class) {
return $class->getName();
}
return null;
}
示例9: getParameterInfo
private function getParameterInfo(\ReflectionParameter $parameter)
{
$paramName = '$' . $parameter->getName() . '=null';
if ($parameter->isPassedByReference()) {
$paramName = '&' . $paramName;
}
$paramType = $parameter->getClass() !== null ? $parameter->getClass()->getName() : '';
return "{$paramType} {$paramName}";
}
示例10: getTypeHint
/**
* return type hint, if any (none or object type - inteface, class, ...)
*
* @return string
*/
public function getTypeHint()
{
if ($this->typeHint === null) {
if (($class = $this->reflectionParameter->getClass()) !== null) {
$this->typeHint = $class->getName();
}
}
return $this->typeHint;
}
示例11: getType
private function getType(\ReflectionParameter $param)
{
if ($param->getClass() && $param->getClass()->getName()) {
return $param->getClass()->getName();
}
if ($param->isArray()) {
return 'Array';
}
}
示例12: validate
public function validate(\ReflectionParameter $parameter, $argument)
{
if ($parameter->isArray()) {
$this->validateArrayArgument($argument);
} elseif ($parameter->getClass()) {
$this->validateObjectArgument($parameter->getClass()->getName(), $argument, $parameter->allowsNull());
}
// other arguments don't need to be or can't be validated
}
示例13: getParameterDependency
/**
* @param Horde_Injector $injector
* @param ReflectionParameter $method
*
* @return mixed
* @throws Horde_Injector_Exception
*/
public function getParameterDependency(Horde_Injector $injector, ReflectionParameter $parameter)
{
if ($parameter->getClass()) {
return $injector->getInstance($parameter->getClass()->getName());
} elseif ($parameter->isOptional()) {
return $parameter->getDefaultValue();
}
throw new Horde_Injector_Exception("Untyped parameter \$" . $parameter->getName() . "can't be fulfilled");
}
示例14: getTypeByReflectionParameter
/**
* @param \ReflectionParameter $reflectionParameter
*
* @return null|string
*/
protected function getTypeByReflectionParameter(\ReflectionParameter $reflectionParameter)
{
if ($reflectionParameter->getClass()) {
return $reflectionParameter->getClass()->getName();
}
if ($reflectionParameter->isArray()) {
return 'array';
}
return null;
}
示例15: getArgument
private function getArgument(\ReflectionParameter $argument)
{
if ($argument->isOptional()) {
return $argument->getDefaultValue();
}
if ($argument->allowsNull()) {
return null;
}
if ($argument->getClass()) {
return $this->getMockBuilder($argument->getClass()->getName())->disableOriginalConstructor()->getMock();
}
return null;
}