本文整理汇总了PHP中Type::getStringValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::getStringValue方法的具体用法?PHP Type::getStringValue怎么用?PHP Type::getStringValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type::getStringValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: TryParse
/**
* Extracts a {@see \Beluga\GIS\Longitude} instance from defined value and returns it by reference with the
* $output parameter. The Method returns TRUE on success, FALSE otherwise.
*
* @param string|double|float|\SimpleXMLElement|\Beluga\GIS\Longitude|\Beluga\GIS\Coordinate $value
* @param \Beluga\GIS\Longitude|null &$output Returns the resulting Longitude reference, if the method returns TRUE
* @return boolean
*/
public static function TryParse($value, &$output) : bool
{
if (\is_null($value)) {
return false;
}
if ($value instanceof Longitude) {
$output = $value;
return true;
}
if ($value instanceof Coordinate) {
$output = $value->Longitude;
return true;
}
if (\is_double($value) || \is_float($value)) {
$data = AbstractElement::_DecToDDMS($value, true);
try {
$output = new Longitude($data['DIR'], $data['DEG'], $data['MIN'], $data['SEC']);
} catch (\Throwable $ex) {
return false;
}
return true;
}
$type = new Type($value);
if (!$type->hasAssociatedString()) {
return false;
}
return self::TryParseString($type->getStringValue(), $output);
}
示例2: WriteTypedXmlValue
/**
* Writes all data of the defined Value to the XmlWriter.
*
* You can write it in 3 different ways:
*
* - <$name type="..." value="..." />
* Is created if $short is boolean TRUE.
*
* If $short is FALSE you can write in the following 2 ways:
*
* - <$name type="...">$value</$name>
* Is created if $separateElements is boolean FALSE.
* - <$name><Type>...</Type><Value>$value</Value></$name>
* Is created if $separateElements is boolean TRUE.
*
* @param \XMLWriter $w The XmlWriter to use.
* @param mixed $value The value to write.
* @param string $name The name of the element to write
* @param boolean $short Use the short notation? (type and value as attributes)
* @param boolean $separateElements Write type and value in separate elements, if $short is FALSE
*/
public static function WriteTypedXmlValue(\XMLWriter $w, $value, string $name, bool $short = true, bool $separateElements = false)
{
if (!$value instanceof Type) {
$value = new Type($value);
}
$v = null;
$t = null;
switch ($value->getType()) {
case Type::PHP_ARRAY:
$v = \serialize($value->getValue());
$t = Type::PHP_ARRAY;
break;
case Type::PHP_BOOLEAN:
$v = $value->getValue() ? 'true' : 'false';
$t = Type::PHP_BOOLEAN;
break;
case Type::PHP_DOUBLE:
case Type::PHP_FLOAT:
case Type::PHP_INTEGER:
$v = $value->getValue();
$t = $value->getType();
break;
case Type::PHP_NULL:
$v = '';
$t = Type::PHP_NULL;
break;
case Type::PHP_RESOURCE:
# Ignore some resources
break;
case Type::PHP_STRING:
$v = $value->getValue();
$t = Type::PHP_STRING;
break;
case Type::PHP_UNKNOWN:
$v = $value->getStringValue();
$t = Type::PHP_STRING;
break;
default:
$v = \serialize($value->getValue());
$t = $value->getType();
break;
}
if (!\is_null($t) && !\is_null($v)) {
$w->startElement($name);
if ($short) {
$w->writeAttribute('type', $t);
$w->writeAttribute('value', $v);
} else {
if ($separateElements) {
$w->writeElement('type', $t);
$w->writeElement('value', $v);
} else {
$w->writeAttribute('type', $t);
$w->text($v);
}
}
$w->endElement();
}
}
示例3: TryParse
/**
* Extracts a {@see \Beluga\GIS\Coordinate} instance from defined value and returns it by reference with the
* $output parameter. The Method returns TRUE on success, FALSE otherwise.
*
* @param string|double|float|\Beluga\GIS\Coordinate $value The value to parse.
* @param \Beluga\GIS\Coordinate|null &$output Returns the resulting Coordinate reference, if the method returns TRUE
* @return boolean
*/
public static function TryParse($value, &$output) : bool
{
if (empty($value)) {
return false;
}
if ($value instanceof Coordinate) {
$output = $value;
return true;
}
$type = new Type($value);
if (!$type->hasAssociatedString()) {
return false;
}
return self::TryParseString($type->getStringValue(), $output);
}