本文整理汇总了PHP中ReflectionParameter类的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter类的具体用法?PHP ReflectionParameter怎么用?PHP ReflectionParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReflectionParameter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(ReflectionParameter $param)
{
if (method_exists('ReflectionParameter', 'getType')) {
if ($type = $param->getType()) {
$this->type_hint = (string) $type;
}
} else {
if ($param->isArray()) {
$this->type_hint = 'array';
} else {
try {
if ($this->type_hint = $param->getClass()) {
$this->type_hint = $this->type_hint->name;
}
} catch (ReflectionException $e) {
preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches);
$this->type_hint = isset($matches[1]) ? $matches[1] : '';
}
}
}
$this->reference = $param->isPassedByReference();
$this->position = $param->getPosition();
$this->name = $param->getName();
if ($param->isDefaultValueAvailable()) {
$this->default = var_export($param->getDefaultValue(), true);
}
}
开发者ID:jnvsor,项目名称:kint,代码行数:27,代码来源:Parameter.php
示例2: getParamTypeHint
public function getParamTypeHint(\ReflectionFunctionAbstract $function, \ReflectionParameter $param)
{
$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, $reflectionClass);
} else {
$typeHint = null;
}
$this->cache->store($paramCacheKey, $typeHint);
return $typeHint;
}
开发者ID:barthelemy-ehui,项目名称:auryn,代码行数:25,代码来源:CachingReflector.php
示例3: getParameterValue
/**
* {@inheritdoc}
*/
public function getParameterValue(\ReflectionParameter $parameter)
{
if ($parameter->isDefaultValueAvailable()) {
return $parameter->getDefaultValue();
}
throw UnresolvedValueException::unresolvedParameter($parameter);
}
开发者ID:brick,项目名称:di,代码行数:10,代码来源:DefaultValueResolver.php
示例4: getParamDocBlockHint
/**
* @param array $docBlockParams
* @param \ReflectionParameter $param
* @param array $arguments
*
* @return bool|string
*/
public function getParamDocBlockHint(array $docBlockParams, \ReflectionParameter $param, array $arguments = [])
{
$typeHint = false;
/** @var DocBlock\Tag\ParamTag $docBlockParam */
foreach ($docBlockParams as $docBlockParam) {
if (!$docBlockParam instanceof DocBlock\Tag\ParamTag) {
continue;
}
$type = $docBlockParam->getType();
$docBlockParamName = $docBlockParam->getVariableName();
if ($param->getName() === ltrim($docBlockParamName, '$') && !empty($type)) {
$definitions = explode('|', $type);
foreach ($arguments as $key => $argument) {
foreach ($definitions as $definition) {
if (is_object($argument) && in_array(ltrim($definition, '\\'), $this->getImplemented(get_class($argument))) && (is_numeric($key) || ltrim($docBlockParamName, '$') === $key)) {
$typeHint = $definition;
// no need to loop again, since we found a match already!
continue 3;
}
}
}
if ($typeHint === false) {
// use first definition, there is no way to know which instance of the hinted doc block definitions is actually required
// because there were either no arguments given or no argument match was found
list($firstDefinition, ) = $definitions;
if (!in_array(strtolower($firstDefinition), ['int', 'float', 'bool', 'string', 'array'])) {
$typeHint = $firstDefinition;
}
}
}
}
return $typeHint;
}
开发者ID:cmpayments,项目名称:atreyu,代码行数:40,代码来源:BaseReflector.php
示例5: loadArray
private static function loadArray($object, &$result, $prefix = "")
{
$reflect = new ReflectionClass($object);
$typeName = $reflect->getName();
$properties = ObjectParser::getProperties($object);
if (is_array($properties)) {
foreach ($properties as $key => $prop) {
$propertyName = $prop->getName();
$propNameCamelCase = ucfirst($propertyName);
$getMethodName = "get{$propNameCamelCase}";
$setMethodName = "set{$propNameCamelCase}";
$setIdMethodName = "{$setMethodName}_id";
$setMethodParameter = new ReflectionParameter(array($typeName, $setMethodName), 0);
if ($reflect->getMethod($setMethodName) && $setMethodParameter->getClass() && method_exists($object, $setIdMethodName)) {
continue;
}
$value = $object->{$getMethodName}();
$name = $prefix . $propertyName;
if (is_object($value)) {
ObjectParser::loadArray($value, $result, "{$name}.");
} else {
$result[$name] = $value;
}
}
return true;
}
return false;
}
开发者ID:rubensgadelha,项目名称:core-api,代码行数:28,代码来源:ObjectParser.php
示例6: test
function test($param)
{
$r = new ReflectionParameter('params', $param);
var_dump($r->getDefaultValue());
var_dump($r->getDefaultValueText());
var_dump($r->getDefaultValueConstantName());
}
开发者ID:RavuAlHemio,项目名称:hhvm,代码行数:7,代码来源:get_default_constant_name.php
示例7: __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);
}
开发者ID:rybakit,项目名称:arguments-resolver,代码行数:7,代码来源:UnresolvableArgumentException.php
示例8: canInject
/**
* @param ReflectionParameter $parameter
* @param CollectionInterface $properties
*
* @return bool
*/
private function canInject(\ReflectionParameter $parameter, CollectionInterface $properties) : bool
{
if (!$parameter->allowsNull() && !$properties->hasKey($parameter->name)) {
return false;
} else {
if ($parameter->allowsNull() && !$properties->hasKey($parameter->name)) {
return false;
}
}
$property = $properties[$parameter->name];
if ($parameter->hasType()) {
$type = $parameter->getType();
if ($type->isBuiltin()) {
return (string) $type === gettype($property);
} else {
if (!is_object($property)) {
return false;
}
}
$refl = new \ReflectionObject($property);
$wishedClass = (string) $type;
return get_class($property) === $wishedClass || $refl->isSubClassOf($wishedClass);
}
return true;
}
开发者ID:Innmind,项目名称:Reflection,代码行数:31,代码来源:ReflectionInstanciator.php
示例9: __construct
public function __construct(\ReflectionParameter $parameter)
{
if (!$parameter->isCallable()) {
throw new \InvalidArgumentException('Provided parameter should have a callable type hint');
}
parent::__construct($parameter);
}
开发者ID:kamioftea,项目名称:php-util,代码行数:7,代码来源:CallableArgument.php
示例10: getArgConfig
/**
* @param Zend_Config $testConfig
* @param ReflectionParameter $arg
* @throws Exception
* @throws KalturaTestException
* @return Ambigous
*/
protected function getArgConfig(Zend_Config $testConfig, ReflectionParameter $arg)
{
$argName = $arg->getName();
$argConfig = $testConfig->get($argName);
KalturaLog::debug("Tests data [{$argName}] config [" . print_r($argConfig, true) . "]");
if (!$argConfig) {
if (!$arg->allowsNull()) {
throw new Exception("Argument [{$argName}] can't be null for test [" . $this->getName() . "]");
}
return null;
}
if (is_string($argConfig)) {
return $argConfig;
}
switch ($argConfig->objectType) {
case 'dependency':
throw new KalturaTestException("Argument [{$argName}] taken from dependency");
case 'array':
return $this->populateArray($argConfig);
case 'native':
return $argConfig->value;
case 'file':
return $argConfig->path;
default:
return $this->populateObject($argConfig);
}
}
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:34,代码来源:KalturaTestCaseApiBase.php
示例11: 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);
}
开发者ID:ondrejmirtes,项目名称:mocktainer,代码行数:13,代码来源:Mocktainer.php
示例12: 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;
}
开发者ID:cmpayments,项目名称:atreyu,代码行数:32,代码来源:CachingReflector.php
示例13: getArgument
private static function getArgument(ReflectionParameter $parameter)
{
if (isset($_REQUEST[$parameter->name])) {
if ($parameter->isArray()) {
return $_REQUEST[$parameter->name];
}
$type = self::getArgumentType($parameter);
if (!class_exists($type)) {
throw new Exception("Type not found for attribute [{$parameter->name}]");
}
$object = new $type();
if (is_array($_REQUEST[$parameter->name])) {
foreach ($_REQUEST[$parameter->name] as $attribute => $value) {
$object->{$attribute} = $value;
}
}
return $object;
}
if ($parameter->isDefaultValueAvailable()) {
return $parameter->getDefaultValue();
}
if ($parameter->allowsNull()) {
return null;
}
if ($parameter->isArray()) {
return array();
}
$type = self::getArgumentType($parameter);
if (!class_exists($type)) {
throw new Exception("Type not found for attribute [{$parameter->name}]");
}
return new $type();
}
开发者ID:reginaldoandrade,项目名称:ezerphp,代码行数:33,代码来源:EzerAjaxFrontController.php
示例14: __construct
public function __construct(\ReflectionParameter $parameter)
{
$this->name = $parameter->getName();
$this->position = $parameter->getPosition();
$this->has_default = $parameter->isDefaultValueAvailable();
$this->default_value = $this->getHasDefault() ? $parameter->getDefaultValue() : null;
}
开发者ID:kamioftea,项目名称:php-util,代码行数:7,代码来源:Argument.php
示例15: 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();
}
开发者ID:spotframework,项目名称:spot,代码行数:32,代码来源:ReaderImpl.php
示例16: resolveNonClass
/**
* @param ReflectionParameter $parameter
* @return mixed
* @throws Exception
*/
public function resolveNonClass($parameter)
{
// 有默认值则返回默认值
if ($parameter->isDefaultValueAvailable()) {
return $parameter->getDefaultValue();
}
throw new Exception('I have no idea what to do here.');
}
开发者ID:TeamOfMalaysia,项目名称:H,代码行数:13,代码来源:Container.php
示例17: getDefaultValue
private function getDefaultValue(\ReflectionParameter $parameter)
{
$defaultValue = null;
if ($parameter->isDefaultValueAvailable()) {
$defaultValue = $parameter->getDefaultValue();
}
return $defaultValue;
}
开发者ID:steve-rodrigue,项目名称:entity-apis,代码行数:8,代码来源:ConcreteEntityAdapter.php
示例18: 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;
}
开发者ID:obrianhc,项目名称:memestime,代码行数:8,代码来源:GoutteFactory.php
示例19: getParameterValue
/**
* {@inheritdoc}
*/
public function getParameterValue(\ReflectionParameter $parameter)
{
$name = $parameter->getName();
if (isset($this->values[$name])) {
return $this->values[$name];
}
return $this->fallback->getParameterValue($parameter);
}
开发者ID:brick,项目名称:di,代码行数:11,代码来源:ArrayValueResolver.php
示例20: isScopeFetcherType
/**
* Returns true if the given controller parameter is type-hinted as an instance of ScopeFetcher.
*
* @param \ReflectionParameter $controllerParam A parameter of the controller action.
*
* @return bool
*/
private function isScopeFetcherType(\ReflectionParameter $controllerParam)
{
$class = $controllerParam->getClass();
if (!$class) {
return false;
}
return $class->implementsInterface(self::SCOPE_FETCHER_INTERFACE);
}
开发者ID:glavweb,项目名称:GlavwebRestBundle,代码行数:15,代码来源:ScopeFetcherListener.php
注:本文中的ReflectionParameter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论