static function __static() { self::$VAR = new self('var', null); self::$VOID = new self('void', null); self::$ARRAY = eval('namespace lang; class NativeArrayType extends Type { static function __static() { } public function isInstance($value) { return is_array($value); } public function newInstance($value= null) { return null === $value ? [] : (array)$value; } public function cast($value) { return null === $value ? null : (array)$value; } public function isAssignableFrom($type) { return $type instanceof self || $type instanceof ArrayType || $type instanceof MapType; } } return new NativeArrayType("array", []);'); self::$CALLABLE = eval('namespace lang; class NativeCallableType extends Type { static function __static() { } public function isInstance($value) { return is_callable($value); } public function newInstance($value= null) { if (is_callable($value)) return $value; throw new IllegalAccessException("Cannot instantiate callable type from ".\\xp::typeOf($value)); } public function cast($value) { if (null === $value || is_callable($value)) return $value; throw new ClassCastException("Cannot cast ".\\xp::typeOf($value)." to the callable type"); } public function isAssignableFrom($type) { return $type instanceof self || $type instanceof FunctionType; } } return new NativeCallableType("callable", null);'); }
static function __static() { self::$VAR = new self('var', null); self::$VOID = new self('void', null); self::$ARRAY = eval('namespace lang; class NativeArrayType extends Type { static function __static() { } public function isInstance($value): bool { return is_array($value); } public function newInstance($value= null) { return null === $value ? [] : (array)$value; } public function cast($value) { return null === $value ? null : (array)$value; } public function isAssignableFrom($type): bool { return $type instanceof self || $type instanceof ArrayType || $type instanceof MapType; } } return new NativeArrayType("array", []);'); self::$OBJECT = eval('namespace lang; class NativeObjectType extends Type { static function __static() { } public function isInstance($value): bool { return is_object($value) && !$value instanceof \\Closure; } public function newInstance($value= null) { if (is_object($value) && !$value instanceof \\Closure) return clone $value; throw new IllegalAccessException("Cannot instantiate ".\\xp::typeOf($value)); } public function cast($value) { if (null === $value || is_object($value) && !$value instanceof \\Closure) return $value; throw new ClassCastException("Cannot cast ".\\xp::typeOf($value)." to the object type"); } public function isAssignableFrom($type): bool { return $type instanceof self || $type instanceof XPClass; } } return new NativeObjectType("object", null);'); self::$CALLABLE = eval('namespace lang; class NativeCallableType extends Type { static function __static() { } public function isInstance($value): bool { return is_callable($value); } public function newInstance($value= null) { if (is_callable($value)) return $value; throw new IllegalAccessException("Cannot instantiate callable type from ".\\xp::typeOf($value)); } public function cast($value) { if (null === $value || is_callable($value)) return $value; throw new ClassCastException("Cannot cast ".\\xp::typeOf($value)." to the callable type"); } public function isAssignableFrom($type): bool { return $type instanceof self || $type instanceof FunctionType; } } return new NativeCallableType("callable", null);'); self::$ITERABLE = eval('namespace lang; class NativeIterableType extends Type { static function __static() { } public function isInstance($value): bool { return $value instanceof \\Traversable || is_array($value); } public function newInstance($value= null) { if ($value instanceof \\Traversable || is_array($value)) return $value; throw new IllegalAccessException("Cannot instantiate iterable type from ".\\xp::typeOf($value)); } public function cast($value) { if (null === $value || $value instanceof \\Traversable || is_array($value)) return $value; throw new ClassCastException("Cannot cast ".\\xp::typeOf($value)." to the iterable type"); } public function isAssignableFrom($type): bool { return $type instanceof self; } } return new NativeIterableType("iterable", null);'); }