本文整理汇总了PHP中ReflectionParameter::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::getName方法的具体用法?PHP ReflectionParameter::getName怎么用?PHP ReflectionParameter::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getName
/**
* @return string|null
*/
public function getName()
{
if (empty($this->parameter)) {
return null;
}
return $this->parameter->getName();
}
示例2: getReflectionParameterName
/**
* Helper method to get the type of a reflection paramter
* @param \ReflectionParameter $parameter
* @return NULL|\ReflectionType|string
*/
protected function getReflectionParameterName(\ReflectionParameter $parameter)
{
// parameter is a class
if ($class = $parameter->getClass()) {
return $class->getName() . ' \\$' . $parameter->getName();
}
return $parameter->getName();
}
示例3: 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;
}
示例4: injectByClass
/**
* @param \ReflectionParameter $class
* @return mixed|object
* @throws \Exception
*/
public function injectByClass($class)
{
$reflection = $class->getClass();
if (is_null($reflection)) {
return HttpParameter::getInstance()->getOrError($class->getName());
} else {
if ($reflection->getName() === Option::class) {
return HttpParameter::getInstance()->get($class->getName());
}
}
return $this->create($reflection);
}
示例5: exportCode
public function exportCode()
{
$default_value = null;
if ($this->_parameter->isDefaultValueAvailable()) {
$default_value = $this->_parameter->getDefaultValue();
if (is_scalar($default_value) && !is_numeric($default_value)) {
$default_value = "'{$default_value}'";
}
} elseif ($this->_parameter->isOptional()) {
$default_value = 'NULL';
}
return sprintf('%s%s$%s%s', $this->_parameter->getClass() ? "{$this->_parameter->getClass()->getName()} " : '', $this->_parameter->isPassedByReference() ? '&' : '', $this->_parameter->getName(), $default_value ? " = {$default_value}" : '');
}
示例6: 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;
}
示例7: 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();
}
示例8: 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);
}
}
示例9: 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;
}
示例10: __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);
}
}
示例11: __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;
}
示例12: 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;
}
示例13: 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());
}
示例14: getName
/**
* Returns this parameters's name
* @return string
*/
public function getName()
{
if ($this->parameter != null) {
return $this->parameter->getName();
} else {
return parent::getName();
}
}
示例15: getParameterValue
/**
* {@inheritdoc}
*/
public function getParameterValue(\ReflectionParameter $parameter)
{
$name = $parameter->getName();
if (isset($this->values[$name])) {
return $this->values[$name];
}
return $this->fallback->getParameterValue($parameter);
}