WsdlToPhp\PackageGenerator\Generator\Utils::getValueWithinItsType PHP Method

getValueWithinItsType() public static method

Returns the value with good type
public static getValueWithinItsType ( mixed $value, $knownType = null ) : mixed
$value mixed the value
return mixed
    public static function getValueWithinItsType($value, $knownType = null)
    {
        if (is_int($value) || !is_null($value) && in_array($knownType, array('time', 'positiveInteger', 'unsignedLong', 'unsignedInt', 'short', 'long', 'int', 'integer'), true)) {
            return intval($value);
        } elseif (is_float($value) || !is_null($value) && in_array($knownType, array('float', 'double', 'decimal'), true)) {
            return floatval($value);
        } elseif (is_bool($value) || !is_null($value) && in_array($knownType, array('bool', 'boolean'), true)) {
            return $value === 'true' || $value === true || $value === 1 || $value === '1';
        }
        return $value;
    }

Usage Example

 /**
  * 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());
 }
All Usage Examples Of WsdlToPhp\PackageGenerator\Generator\Utils::getValueWithinItsType