本文整理汇总了PHP中ReflectionParameter::getDeclaringClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::getDeclaringClass方法的具体用法?PHP ReflectionParameter::getDeclaringClass怎么用?PHP ReflectionParameter::getDeclaringClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::getDeclaringClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: getType
public function getType() : Type
{
if ($this->type === null) {
$phpDocType = $this->phpDocType;
if ($phpDocType !== null && $this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) {
$phpDocType = $phpDocType->makeNullable();
}
$this->type = TypehintHelper::decideTypeFromReflection($this->reflection->getType(), $phpDocType, $this->reflection->getDeclaringClass() !== null ? $this->reflection->getDeclaringClass()->getName() : null, $this->reflection->isVariadic());
}
return $this->type;
}
示例3: 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();
}
示例4: getDeclaringClass
public function getDeclaringClass()
{
$phpReflection = parent::getDeclaringClass();
$zendReflection = new ZendL_Reflection_Class($phpReflection->getName());
unset($phpReflection);
return $zendReflection;
}
示例5: 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());
}
示例6: getDeclaringClass
/**
* Gets the declaring class.
*
* @return \Wingu\OctopusCore\Reflection\ReflectionClass
*/
public function getDeclaringClass()
{
$class = parent::getDeclaringClass();
if ($class !== null) {
$class = new ReflectionClass($class->getName());
}
return $class;
}
示例7: getDependency
protected function getDependency(\ReflectionParameter $param, $container)
{
$dependency = $param->getClass();
if (is_null($dependency)) {
$message = "Unable to resolve [{$param->name}] in {$param->getDeclaringClass()->getName()}";
$this->raiseException($message);
}
return $container->get($dependency->name);
}
示例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: getDeclaringClass
/**
* Get declaring class reflection object
*
* @param string $reflectionClass Reflection class to use
* @return \Zend\Reflection\ReflectionClass
*/
public function getDeclaringClass($reflectionClass = 'Zend\\Reflection\\ReflectionClass')
{
$phpReflection = parent::getDeclaringClass();
$zendReflection = new $reflectionClass($phpReflection->getName());
if (!$zendReflection instanceof ReflectionClass) {
throw new Exception\InvalidArgumentException('Invalid reflection class provided; must extend Zend_Reflection_Class');
}
unset($phpReflection);
return $zendReflection;
}
示例10: getDeclaringClass
/**
* Get declaring class reflection object
*
* @param string $reflectionClass Reflection class to use
* @return Zend_Reflection_Class
*/
public function getDeclaringClass($reflectionClass = 'Zend_Reflection_Class')
{
$phpReflection = parent::getDeclaringClass();
$zendReflection = new $reflectionClass($phpReflection->getName());
if (!$zendReflection instanceof Zend_Reflection_Class) {
#require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
}
unset($phpReflection);
return $zendReflection;
}
示例11: getDeclaringClass
/**
* Returns in which class this parameter is defined (not the type hint of the parameter)
* @return ezcReflectionClass
*/
function getDeclaringClass()
{
if ($this->parameter != null) {
$class = $this->parameter->getDeclaringClass();
} else {
$class = parent::getDeclaringClass();
}
if (!empty($class)) {
return new ezcReflectionClass($class->getName());
} else {
return null;
}
}
示例12: resolveArgument
private function resolveArgument(\ReflectionParameter $parameter)
{
$name = StringUtil::underscore($parameter->name);
if ('container' === $name) {
return $this->container;
}
if (isset($this->container[$name])) {
return $this->container[$name];
}
if ($parameter->isOptional()) {
return $parameter->getDefaultValue();
}
throw new \RuntimeException(sprintf('Unable to resolve parameter "%s" of class "%s" no service/parameter found with name "%s". ' . 'Consider adding a default value.', $name, $parameter->getDeclaringClass()->name, $name));
}
示例13: buildField
private static function buildField(\ReflectionParameter $parameter, $data)
{
// If parameter turns out to be an Object then recurse
if (!empty($parameter->getClass())) {
return self::build($parameter->getClass()->getName(), $data);
}
// If parameter is type of array, then check whether it is an array of Object
if ($parameter->isArray()) {
$possibleObjectClassName = $parameter->getDeclaringClass()->getName() . '_' . $parameter->getName() . '_item';
if (class_exists($possibleObjectClassName)) {
return array_map(function ($values) use($possibleObjectClassName) {
return self::build($possibleObjectClassName, $values);
}, $data);
}
}
return $data;
}
示例14: 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;
}
示例15: getParameterType
/**
* @return string|NULL
*/
public static function getParameterType(\ReflectionParameter $param)
{
if (PHP_VERSION_ID >= 70000) {
if ($param->hasType()) {
$type = PHP_VERSION_ID >= 70100 ? $param->getType()->getName() : (string) $param->getType();
return strtolower($type) === 'self' ? $param->getDeclaringClass()->getName() : $type;
}
} elseif ($param->isArray() || $param->isCallable()) {
return $param->isArray() ? 'array' : 'callable';
} else {
try {
return ($ref = $param->getClass()) ? $ref->getName() : NULL;
} catch (\ReflectionException $e) {
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
return $m[1];
}
throw $e;
}
}
}