本文整理汇总了PHP中ReflectionParameter::isPassedByReference方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::isPassedByReference方法的具体用法?PHP ReflectionParameter::isPassedByReference怎么用?PHP ReflectionParameter::isPassedByReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::isPassedByReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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}" : '');
}
示例2: __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);
}
}
示例3: fromReflection
/**
* Creates a PHP parameter from reflection
*
* @param \ReflectionParameter $ref
* @return PhpParameter
*/
public static function fromReflection(\ReflectionParameter $ref)
{
$parameter = new static();
$parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference());
if ($ref->isDefaultValueAvailable()) {
$parameter->setDefaultValue($ref->getDefaultValue());
}
// find type and description in docblock
$docblock = new Docblock($ref->getDeclaringFunction());
$params = $docblock->getTags('param');
$tag = $params->find($ref->name, function (ParamTag $t, $name) {
return $t->getVariable() == '$' . $name;
});
if ($tag !== null) {
$parameter->setType($tag->getType(), $tag->getDescription());
}
// set type if not found in comment
if ($parameter->getType() === null) {
if ($ref->isArray()) {
$parameter->setType('array');
} elseif ($class = $ref->getClass()) {
$parameter->setType($class->getName());
} elseif (method_exists($ref, 'isCallable') && $ref->isCallable()) {
$parameter->setType('callable');
}
}
return $parameter;
}
示例4: 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;
}
示例5: 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;
}
示例6: isPassedByReference
/**
* Returns whether this parameters is passed to by reference
* @return boolean
*/
public function isPassedByReference()
{
if ($this->parameter != null) {
return $this->parameter->isPassedByReference();
} else {
return parent::isPassedByReference();
}
}
示例7: getParameterInfo
private function getParameterInfo(\ReflectionParameter $parameter)
{
$paramName = '$' . $parameter->getName() . '=null';
if ($parameter->isPassedByReference()) {
$paramName = '&' . $paramName;
}
$paramType = $parameter->getClass() !== null ? $parameter->getClass()->getName() : '';
return "{$paramType} {$paramName}";
}
示例8:
function __construct(API_Doc_Method $method, ReflectionParameter $parameter)
{
$this->name = $parameter->getName();
$this->is_passed_by_reference = $parameter->isPassedByReference();
$this->allows_null = $parameter->allowsNull();
$this->is_optional = $parameter->isOptional();
$this->is_default_value_available = $parameter->isDefaultValueAvailable();
$this->position = $parameter->getPosition();
$this->declaring_method = $method;
}
示例9: testWrappedMethods
public function testWrappedMethods()
{
$php_parameter = new \ReflectionParameter([$this, 'method'], 'param');
$our_parameter = new ReflectionParameter($php_parameter);
$this->assertSame($php_parameter->getName(), $our_parameter->getName());
$this->assertSame($php_parameter->allowsNull(), $our_parameter->allowsNull());
$this->assertSame($php_parameter->isOptional(), $our_parameter->isOptional());
$this->assertSame($php_parameter->isDefaultValueAvailable(), $our_parameter->isDefaultValueAvailable());
$this->assertSame($php_parameter->isVariadic(), $our_parameter->isVariadic());
$this->assertSame($php_parameter->isPassedByReference(), $our_parameter->isPassedByReference());
$this->assertSame($php_parameter->getDefaultValue(), $our_parameter->getDefaultValue());
}
示例10: parameter
/**
* @param \ReflectionParameter $parameter
* @return Parameter
*/
public function parameter(\ReflectionParameter $parameter)
{
$phpyParam = new Parameter($parameter->getName());
if ($parameter->isArray()) {
$phpyParam->setTypeHint('array');
} elseif ($class = $parameter->getClass()) {
$phpyParam->setTypeHint('\\' . $class->getName());
}
if ($parameter->isDefaultValueAvailable()) {
$phpyParam->setDefaultValue($parameter->getDefaultValue());
}
$phpyParam->setByRef($parameter->isPassedByReference());
return $phpyParam;
}
示例11: fromReflection
public static function fromReflection(\ReflectionParameter $ref)
{
$parameter = new static();
$parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference());
if ($ref->isDefaultValueAvailable()) {
$parameter->setDefaultValue($ref->getDefaultValue());
}
if ($ref->isArray()) {
$parameter->setType('array');
} elseif ($class = $ref->getClass()) {
$parameter->setType($class->getName());
} elseif (method_exists($ref, 'isCallable') && $ref->isCallable()) {
$parameter->setType('callable');
}
return $parameter;
}
示例12: getArgumentDetails
/**
* Gets the details for a single method argument
*
* @param \ReflectionParameter $argument Argument's ReflectionParameter instance
* @return ArgumentData
*/
private function getArgumentDetails(\ReflectionParameter $argument)
{
$details = new ArgumentData();
$details->name = $argument->getName();
$details->passedByReference = $argument->isPassedByReference();
// true if no typehinting or typehinted argument defaults to null
$details->allowsNull = $argument->allowsNull();
$details->dataType = $this->getArgumentType($argument);
if ($details->dataType === 'object') {
$classData = $this->getDefaultValueClassData($argument->__toString());
$details->className = $classData['className'];
$details->classNamespace = $classData['classNamespace'];
}
if ($argument->isOptional()) {
$details->isRequired = false;
$details->defaultValue = $argument->getDefaultValue();
}
return $details;
}
示例13: create_from_reflection_parameter
public static function create_from_reflection_parameter(\ReflectionParameter $rp)
{
$arg = new Argument($rp->getName());
if ($rp->allowsNull()) {
$arg->set_null_allowed(true);
}
if ($rp->isDefaultValueAvailable()) {
$arg->set_default($rp->getDefaultValue());
}
if ($rp->isArray()) {
$arg->set_array(true);
} elseif ($type = $rp->getClass()) {
$arg->set_type($type->getName());
}
if ($rp->isPassedByReference()) {
$arg->set_reference(true);
}
return $arg;
}
示例14: 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;
}
示例15: __construct
public function __construct($method, $param)
{
$param = new ReflectionParameter($method, $param);
$this->name = $param->name;
if ($param->isDefaultValueAvailable()) {
$default = $param->getDefaultValue();
if ($default === NULL) {
$this->default .= 'NULL';
} elseif (is_bool($default)) {
$this->default .= $default ? 'TRUE' : 'FALSE';
} elseif (is_string($default)) {
$this->default .= "'" . $default . "'";
} else {
$this->default .= print_r($default, TRUE);
}
}
if ($param->isPassedByReference()) {
$this->byref = TRUE;
}
if ($param->isOptional()) {
$this->optional = TRUE;
}
}