1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172:
<?php
namespace esperecyan\webidl\lib;
class Type
{
use Utility;
public static function to($type, $value, $pseudoTypes = null)
{
switch ($type) {
case 'any':
$returnValue = $value;
break;
case 'boolean':
$returnValue = BooleanType::toBoolean($value);
break;
case '[EnforceRange] byte':
$returnValue = IntegerType::toByte($value, '[EnforceRange]');
break;
case '[Clamp] byte':
$returnValue = IntegerType::toByte($value, '[Clamp]');
break;
case 'byte':
$returnValue = IntegerType::toByte($value);
break;
case '[EnforceRange] octet':
$returnValue = IntegerType::toOctet($value, '[EnforceRange]');
break;
case '[Clamp] octet':
$returnValue = IntegerType::toOctet($value, '[Clamp]');
break;
case 'octet':
$returnValue = IntegerType::toOctet($value);
break;
case '[EnforceRange] short':
$returnValue = IntegerType::toShort($value, '[EnforceRange]');
break;
case '[Clamp] short':
$returnValue = IntegerType::toShort($value, '[Clamp]');
break;
case 'short':
$returnValue = IntegerType::toShort($value);
break;
case '[EnforceRange] unsigned short':
$returnValue = IntegerType::toUnsignedShort($value, '[EnforceRange]');
break;
case '[Clamp] unsigned short':
$returnValue = IntegerType::toUnsignedShort($value, '[Clamp]');
break;
case 'unsigned short':
$returnValue = IntegerType::toUnsignedShort($value);
break;
case '[EnforceRange] long':
$returnValue = IntegerType::toLong($value, '[EnforceRange]');
break;
case '[Clamp] long':
$returnValue = IntegerType::toLong($value, '[Clamp]');
break;
case 'long':
$returnValue = IntegerType::toLong($value);
break;
case '[EnforceRange] unsigned long':
$returnValue = IntegerType::toUnsignedLong($value, '[EnforceRange]');
break;
case '[Clamp] unsigned long':
$returnValue = IntegerType::toUnsignedLong($value, '[Clamp]');
break;
case 'unsigned long':
$returnValue = IntegerType::toUnsignedLong($value);
break;
case '[EnforceRange] long long':
$returnValue = IntegerType::toLongLong($value, '[EnforceRange]');
break;
case '[Clamp] long long':
$returnValue = IntegerType::toLongLong($value, '[Clamp]');
break;
case 'long long':
$returnValue = IntegerType::toLongLong($value);
break;
case '[EnforceRange] unsigned long long':
$returnValue = IntegerType::toUnsignedLongLong($value, '[EnforceRange]');
break;
case '[Clamp] unsigned long long':
$returnValue = IntegerType::toUnsignedLongLong($value, '[Clamp]');
break;
case 'unsigned long long':
$returnValue = IntegerType::toUnsignedLongLong($value);
break;
case 'float':
$returnValue = FloatType::toFloat($value);
break;
case 'unrestricted float':
$returnValue = FloatType::toUnrestrictedFloat($value);
break;
case 'double':
$returnValue = FloatType::toDouble($value);
break;
case 'unrestricted double':
$returnValue = FloatType::toUnrestrictedDouble($value);
break;
case 'DOMString':
$returnValue = StringType::toDOMString($value);
break;
case 'ByteString':
$returnValue = StringType::toByteString($value);
break;
case 'USVString':
$returnValue = StringType::toUSVString($value);
break;
case 'object':
$returnValue = ObjectType::toObject($value);
break;
case 'Error':
$returnValue = self
::to('(esperecyan\\webidl\\Error or TypeError or DOMException or \\Error)', $value, $pseudoTypes);
break;
case 'DOMException':
$returnValue = ObjectType::toInterface($value, 'DOMException');
break;
default:
$pattern = '/^(?:(?<nullable>.+)\\?|sequence<(?<sequence>.+)>|record<(?<recordK>(?:DOMString|USVString|ByteString)), (?<recordV>.+)>|(?<union>\\(.+\\))|FrozenArray<(?<FrozenArray>.+)>)$/u';
if (preg_match($pattern, $type, $matches) === 1) {
if (!empty($matches['nullable'])) {
$returnValue = NullableType::toNullable($value, $matches['nullable'], $pseudoTypes);
} elseif (!empty($matches['sequence'])) {
$returnValue = SequenceType::toSequence($value, $matches['sequence'], $pseudoTypes);
} elseif (!empty($matches['recordK'])) {
$returnValue
= DictionaryType::toRecord($value, $matches['recordK'], $matches['recordV'], $pseudoTypes);
} elseif (!empty($matches['union'])) {
$returnValue = UnionType::toUnion($value, $matches['union'], $pseudoTypes);
} elseif (!empty($matches['FrozenArray'])) {
$returnValue = SequenceType::toFrozenArray($value, $matches['FrozenArray'], $pseudoTypes);
}
} elseif (isset($pseudoTypes[$type])) {
$pseudoType = $pseudoTypes[$type];
switch ($pseudoType) {
case 'callback interface':
case 'single operation callback interface':
$returnValue = ObjectType::toCallbackInterface(
$value,
$pseudoType === 'single operation callback interface'
);
break;
case 'callback function':
$returnValue = ObjectType::toCallbackFunction($value);
break;
default:
if (is_string($pseudoType) || isset($pseudoType[0])) {
$returnValue = StringType::toEnumerationValue($value, $type, $pseudoType);
} else {
$returnValue = DictionaryType::toDictionary($value, $type, $pseudoTypes);
}
}
} else {
$returnValue = ObjectType::toInterface($value, $type);
}
}
return $returnValue;
}
}