GetXmlTypeCode
@param object $value
@return XmlTypeCode
327150
static public function GetXmlTypeCodeFromObject( $value )
	{
		if ( $value instanceof XPathNavigator )
		{
			/**
			 * @var XPathNavigator $nav
			 */
			$nav = $value;
			switch ( $nav->getNodeType() )
			{
				case XPathNodeType::Attribute:
					return XmlTypeCode::Attribute;

				case XPathNodeType::Comment:
					return XmlTypeCode::Comment;

				case XPathNodeType::Element:
					return XmlTypeCode::Element;

				case XPathNodeType::NamespaceURI:
					return XmlTypeCode::Namespace_;

				case XPathNodeType::ProcessingInstruction:
					return XmlTypeCode::ProcessingInstruction;

				case XPathNodeType::Root:
					return XmlTypeCode::Document;

				case XPathNodeType::SignificantWhitespace:
				case XPathNodeType::Whitespace:
				case XPathNodeType::Text:
					return XmlTypeCode::Text;

				default:
					return XmlTypeCode::None;
			}
		}
		if ( $value instanceof  XPathItem )
		{
			/**
			 * @var XPathItem $item
			 */
			$item = $value;
			if ( is_null( $item->getSchemaType() ) )
			{
				return XmlTypeCode::UntypedAtomic;
			}

			return $item->getSchemaType()->TypeCode;
		}

		return SequenceType::GetXmlTypeCodeFromType( Type::FromValue( $value ) );
	}
107478
public function encodeValue($value)
    {
        $type = gettype($value);

        switch ($type) {
            case 'boolean':
                return ['booleanValue' => $value];
                break;

            case 'integer':
                return ['integerValue' => $value];
                break;

            case 'double':
                return ['doubleValue' => $value];
                break;

            case 'string':
                return ['stringValue' => $value];
                break;

            case 'resource':
                return ['bytesValue' => stream_get_contents($value)];
                break;

            case 'object':
                return $this->encodeObjectValue($value);
                break;

            case 'array':
                if (!empty($value) && $this->isAssoc($value)) {
                    return $this->encodeAssociativeArrayValue($value);
                }

                return ['arrayValue' => $this->encodeArrayValue($value)];
                break;

            case 'NULL':
                // @todo encode this in a way such that is compatible with a potential future REST transport.
                return ['nullValue' => NullValue::NULL_VALUE];
                break;

            // @codeCoverageIgnoreStart
            default:
                throw new \RuntimeException(sprintf(
                    'Invalid value type %s',
                    $type
                ));
                break;
            // @codeCoverageIgnoreEnd
        }
    }
387747
protected function handleDateParameter( $value )
    {
        $date = DateTime::createFromFormat(
            self::XML_RPC_ISO8601, (string)$value, new \DateTimeZone( 'UTC' )
        );

        // no separators, maybe, try again
        if ( $date instanceof DateTime )
        {
            $date->setTimezone( new DateTimeZone( date_default_timezone_get() ) );
            return $date;
        }

        $parts = explode( 'T', $value );

        if ( count( $parts ) != 2 )
            throw new UnexpectedValueException( "Invalid date $value" );
        if ( strlen( $parts[0] ) !== 8 || strlen( $parts[1] ) != 8)
            throw new UnexpectedValueException( "Invalid date $value" );

        $dateParts = array();
        sscanf( $parts[0], '%04d%02d%02d', $dateParts['year'], $dateParts['month'], $dateParts['day'] );
        sscanf( $parts[1], '%02d:%02d:%02d', $dateParts['hours'], $dateParts['minutes'], $dateParts['seconds'] );
        $iso8601date = sprintf(
            '%4d-%02d-%02dT%02d:%02d:%02d',
            $dateParts['year'], $dateParts['month'], $dateParts['day'],
            $dateParts['hours'], $dateParts['minutes'], $dateParts['seconds']
        );

        $date = DateTime::createFromFormat( self::XML_RPC_ISO8601, $iso8601date, new DateTimeZone( 'UTC' ) );
        if ( $date instanceof DateTime )
        {
            $date->setTimezone( new DateTimeZone( date_default_timezone_get() ) );
            return $date;
        }
        return $date;
    }
1097467
public function getTypeForValue($value) : string
    {
        foreach ($this->handlers as $type => $handler) {
            if ($handler->canHandleValue($value)) {
                return $type;
            }
        }

        throw DataTypeException::handlerNotFoundForValue($value);
    }
125949
public static function getTypeCodeFromObject( $value )
	{
		if ( is_null( $value ) )
		{
			return TypeCode::Null_;
		}

		if ( is_array( $value ) )
		{
			return TypeCode::assocArray;
		}

		if ( is_string( $value ) )
		{
			return strlen( $value ) === 1 ? TypeCode::Char : TypeCode::String;
		}

		if ( $value instanceof DateTime )
		{
			return TypeCode::DateTime;
		}

		if ( $value instanceof DateTimeInterval )
		{
			return TypeCode::DateTimeInterval;
		}

		if ( is_double( $value ) )
		{
			return TypeCode::Double;
		}

		if ( is_int( $value ) )
		{
			return TypeCode::Int32;
		}

		if ( is_bool( $value ) )
		{
			return TypeCode::Boolean;
		}

		if ( is_object( $value ) )
		{
			return TypeCode::Object;
		}
	}
896842
public function getOptionsByValue($value)
	{
		$xpath = 'descendant-or-self::option[@value = ' . $this->getXpathEscaper()->escapeLiteral($value) . ']';

		return $this->wrapOptions($this->getWrappedElement()->findAll('xpath', $xpath));
	}
49617
public function xml( $value, $trust = self::TAINT )
	{
		if( $trust === self::TRUST ) {
			return $value;
		}

		return htmlspecialchars( $value, ENT_NOQUOTES, 'UTF-8' );
	}
524647
public static function convertEntities($value)
    {
        $converted = null;
        
        //deal with double encoded payload 
        $value = preg_replace('/&amp;/', '&', $value);     
        
        if (preg_match('/&#x?[\w]+/ms', $value)) {
            $converted = preg_replace('/(&#x?[\w]{2}\d?);?/ms', '$1;', $value);
            $converted = html_entity_decode($converted, ENT_QUOTES, 'UTF-8');
            $value    .= "\n" . str_replace(';;', ';', $converted);
        }
        // normalize obfuscated protocol handlers
        $value = preg_replace(
            '/(?:j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:)|(d\s*a\s*t\s*a\s*:)/ms', 
            'javascript:', $value
        );
        
        return $value;
    }
8369
protected function encode($value)
    {
        try {
            return $this->encoders->getEncoderForValue($value)
                ->encode($value, new EncodingContext());
        } catch (EncodingException | InvalidArgumentException | OutOfBoundsException $ex) {
            throw new SerializationException('Failed to serialize value', 0, $ex);
        }
    }
503237
protected function encode($value)
    {
        if (is_object($value) && method_exists($value, 'getJs')) {
            return new JsExpression($value->getJs());
        } elseif (is_bool($value)) {
            return new JsExpression(($value ? 'true' : 'false'));
        } elseif (is_array($value)) {
            $parsed = [];
            foreach ($value as $child) {
                $parsed[] = $this->encode($child);
            }
            return $parsed;
        }
        try {
            // a value may contain a valid JSON string
            return Json::decode($value);
        } catch (InvalidParamException $e) {
        }
        return $value;
    }
115260
protected function _getType($value)
    {
        if (is_object($value)) {
            try {
                return self::getShortClassname($value);
            } catch (\InvalidArgumentException $e) {
                return null;
            }
        }

        if (is_array($value)) {
            return 'array';
        }

        return 'scalar';
    }
541023
protected function resolveTypeDescription($value): string
    {
        $type = gettype($value);

        if ($type === 'object') {
            return 'an instance of ' . get_class($value);
        }

        if ($type === 'integer') {
            return 'an integer';
        }

        return 'a ' . $type;
    }
1189592
public static function getType($value)
    {
        if (is_int($value)) {
            return MDataType::INT;
        }

        if (is_long($value)) {
            return MDataType::LONG;
        }

        if (is_bool($value)) {
            return MDataType::BOOLEAN;
        }

        if (is_float($value)) {
            return MDataType::FLOAT;
        }

        if (is_double($value)) {
            return MDataType::DOUBLE;
        }

        if (is_string($value)) {
            return MDataType::STRING;
        }

        if ($value == null) {
            return MDataType::NULL;
        }

        if (is_array($value)) {
            return MDataType::__ARRAY;
        }

        if (is_object($value)) {
            return MDataType::OBJECT;
        }

        if (is_resource($value)) {
            return MDataType::RESOURCE;
        }

        return MDataType::UNKNOWN;
    }
884800
private static function convertToString($value): string
    {
        // float value (INF and NAN are float type)
        if (is_float($value)) {
            if (is_infinite($value)) {
                $value = 'INF';
            } elseif (is_nan($value)) {
                $value = 'NAN';
            } else {
                $value = (string) $value;
                if (self::XML_PRESERVE_ZERO_FRACTION && strpos($value, '.') === false) {
                    $value .= '.0';
                }
            }
        }

        // bool value
        if (is_bool($value)) {
            $value = ($value === true) ? 'true' : 'false';
        }

        // class value
        if (is_object($value)) {
            $value = json_encode($value);
        }

        // int or string value.
        return (string) $value;
    }
997964
protected function getTypeOf($value): string
    {
        $type = gettype($value);

        switch ($type) {
            case 'integer':
            case 'boolean':
            case 'string':
                return $type;
            case 'double':
                return 'float';
            case 'array':
                return count(array_filter(array_keys($value), 'is_string')) > 0 ? 'assoc' : 'array';
            case 'object':
                return $value instanceof Traversable ? 'array' :
                    ($value instanceof DateTime ? DateTime::class : 'object');
            default:
                return $type;
        }
    }
1206284
public function encode($value)
    {
        switch (true) {
            case is_null($value):
                return $this->encodeString('', self::T_NULL);
            case is_bool($value):
                return $this->encodeString($value ? 'true' : 'false', self::T_BOOL);
            case is_int($value):
                return $this->encodeString($value, self::T_INT);
            case is_float($value):
                return $this->encodeString($value, self::T_FLOAT);
            case is_array($value):
                return $this->encodePHPArray($value);

            case is_resource($value):
                throw new InvalidArgumentException("You can't encode a PHP resource as a tagged netstring.");

            default:
                return $this->encodeString($value);
        }
    }
1348054
protected function getValueTypeDescription($value): string
    {
        if (is_resource($value)) {
            $valueType = get_resource_type($value) . " resource";
        } elseif (is_object($value)) {
            $valueType = get_class($value) . " object";
        } elseif (is_string($value)) {
            $valueType = "string \"{$value}\"";
        } else {
            $valueType = gettype($value);
        }

        return $valueType;
    }