Return handler with only the possible types for the value.

@return static
556317
protected function onlyPossible(): self
    {
        if (count($this->types) < 2) {
            return $this;
        }

        $possible = $this->getPossibleTypes($this->value);

        return empty($possible) ? $this : $this->setTypes($possible);
    }
1268644
public static function __static()
	{
		// XmlTypeCode::getTypeForCode( XmlTypeCode::Boolean );
		XmlSchema::$AnySimpleType = DOMSchemaType::GetBuiltInSimpleTypeByQName( new \lyquidity\xml\qname( SCHEMA_PREFIX, XmlReservedNs::xs, "anySimpleType" ) );
		XmlSchema::$AnyType = DOMSchemaType::GetBuiltInComplexTypeByQName( new \lyquidity\xml\qname( SCHEMA_PREFIX, XmlReservedNs::xs, "anyType" ) );
		XmlSchema::$AnyUri = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::AnyUri );
		XmlSchema::$AnyAtomicType = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::AnyAtomicType );
		XmlSchema::$UntypedAtomic = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::UntypedAtomic );
		XmlSchema::$Boolean = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Boolean );
		XmlSchema::$Byte = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Byte );
		XmlSchema::$Integer = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Integer );
		XmlSchema::$Decimal = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Decimal );
		XmlSchema::$Double = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Double );
		XmlSchema::$Float = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Float );
		XmlSchema::$Long = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Long );
		XmlSchema::$Short = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Short );
		XmlSchema::$UnsignedLong = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::UnsignedLong );
		XmlSchema::$UnsignedInt = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::UnsignedInt );
		XmlSchema::$UnsignedShort = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::UnsignedShort );
		XmlSchema::$DateTime = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::DateTime );
		XmlSchema::$Date = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Date );
		XmlSchema::$Time = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Time );
		XmlSchema::$Duration = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Duration );
		XmlSchema::$YearMonthDuration = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::YearMonthDuration );
		XmlSchema::$DayTimeDuration = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::DayTimeDuration );
		XmlSchema::$GYearMonth = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::GYearMonth );
		XmlSchema::$GYear = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::GYear );
		XmlSchema::$GDay = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::GDay );
		XmlSchema::$GMonth = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::GMonth );
		XmlSchema::$GMonthDay = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::GMonthDay );
		XmlSchema::$QName = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::QName );
		XmlSchema::$HexBinary = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::HexBinary );
		XmlSchema::$Base64Binary = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Base64Binary );
		XmlSchema::$NMTOKEN = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::NmToken );
		XmlSchema::$IDREF = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Idref );
		XmlSchema::$ID = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Id );
		XmlSchema::$IDREFS = DOMSchemaType::GetBuiltInSimpleTypeByQName( new \lyquidity\xml\qname( SCHEMA_PREFIX, XmlReservedNs::xs, "IDREFS" ) );
		XmlSchema::$NMTOKENS = DOMSchemaType::GetBuiltInSimpleTypeByQName( new \lyquidity\xml\qname( SCHEMA_PREFIX, XmlReservedNs::xs, "NMTOKENS" ) );
		XmlSchema::$ENTITY = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Entity );
		XmlSchema::$ENTITIES = DOMSchemaType::GetBuiltInSimpleTypeByQName( new \lyquidity\xml\qname( SCHEMA_PREFIX, XmlReservedNs::xs, "ENTITIES" ) );
		XmlSchema::$Name = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Name );
		XmlSchema::$NCName = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::NCName );
		XmlSchema::$String = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::String );
		XmlSchema::$Token = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Token );
		XmlSchema::$Notation = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Notation );
		XmlSchema::$Language = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::Language );
		XmlSchema::$NormalizedString = DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::NormalizedString );
	}
251008
protected function pickArrayForScalar(): self
    {
        if (
            count($this->types) < 2 ||
            (!is_scalar($this->value) && (!is_object($this->value) || get_class($this->value) === stdClass::class))
        ) {
            return $this;
        }

        if (in_array('array', $this->types)) {
            $types = array_filter($this->types, function($type) {
                return substr($type, -2) !== '[]';
            });

            return $this->setTypes($types);
        }

        $subtypes = $this->getSubTypes();
        if (count($subtypes) !== count($this->types)) {
            return $this;
        }

        $type = $this->guess($this->value, $subtypes);

        return $type ? $this->setTypes([$type . '[]']) : $this;
    }
115433
static function __static()
	{
		XmlTokenizedType::$typeToCodeMap = array(
			'xs:string'					=> XmlTokenizedType::None,
			'xs:boolean'				=> XmlTokenizedType::None,
			'xs:decimal'				=> XmlTokenizedType::None,
			'xs:double'					=> XmlTokenizedType::None,
			'xs:float'					=> XmlTokenizedType::None,
			'xs:duration'				=> XmlTokenizedType::None,
			'xs:dateTime'				=> XmlTokenizedType::None,
			'xs:time'					=> XmlTokenizedType::None,
			'xs:date'					=> XmlTokenizedType::None,
			'xs:gYearMonth'				=> XmlTokenizedType::None,
			'xs:gYear'					=> XmlTokenizedType::None,
			'xs:gMonthDay'				=> XmlTokenizedType::None,
			'xs:gDay'					=> XmlTokenizedType::None,
			'xs:gMonth'					=> XmlTokenizedType::None,
			'xs:hexBinary'				=> XmlTokenizedType::None,
			'xs:base64Binary'			=> XmlTokenizedType::None,
			'xs:anyURI'					=> XmlTokenizedType::None,
			'xs:QName'					=> XmlTokenizedType::None,
			'xs:NOTATION'				=> XmlTokenizedType::NOTATION,
			'xs:normalizedString'		=> XmlTokenizedType::None,
			'xs:token'					=> XmlTokenizedType::None,
			'xs:language'				=> XmlTokenizedType::None,
			'xs:name'					=> XmlTokenizedType::None,
			'xs:NCName'					=> XmlTokenizedType::NCName,
			'xs:NMTOKEN'				=> XmlTokenizedType::NMTOKEN,
			'xs:ID'						=> XmlTokenizedType::ID,
			'xs:IDREF'					=> XmlTokenizedType::IDREF,
			'xs:ENTITY'					=> XmlTokenizedType::ENTITY,
			'xs:integer'				=> XmlTokenizedType::None,
			'xs:nonPositiveInteger'		=> XmlTokenizedType::None,
			'xs:long'					=> XmlTokenizedType::None,
			'xs:nonNegativeInteger'		=> XmlTokenizedType::None,
			'xs:negativeInteger' 		=> XmlTokenizedType::None,
			'xs:int'					=> XmlTokenizedType::None,
			'xs:short'					=> XmlTokenizedType::None,
			'xs:byte'					=> XmlTokenizedType::None,
			'xs:positiveInteger' 		=> XmlTokenizedType::None,
			'xs:unsignedLong' 			=> XmlTokenizedType::None,
			'xs:unsignedInt' 			=> XmlTokenizedType::None,
			'xs:unsignedShort'			=> XmlTokenizedType::None,
			'xs:unsignedByte'			=> XmlTokenizedType::None,
			'xs:IDREFS'					=> XmlTokenizedType::IDREFS,
			'xs:ENTITIES'				=> XmlTokenizedType::ENTITIES,
			'xs:NMTOKENS'				=> XmlTokenizedType::NMTOKENS,
			'xsd:string'				=> XmlTokenizedType::None,
			'xsd:boolean'				=> XmlTokenizedType::None,
			'xsd:decimal'				=> XmlTokenizedType::None,
			'xsd:double'				=> XmlTokenizedType::None,
			'xsd:float'					=> XmlTokenizedType::None,
			'xsd:duration'				=> XmlTokenizedType::None,
			'xsd:dateTime'				=> XmlTokenizedType::None,
			'xsd:time'					=> XmlTokenizedType::None,
			'xsd:date'					=> XmlTokenizedType::None,
			'xsd:gYearMonth'			=> XmlTokenizedType::None,
			'xsd:gYear'					=> XmlTokenizedType::None,
			'xsd:gMonthDay'				=> XmlTokenizedType::None,
			'xsd:gDay'					=> XmlTokenizedType::None,
			'xsd:gMonth'				=> XmlTokenizedType::None,
			'xsd:hexBinary'				=> XmlTokenizedType::None,
			'xsd:base64Binary'			=> XmlTokenizedType::None,
			'xsd:anyURI'				=> XmlTokenizedType::None,
			'xsd:QName'					=> XmlTokenizedType::None,
			'xsd:NOTATION'				=> XmlTokenizedType::NOTATION,
			'xsd:normalizedString'		=> XmlTokenizedType::None,
			'xsd:token'					=> XmlTokenizedType::None,
			'xsd:language'				=> XmlTokenizedType::None,
			'xsd:name'					=> XmlTokenizedType::None,
			'xsd:NCName'				=> XmlTokenizedType::NCName,
			'xsd:NMTOKEN'				=> XmlTokenizedType::NMTOKEN,
			'xsd:ID'					=> XmlTokenizedType::ID,
			'xsd:IDREF'					=> XmlTokenizedType::IDREF,
			'xsd:ENTITY'				=> XmlTokenizedType::ENTITY,
			'xsd:integer'				=> XmlTokenizedType::None,
			'xsd:nonPositiveInteger'	=> XmlTokenizedType::None,
			'xsd:long'					=> XmlTokenizedType::None,
			'xsd:nonNegativeInteger'	=> XmlTokenizedType::None,
			'xsd:negativeInteger' 		=> XmlTokenizedType::None,
			'xsd:int'					=> XmlTokenizedType::None,
			'xsd:short'					=> XmlTokenizedType::None,
			'xsd:byte'					=> XmlTokenizedType::None,
			'xsd:positiveInteger' 		=> XmlTokenizedType::None,
			'xsd:unsignedLong' 			=> XmlTokenizedType::None,
			'xsd:unsignedInt' 			=> XmlTokenizedType::None,
			'xsd:unsignedShort'			=> XmlTokenizedType::None,
			'xsd:unsignedByte'			=> XmlTokenizedType::None,
			'xsd:IDREFS'				=> XmlTokenizedType::IDREFS,
			'xsd:ENTITIES'				=> XmlTokenizedType::ENTITIES,
			'xsd:NMTOKENS'				=> XmlTokenizedType::NMTOKENS,
		);
	}
1197765
protected function getHandler()
    {
        $handler = resolve($this->type->handler);
        if (!$handler instanceof ContentTypeHandler) {
            throw new DomainException("Type: $this->type can't be handled");
        }
        return $handler;
    }
1153308
protected function castParameter($value, $type = null) {
		//check null value
		if (is_null($value))
			return 'NULL';
		elseif (is_null($type)) {
			//obtain default type handler
			$typeHandler = $this->getDefaultTypeHandler($value);
			if (is_null($typeHandler))
				return 'NULL';
			if (is_array($value))
				return $this->castArray($value, $typeHandler, '_');
		}
		else {
			//cast value to the specified type
			$typeHandler = $this->typeManager->getTypeHandler($type);
				
			if ($typeHandler === false)
				throw new \RuntimeException("No type handler found for type '$type'");
				
			if (is_array($value))
				return $this->castArray($value, $typeHandler, '_');
			
			//check if returned value is null
			$value = $typeHandler->castParameter($value);
			if (is_null($value))
				return 'NULL';
		}
	
		//get parameter expression
		$value = $typeHandler->setParameter($value);
	
		//check null value
		if (is_null($value))
			return 'NULL';
		//cast to string
		if (!is_string($value))
			$value = strval($value);
		return $value;
	}
20226
public static function __static()
	{
		// NameValue::$nameStartChar = "[:_\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nl}]";
		NameValue::$nameStartChar = SchemaTypes::$nameStartChar;
		NameValue::$nameChar = SchemaTypes::$nameChar;
		NameValue::$name = SchemaTypes::$name;
		NameValue::$ncName = SchemaTypes::$ncName;
	}
545263
static function ByValue($value)
    {
        $calledClass = get_called_class();
        $allowed = self::AllowedClassValues($calledClass);
        if (!in_array($value, $allowed, true))
            throw new \InvalidArgumentException('Value ' . $value . ' not allowed for enum ' . $calledClass);
        
        return new $calledClass($value);
    }
708470
public function type($value)
    {
        if ($value instanceof SuperTableBlockType) {
            $this->typeId = $value->id;
        } else if ($value !== null) {
            $this->typeId = (new Query())
                ->select(['id'])
                ->from(['{{%supertableblocktypes}}'])
                ->where(Db::parseParam('id', $value))
                ->column();
        } else {
            $this->typeId = null;
        }

        return $this;
    }
520189
public static function __static()
	{
		Types::$NullType					= Type::FromNameAndTypeCode( Type::null_, TypeCode::Null_ );
		Types::$ArrayType					= Type::FromNameAndTypeCode( Type::assocArray, TypeCode::AssocArray );
		Types::$BoolType					= Type::FromNameAndTypeCode( Type::bool, TypeCode::Boolean );
		Types::$BooleanType					= Types::$BoolType;
		Types::$ByteType					= Type::FromNameAndTypeCode( Type::byte, TypeCode::Int32 );
		Types::$CharType					= Type::FromNameAndTypeCode( Type::char, TypeCode::String );
		Types::$DateTimeIntervalType		= Type::FromNameAndTypeCode( Type::dateTimeInterval, TypeCode::DateTimeInterval );
		Types::$DateTimeValueType			= Type::FromNameAndTypeCode( DateTimeValue::$CLASSNAME, TypeCode::DateTime );
		Types::$DateValueType				= Type::FromNameAndTypeCode( DateValue::$CLASSNAME, TypeCode::DateTime );
		Types::$DayTimeDurationValueType	= Type::FromNameAndTypeCode( DayTimeDurationValue::$CLASSNAME, TypeCode::DateTimeInterval );
		// Types::$DecimalType				= Type::FromNameAndTypeCode( Type::decimal, TypeCode::Float );
		Types::$DecimalType					= Type::FromNameAndTypeCode( DecimalValue::$CLASSNAME, TypeCode::Decimal );
		Types::$DurationValueType			= Type::FromNameAndTypeCode( DurationValue::$CLASSNAME, TypeCode::DateTimeInterval );
		Types::$FloatType					= Type::FromNameAndTypeCode( Type::float, TypeCode::Float );
		Types::$DoubleType					= Type::FromNameAndTypeCode( Type::double, TypeCode::Float );
		// Types::$DoubleType					= Types::$FloatType;
		Types::$Int16Type					= Type::FromNameAndTypeCode( Type::int16, TypeCode::Int32 );
		Types::$Int32Type					= Type::FromNameAndTypeCode( Type::int32, TypeCode::Int32 );
		Types::$Int64Type					= Type::FromNameAndTypeCode( Type::int64, TypeCode::Int32 );
		Types::$IntType						= Types::$Int32Type;
		Types::$IntegerType					= Type::FromNameAndTypeCode( Integer::$CLASSNAME, TypeCode::Float );
		// Types::$LongType					= Types::$Int64Type;
		Types::$LongType					= Type::FromNameAndTypeCode( Long::$CLASSNAME, TypeCode::Int64 );
		Types::$ObjectType					= Type::FromNameAndTypeCode( Type::object, TypeCode::Object );
		Types::$SByteType					= Type::FromNameAndTypeCode( Type::sbyte, TypeCode::Int32 );
		Types::$ShortType					= Types::$Int16Type;
		Types::$StringType					= Type::FromNameAndTypeCode( Type::string, TypeCode::String );
		Types::$TimeValueType				= Type::FromNameAndTypeCode( "lyquidity\XPath2\Value\TimeValue", TypeCode::DateTime );
		Types::$UInt16Type					= Type::FromNameAndTypeCode( Type::uint16, TypeCode::Int32 );
		Types::$UInt32Type					= Type::FromNameAndTypeCode( Type::uint32, TypeCode::Int32 );
		Types::$UInt64Type					= Type::FromNameAndTypeCode( Type::uint64, TypeCode::Int32 );

		Types::$AnyUriValueType				= Type::FromNameAndTypeCode( AnyUriValue::$CLASSNAME, TypeCode::Object );
		Types::$Base64BinaryValueType		= Type::FromNameAndTypeCode( Base64BinaryValue::$CLASSNAME, TypeCode::Object );
		Types::$ENTITIESValueType			= Type::FromNameAndTypeCode( ENTITIESValue::$CLASSNAME, TypeCode::Object );
		Types::$GDayValueType				= Type::FromNameAndTypeCode( GDayValue::$CLASSNAME, TypeCode::DateTime );
		Types::$GMonthValueType				= Type::FromNameAndTypeCode( GMonthValue::$CLASSNAME, TypeCode::DateTime );
		Types::$GMonthDayValueType			= Type::FromNameAndTypeCode( GMonthDayValue::$CLASSNAME, TypeCode::DateTime );
		Types::$GYearMonthValueType			= Type::FromNameAndTypeCode( GYearMonthValue::$CLASSNAME, TypeCode::DateTime );
		Types::$GYearValueType				= Type::FromNameAndTypeCode( GYearValue::$CLASSNAME, TypeCode::DateTime );
		Types::$HexBinaryValueType			= Type::FromNameAndTypeCode( HexBinaryValue::$CLASSNAME, TypeCode::Object );
		Types::$IDREFSValueType				= Type::FromNameAndTypeCode( IDREFSValue::$CLASSNAME, TypeCode::Object );
		Types::$NMTOKENSValueType			= Type::FromNameAndTypeCode( NMTOKENSValue::$CLASSNAME, TypeCode::Object );
		Types::$QNameValueType				= Type::FromNameAndTypeCode( QNameValue::$CLASSNAME, TypeCode::Object );
		Types::$UntypedAtomicType			= Type::FromNameAndTypeCode( UntypedAtomic::$CLASSNAME, TypeCode::Object );
		Types::$YearMonthDurationValueType	= Type::FromNameAndTypeCode( YearMonthDurationValue::$CLASSNAME, TypeCode::DateTimeInterval );
		Types::$UNION						= Type::FromNameAndTypeCode( Type::union, TypeCode::UNION );
	}
1325858
public function toPascalCase(): Utility
    {
        $string = ucfirst($this->toCamelCase()->value());

        return new static($string, $this->encoding);
    }
548799
public static final function values() {
			if (!static::isDone())
				static::autoload();

			$key = get_called_class();

			if (array_key_exists($key, self::$types))
				return self::$types[$key];

			return array();
		}
1118551
protected function reduceScalarTypes(): self
    {
        if (count($this->types) < 2 || !is_scalar($this->value)) {
            return $this;
        }

        $preferredTypes = ['string', 'integer', 'float', 'boolean', DateTime::class];
        $types = array_uintersect($this->types, $preferredTypes, 'strcasecmp');

        if (count($types) < 2) {
            return empty($types) ? $this : $this->setTypes($types);
        }

        $remove = [];

        if (count(array_uintersect($types, [DateTime::class], 'strcasecmp')) > 0) {
            $remove[] = 'string';
        }

        if (in_array('integer', $types)) {
            $remove[] = DateTime::class;
        }

        if (in_array('boolean', $types) && is_bool($this->value)) {
            $remove[] = 'integer';
            $remove[] = 'float';
            $remove[] = 'string';
        } elseif (in_array('integer', $types) || in_array('float', $types)) {
            $remove[] = 'boolean';
            $remove[] = 'string';
        } elseif (in_array('boolean', $types) && in_array('string', $types)) {
            $remove[] = 'boolean';
        }

        if (in_array('integer', $types) && in_array('float', $types)) {
            $remove[] = is_float($this->value) || (is_string($this->value) && strpos($this->value, '.') !== false) ? 'integer' : 'float';
        }

        return $this->setTypes(array_udiff($types, $remove, 'strcasecmp'));
    }
569165
private function _getMapValueHandler() {
        return function($key, $value) {
            foreach($this->customArgumentHandler as $name => $callable) {
                if(is_callable($callable)) {
                    $value = $callable($key, $value);
                } else
                    trigger_error("Custom argument handler $name is not callable", E_USER_WARNING);
            }
            return $value;
        };
    }
369598
public function detectTypes(){
		$table = $this->getTable();
		$this->performed || $this->run();

		// Try fetch from cache
		$types = (array) $this->connection->getCache()->fetch($table . '_detectedTypes');

		if(empty($types)){
			try{
				$types = $this->connection->getDriver()->getColumnTypes($this->resultSet, $table);
			} catch(NeevoException $e){
				return $this;
			}
		}

		foreach((array) $types as $col => $type){
			$this->columnTypes[$col] = $this->resolveType($type);
		}

		$this->connection->getCache()->store($table . '_detectedTypes', $this->columnTypes);
		return $this;
	}
925449
private function processDeserializeTypeHandler(Type\Handler $handler, $object, $value): self
    {
        $handler->deserializer()->deserialize($object, $value);

        return $this;
    }
210188
public function type(): string
    {
        if (is_string($this->value)) {

            return $this->string($this->value);

        }

        if (is_array($this->value)) {

            return $this->array($this->value);

        }

        if (is_object($this->value)) {

            return $this->object($this->value);

        }

        return gettype($this->value);
    }