本文整理汇总了PHP中ReflectionParameter::isDefaultValueConstant方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::isDefaultValueConstant方法的具体用法?PHP ReflectionParameter::isDefaultValueConstant怎么用?PHP ReflectionParameter::isDefaultValueConstant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::isDefaultValueConstant方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isParamDefaultValueConstant
/**
* Check whether a parameter's default value is a constant.
*
* This is only supported in PHP >= 5.4.3, and currently unimplemented in
* HHVM.
*
* @param \ReflectionParameter $param
*
* @return boolean
*/
protected static function isParamDefaultValueConstant(\ReflectionParameter $param)
{
// HHVM doesn't currently support `isDefaultValueConstant`, skip for now
// see https://github.com/facebook/hhvm/issues/3812
if (defined('HHVM_VERSION')) {
return false;
}
return version_compare(PHP_VERSION, '5.4.3', '>=') && $param->isDefaultValueConstant();
}
示例2: formatParam
/**
* Format an individual Closure parameter.
*
* @param \ReflectionParameter $param
*
* @return string
*/
protected function formatParam(\ReflectionParameter $param, $color = false)
{
$ret = '$' . $param->name;
if ($color) {
$ret = '<strong>' . $ret . '</strong>';
}
if ($param->isOptional()) {
$ret .= ' = ';
if (version_compare(PHP_VERSION, '5.4.3', '>=') && $param->isDefaultValueConstant()) {
$name = $param->getDefaultValueConstantName();
if ($color) {
$ret .= '<const>' . $name . '</const>';
} else {
$ret .= $name;
}
} elseif ($param->isDefaultValueAvailable()) {
$ret .= $this->manager->presentRef($param->getDefaultValue(), $color);
} else {
if ($color) {
$ret .= '<urgent>?</urgent>';
} else {
$ret .= '?';
}
}
}
return $ret;
}
示例3: formatParam
/**
* Format an individual Closure parameter.
*
* @param \ReflectionParameter $param
*
* @return string
*/
protected function formatParam(\ReflectionParameter $param)
{
$ret = $this->formatParamName($param->name);
if ($param->isOptional()) {
$ret .= ' = ';
if (version_compare(PHP_VERSION, '5.4.3', '>=') && $param->isDefaultValueConstant()) {
$name = $param->getDefaultValueConstantName();
$ret .= '<const>' . $name . '</const>';
} elseif ($param->isDefaultValueAvailable()) {
$ret .= $this->manager->presentRef($param->getDefaultValue());
} else {
$ret .= '<urgent>?</urgent>';
}
}
return $ret;
}
示例4: matchReflector
public function matchReflector(\ReflectionParameter $reflector)
{
$this->setReference($reflector->isPassedByReference());
// Match the reflector's type hint.
if ($reflector->isArray()) {
$this->setTypeHint('array');
} elseif ($reflector->isCallable()) {
$this->setTypeHint('callable');
} elseif ($class = $reflector->getClass()) {
$this->setTypeHint($class->getName());
}
// Match the reflector's default value, if there is one. It will be a
// scalar value, an array of scalar values, or a constant.
if ($reflector->isDefaultValueAvailable()) {
if ($reflector->isDefaultValueConstant()) {
$this->setValue(ConstantNode::create($reflector->getDefaultValueConstantName()));
} else {
$this->setValue(Node::fromValue($reflector->getDefaultValue()));
}
}
return $this;
}
示例5: paramDetails
/**
* Get a declaration of the param for cli command;
* @param \ReflectionParameter $param
* @return string
*/
protected function paramDetails(\ReflectionParameter $param)
{
return ' ' . ($param->isOptional() ? '[' : '') . '--' . $param->getName() . ($param->isOptional() ? '=' . ($param->isDefaultValueConstant() ? $param->getDefaultValueConstantName() : '"' . $param->getDefaultValue() . '"') : '') . ($param->isOptional() ? ']' : '');
}
示例6: getParameterDefinition
/**
* @param \ReflectionParameter $r
*
* @return string
*/
protected function getParameterDefinition(\ReflectionParameter $r)
{
$type = '';
if ($r->isArray()) {
$type = 'array';
} elseif ($r->isCallable()) {
$type = 'callable';
} elseif ($r->getClass()) {
$type = '\\' . $r->getClass()->getName();
}
$name = $r->getName();
$default = '';
if ($r->isDefaultValueAvailable() and $r->isDefaultValueConstant()) {
$default = ' = \\' . $r->getDefaultValueConstantName();
} elseif ($r->isDefaultValueAvailable()) {
$default = ' = ' . var_export($r->getDefaultValue(), true);
}
$definition = trim($type . ' $' . $name . $default);
return $definition;
}
示例7: getPhpForParameter
/**
* @param \ReflectionParameter $parameter
* @return string
*/
protected function getPhpForParameter(\ReflectionParameter $parameter)
{
$php = null;
if ($parameter->getClass() instanceof \ReflectionClass) {
$php .= '\\' . $parameter->getClass()->name . ' ';
} elseif ($parameter->isCallable()) {
$php .= 'callable ';
} elseif ($parameter->isArray()) {
$php .= 'array ';
}
if ($parameter->isPassedByReference()) {
$php .= '&';
}
$php .= '$' . $parameter->name;
if ($parameter->isDefaultValueAvailable()) {
$parameterDefaultValue = $parameter->getDefaultValue();
if ($parameter->isDefaultValueConstant()) {
$defaultValue = $parameter->getDefaultValueConstantName();
} elseif ($parameterDefaultValue === null) {
$defaultValue = 'null';
} elseif (is_bool($parameterDefaultValue)) {
$defaultValue = $parameterDefaultValue === true ? 'true' : 'false';
} elseif (is_string($parameterDefaultValue)) {
$defaultValue = '\'' . $parameterDefaultValue . '\'';
} elseif (is_array($parameterDefaultValue)) {
$defaultValue = 'array()';
} else {
$defaultValue = $parameterDefaultValue;
}
$php .= ' = ' . $defaultValue;
}
return $php;
}
示例8: setDependencyByReflection
/**
* Set dependency value by reflection
*
* @param ParameterDefinition $parameterDefinition
* @param \ReflectionParameter $reflectionParameter
* @throws \InvalidArgumentException
* @throws ReferenceNotImplementsException
*/
public function setDependencyByReflection(ParameterDefinition $parameterDefinition, \ReflectionParameter $reflectionParameter)
{
// If default value available
if ($reflectionParameter->isDefaultValueAvailable()) {
// There is a constant
if ($reflectionParameter->isDefaultValueConstant()) {
$parameterDefinition->setDependency(new ConstantReference($reflectionParameter->getDefaultValueConstantName()));
} else {
// There is some php types
$parameterDefinition->setDependency(CollectionReference::convertValueToReference($reflectionParameter->getDefaultValue()));
}
// There is class dependency
} elseif ($this->checkIfTypeHingIsClass($parameterDefinition)) {
$class = (string) $parameterDefinition->getTypeHint();
$parameterDefinition->setDependency(new ClassReference($class));
}
}
示例9: getParamStr
function getParamStr(ReflectionParameter $param)
{
$name = $param->getName();
//support variable-length argument lists
if ($name == '...') {
return '$_ = null';
}
$str = '$' . $name;
if ($param->isPassedByReference()) {
$str = '&' . $str;
}
if ($param->isArray()) {
$str = 'array ' . $str;
} else {
if ($param->isCallable()) {
$str = 'callable ' . $str;
}
}
//it's impossible to get default value of build-in function's parameter, just for forward compatible
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
if ($param->isDefaultValueConstant()) {
$default = $param->getDefaultValueConstantName();
} else {
$default = $param->getDefaultValue();
}
$str .= ' = ' . $default;
}
return $str;
}