本文整理汇总了PHP中ReflectionParameter::isCallable方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::isCallable方法的具体用法?PHP ReflectionParameter::isCallable怎么用?PHP ReflectionParameter::isCallable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::isCallable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(\ReflectionParameter $parameter)
{
if (!$parameter->isCallable()) {
throw new \InvalidArgumentException('Provided parameter should have a callable type hint');
}
parent::__construct($parameter);
}
示例2: 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;
}
示例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: _getHintName
/**
* @param \ReflectionParameter $param
*
* @return string|null
*/
protected function _getHintName(\ReflectionParameter $param)
{
if (version_compare(phpversion(), '5.4', '>=') && $param->isCallable()) {
return 'callable';
}
if ($param->isArray()) {
return 'array';
}
if ($class = $param->getClass()) {
return $class->getName();
}
}
示例5: buildParameter
private function buildParameter(\ReflectionParameter $parameter)
{
switch (true) {
case $parameter->getClass() !== null:
return new ClassArgument($parameter);
case $parameter->isArray():
return new ArrayArgument($parameter);
case $parameter->isCallable():
return new CallableArgument($parameter);
default:
return new MixedArgument($parameter);
}
}
示例6: matchType
/**
* Checks if the value matches the parameter type.
*
* @param \ReflectionParameter $parameter
* @param mixed $value
*
* @return bool
*/
protected static function matchType(\ReflectionParameter $parameter, $value)
{
if ($class = $parameter->getClass()) {
return is_object($value) && $class->isInstance($value);
}
if ($parameter->isArray()) {
return is_array($value);
}
if ($parameter->isCallable()) {
return is_callable($value);
}
return true;
}
示例7: getParameterType
/**
* @return string|NULL
*/
public static function getParameterType(\ReflectionParameter $param)
{
if ($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;
}
}
}
示例8: generateTypeHint
private function generateTypeHint(\ReflectionParameter $param)
{
if ($param->isArray()) {
return 'array ';
} else {
if ($param->isCallable()) {
return 'callable ';
} else {
if ($param->getClass()) {
return $param->getClass()->getName() . ' ';
} else {
return '';
}
}
}
}
示例9: getParameterType
/**
* @return string|NULL
*/
public static function getParameterType(\ReflectionParameter $param)
{
if (PHP_VERSION_ID >= 70000) {
return $param->hasType() ? (string) $param->getType() : NULL;
} elseif ($param->isArray()) {
return 'array';
} elseif (PHP_VERSION_ID >= 50400 && $param->isCallable()) {
return '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;
}
}
}
示例10: getType
/**
* Returns an associated type to the given parameter if available.
*
* @param \ReflectionParameter $parameter
*
* @return null|string
*/
private function getType(\ReflectionParameter $parameter)
{
if (PHP_VERSION_ID >= 70000) {
return $parameter->hasType() ? (string) $parameter->getType() : null;
}
if ($parameter->isArray()) {
return 'array';
}
if ($parameter->isCallable()) {
return 'callable';
}
try {
$refClass = $parameter->getClass();
} catch (\ReflectionException $e) {
// mandatory; extract it from the exception message
return str_replace(array('Class ', ' does not exist'), '', $e->getMessage());
}
return $refClass ? $refClass->getName() : null;
}
示例11: generateParameterDeclaration
protected function generateParameterDeclaration(\ReflectionParameter $param)
{
$output = '';
if ($param->isArray()) {
$output .= 'array ';
} elseif (is_callable(array($param, 'isCallable')) && $param->isCallable()) {
$output .= 'callable ';
} elseif ($param->getClass()) {
$output .= '\\' . $param->getClass()->getName() . ' ';
}
if ($param->isPassedByReference()) {
$output .= '&';
}
$output .= '$' . $param->getName();
if ($param->isDefaultValueAvailable()) {
$output .= ' = ' . $param->getDefaultValue();
}
return $output;
}
示例12: 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;
}
}
}
示例13: getParamType
/**
* Determine the fully-qualified name of a type-hint for the given param without actually loading typehinted classes.
*
* @param \ReflectionParameter $param
* @return string Hinted typename or NULL when no type-hint is present.
*/
protected function getParamType(\ReflectionParameter $param)
{
if ($param->isArray()) {
return 'array';
}
if ($param->isCallable()) {
return 'callable';
}
$m = NULL;
if (defined('HHVM_VERSION')) {
// @codeCoverageIgnoreStart
$type = $param->getTypehintText();
if ('' === trim($type)) {
$type = NULL;
}
// @codeCoverageIgnoreEnd
} elseif (preg_match("'\\[\\s*<[^>]+>\\s+([a-z_][a-z_0-9]*(?:\\s*\\\\\\s*[a-z_][a-z_0-9]*)*)'i", (string) $param, $m)) {
$type = preg_replace("'\\s+'", '', $m[1]);
} else {
$type = NULL;
}
if ($type !== NULL) {
switch (strtolower($type)) {
case 'self':
$ref = $param->getDeclaringFunction();
if ($ref instanceof \ReflectionMethod) {
return $ref->getDeclaringClass()->name;
}
throw new \RuntimeException(sprintf('Unable to resolve "self" in parameter "%s" of function %s', $param->name, $ref->name));
case 'boolean':
return 'bool';
case 'integer':
return 'int';
}
return $type;
}
return NULL;
}
示例14: getParameterCode
/**
* Return string representation of parameter
*
* @param Parameter|ParsedParameter $parameter Reflection parameter
*
* @return string
*/
protected function getParameterCode($parameter)
{
$type = '';
if ($parameter->isArray()) {
$type = 'array';
} elseif ($parameter->isCallable()) {
$type = 'callable';
} elseif ($parameter->getClass()) {
$type = '\\' . $parameter->getClass()->name;
}
$defaultValue = null;
$isDefaultValueAvailable = $parameter->isDefaultValueAvailable();
if ($isDefaultValueAvailable) {
if ($parameter instanceof ParsedParameter) {
$defaultValue = $parameter->getDefaultValueDefinition();
} else {
$defaultValue = var_export($parameter->getDefaultValue(), true);
}
} elseif ($parameter->isOptional()) {
$defaultValue = 'null';
}
$code = ($type ? "{$type} " : '') . ($parameter->isPassedByReference() ? '&' : '') . ($this->useVariadics && $parameter->isVariadic() ? '...' : '') . '$' . $parameter->name . ($defaultValue !== null ? " = " . $defaultValue : '');
return $code;
}
示例15: documentParam
/**
* @param \ReflectionParameter $param
*
* @return string
*/
protected function documentParam(\ReflectionParameter $param)
{
$text = "";
if ($param->isArray()) {
$text .= 'array ';
}
if ($param->isCallable()) {
$text .= 'callable ';
}
$text .= '$' . $param->name;
if ($param->isDefaultValueAvailable()) {
if ($param->allowsNull()) {
$text .= ' = null';
} else {
$text .= ' = ' . str_replace("\n", ' ', print_r($param->getDefaultValue(), true));
}
}
return $text;
}