This commit is contained in:
Dante
2026-05-21 23:40:20 -07:00
parent 3e2915dff7
commit 877a69d844
5737 changed files with 29796 additions and 1589684 deletions

View File

@ -215,11 +215,14 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
@:noCompletion @:keep
@:php.attribute('\\ReturnTypeWillChange')
function offsetGet(offset:Int):Ref<T> {
try {
return arr[offset];
} catch (e:Dynamic) {
return null;
if(offset < 0 || offset >= length) {
//This var is required in generated php code
//because only variables can be returned by reference.
final result = null;
Syntax.keepVar(result);
return result;
}
return arr[offset];
}
@:noCompletion @:keep

View File

@ -52,22 +52,27 @@ import php.Syntax;
}
public static function parseInt(x:String):Null<Int> {
if (Global.is_numeric(x)) {
return Global.intval(x, 10);
} else {
x = Global.ltrim(x);
var firstCharIndex = (x.charAt(0) == '-' ? 1 : 0);
var firstCharCode = x.charCodeAt(firstCharIndex);
if (!isDigitCode(firstCharCode)) {
x = Global.ltrim(x, " \t\n\x0b\x0c\r");
final digitsOnly = Global.ltrim(x, "+-");
if (Global.str_starts_with(digitsOnly, '0x') || Global.str_starts_with(digitsOnly, '0X')) {
final val = Global.intval(x, 16); // hexadecimal
// if the value was 0, ensure there is only a maximum of one + or - sign
if (val == 0 && digitsOnly.length + 1 < x.length)
return null;
}
var secondChar = x.charAt(firstCharIndex + 1);
if (secondChar == 'x' || secondChar == 'X') {
return Global.intval(x, 0);
} else {
return Global.intval(x, 10);
}
return val;
}
switch Global.stripos(x, 'e') {
case false:
case ePos: x = Global.substr(x, 0, ePos);
}
final val = Global.intval(x, 10);
// if the value was 0, make sure it wasn't because the string had no valid digits
// last check ensures there is only a maximum of one + or - sign
if (val == 0 && (Global.strspn(digitsOnly, "0123456789", 0, 1) == 0 || digitsOnly.length + 1 < x.length))
return null;
return val;
}
public static function parseFloat(x:String):Float {

View File

@ -29,6 +29,43 @@ import haxe.SysTools;
/** Environment variables set by `Sys.putEnv()` */
static var customEnvVars = new NativeAssocArray<String>();
// we need to keep track of capitalization for windows
static final isWindows = systemName() == "Windows";
static var envCapitalization(get, null):Map<String, String>;
static function get_envCapitalization():Map<String, String> {
if (envCapitalization == null)
return envCapitalization = [for (k => _ in SuperGlobal._SERVER) k.toUpperCase() => k];
return envCapitalization;
}
static inline function addCustom(name:String, value:String):Void {
customEnvVars[name] = value;
if (!isWindows)
return;
final upperCase = name.toUpperCase();
if (envCapitalization.exists(upperCase))
return;
envCapitalization[upperCase] = name;
}
static inline function removeCustom(name:String):Void {
Global.unset(customEnvVars[name]);
if (!isWindows)
return;
envCapitalization.remove(name.toUpperCase());
}
static inline function getCapitalization(name:String):String {
if (!isWindows)
return name;
final existing = envCapitalization[name.toUpperCase()];
if (existing != null)
return existing;
return name;
}
public static inline function print(v:Dynamic):Void {
Global.echo(Std.string(v));
}
@ -50,9 +87,14 @@ import haxe.SysTools;
return value == false ? null : value;
}
public static function putEnv(s:String, v:String):Void {
customEnvVars[s] = '$v'; // in case of `null` it should become `"null"`
Global.putenv('$s=$v');
public static function putEnv(s:String, v:Null<String>):Void {
if (v == null) {
removeCustom(s);
Global.putenv('$s');
} else {
addCustom(s, v);
Global.putenv('$s=$v');
}
}
public static inline function sleep(seconds:Float):Void {
@ -124,7 +166,8 @@ import haxe.SysTools;
public static function environment():Map<String, String> {
var env = SuperGlobal._SERVER;
Syntax.foreach(customEnvVars, function(name:String, value:String) {
env[name] = value;
final actualName = getCapitalization(name);
env[actualName] = value;
});
return php.Lib.hashOfAssociativeArray(env);
}

View File

@ -17,6 +17,11 @@ abstract Rest<T>(NativeRest<T>) {
static public inline function of<T>(array:Array<T>):Rest<T>
return new Rest(@:privateAccess array.arr);
@:noDoc
@:from
static inline function ofNative<T>(array:NativeIndexedArray<T>):Rest<T>
return new Rest(array);
inline function new(a:NativeIndexedArray<T>):Void
this = a;

View File

@ -44,15 +44,18 @@ class Base64 {
public static inline function decode(str:String, complement = true):Bytes {
if (!complement) {
switch (strlen(str) % 3) {
case 1:
str += "==";
switch (strlen(str) % 4) {
case 2:
str += "==";
case 3:
str += "=";
default:
}
}
return Bytes.ofString(base64_decode(str, true));
return switch base64_decode(str, true) {
case false: throw new Exception("Base64.decode : invalid encoded string");
case s: Bytes.ofString(s);
}
}
public static inline function urlEncode(bytes:Bytes, complement = false):String {
@ -62,14 +65,17 @@ class Base64 {
public static inline function urlDecode(str:String, complement = false):Bytes {
if (complement) {
switch (strlen(str) % 3) {
case 1:
str += "==";
switch (strlen(str) % 4) {
case 2:
str += "==";
case 3:
str += "=";
default:
}
}
return Bytes.ofString(base64_decode(str_replace(URL_62_63, NORMAL_62_63, str), true));
return switch base64_decode(str_replace(URL_62_63, NORMAL_62_63, str), true) {
case false: throw new Exception("Base64.urlDecode : invalid encoded string");
case s: Bytes.ofString(s);
}
}
}

View File

@ -79,7 +79,7 @@ import php.NativeIndexedArray;
Global.array_push(parts, '$key => ' + Std.string(value));
});
return '{' + Global.implode(', ', parts) + '}';
return "[" + Global.implode(", ", parts) + "]";
}
public inline function clear():Void {

View File

@ -78,7 +78,7 @@ class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
}
public function toString():String {
var s = "{";
var s = "[";
var it = keys();
for (i in it) {
s += Std.string(i);
@ -87,7 +87,7 @@ class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
if (it.hasNext())
s += ", ";
}
return s + "}";
return s + "]";
}
public inline function clear():Void {

View File

@ -80,7 +80,7 @@ import haxe.Constraints;
Global.array_push(parts, '$key => ' + Std.string(value));
});
return '{' + Global.implode(', ', parts) + '}';
return "[" + Global.implode(", ", parts) + "]";
}
public inline function clear():Void {

View File

@ -28,19 +28,24 @@ private class PhpVectorData<T> {
public var length:Int;
public var data:NativeIndexedArray<T>;
public inline function new(length:Int) {
public inline function new(length:Int, data:NativeIndexedArray<T>) {
this.length = length;
data = new NativeIndexedArray();
this.data = data;
}
}
private typedef VectorData<T> = PhpVectorData<T>;
@:coreApi
abstract Vector<T>(VectorData<T>) {
public var length(get, never):Int;
public inline function new(length:Int) {
this = new VectorData(length);
extern overload public inline function new(length:Int) {
this = new VectorData(length, new NativeIndexedArray());
}
extern overload public inline function new(length:Int, defaultValue:T):Vector<T> {
this = new VectorData(length, Global.array_fill(0, length, defaultValue));
}
@:op([]) public inline function get(index:Int):T {
@ -55,6 +60,9 @@ abstract Vector<T>(VectorData<T>) {
return this.length;
}
public inline function fill(value:T):Void
this.data = Global.array_fill(0, length, value);
public static function blit<T>(src:Vector<T>, srcPos:Int, dest:Vector<T>, destPos:Int, len:Int):Void {
if (src == dest) {
if (srcPos < destPos) {
@ -99,8 +107,7 @@ abstract Vector<T>(VectorData<T>) {
}
static public inline function fromArrayCopy<T>(array:Array<T>):Vector<T> {
var vectorData = new VectorData(array.length);
vectorData.data = @:privateAccess array.arr;
var vectorData = new VectorData(array.length, @:privateAccess array.arr);
return cast vectorData;
}
@ -127,7 +134,7 @@ abstract Vector<T>(VectorData<T>) {
return result;
}
public inline function sort<T>(f:T->T->Int):Void {
public inline function sort(f:T->T->Int):Void {
Global.usort(this.data, f);
}
}