Returns the value with good type
public static getValueWithinItsType ( mixed $value, $knownType = null ) : mixed | ||
$value | mixed | the value |
return | mixed |
/** * Returns potential default value * @uses AbstractModel::getMetaValueFirstSet() * @uses Utils::getValueWithinItsType() * @uses StructAttribute::getType() * @uses StructAttribute::getContainsElements() * @return mixed */ public function getDefaultValue() { if ($this->isArray()) { return array(); } return Utils::getValueWithinItsType($this->getMetaValueFirstSet(array('default', 'Default', 'DefaultValue', 'defaultValue', 'defaultvalue')), $this->getType()); }
/** * @param bool $withNamespace * @param bool $withinItsType * @param string $asType * @return mixed */ public function getValue($withNamespace = false, $withinItsType = true, $asType = self::DEFAULT_VALUE_TYPE) { $value = $this->getAttribute()->value; if ($withNamespace === false && !empty($value)) { $value = implode('', array_slice(explode(':', $value), -1, 1)); } if ($value !== null && $withinItsType === true) { $value = Utils::getValueWithinItsType($value, empty($asType) ? $this->getType() : $asType); } return $value; }
/** * */ public function testGetValueWithinItsType() { $this->assertSame('020', Utils::getValueWithinItsType('020', 'string')); $this->assertSame('01', Utils::getValueWithinItsType('01', 'string')); }
/** * Returns the value with good type * @uses AbstractModel::getName() * @uses Utils::getValueWithinItsType() * @return mixed */ public function getValue() { return Utils::getValueWithinItsType($this->getName()); }