|
@@ -28,7 +28,7 @@ import haxe.iterators.ArrayKeyValueIterator;
|
|
|
using php.Global;
|
|
|
|
|
|
@:coreApi
|
|
|
-final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate<T> implements JsonSerializable<NativeIndexedArray<T>> {
|
|
|
+final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate<T> implements Countable implements JsonSerializable<NativeIndexedArray<T>> {
|
|
|
public var length(default, null):Int;
|
|
|
|
|
|
var arr:NativeIndexedArray<T>;
|
|
@@ -206,12 +206,12 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
|
|
|
length = len;
|
|
|
}
|
|
|
|
|
|
- @:noCompletion
|
|
|
+ @:noCompletion @:keep
|
|
|
function offsetExists(offset:Int):Bool {
|
|
|
return offset < length;
|
|
|
}
|
|
|
|
|
|
- @:noCompletion
|
|
|
+ @:noCompletion @:keep
|
|
|
function offsetGet(offset:Int):Ref<T> {
|
|
|
try {
|
|
|
return arr[offset];
|
|
@@ -220,7 +220,7 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @:noCompletion
|
|
|
+ @:noCompletion @:keep
|
|
|
function offsetSet(offset:Int, value:T):Void {
|
|
|
if (length <= offset) {
|
|
|
for(i in length...offset + 1) {
|
|
@@ -232,7 +232,7 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
|
|
|
Syntax.code("return {0}", value);
|
|
|
}
|
|
|
|
|
|
- @:noCompletion
|
|
|
+ @:noCompletion @:keep
|
|
|
function offsetUnset(offset:Int):Void {
|
|
|
if (offset >= 0 && offset < length) {
|
|
|
Global.array_splice(arr, offset, 1);
|
|
@@ -245,6 +245,12 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
|
|
|
return new NativeArrayIterator(arr);
|
|
|
}
|
|
|
|
|
|
+ @:noCompletion @:keep
|
|
|
+ @:native('count') //to not interfere with `Lambda.count`
|
|
|
+ private function _hx_count():Int {
|
|
|
+ return length;
|
|
|
+ }
|
|
|
+
|
|
|
@:noCompletion @:keep
|
|
|
function jsonSerialize():NativeIndexedArray<T> {
|
|
|
return arr;
|
|
@@ -259,7 +265,8 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- This one is required for `Array`
|
|
|
+ Following interfaces are required to make `Array` mimic native arrays for usage
|
|
|
+ from a 3rd party PHP code.
|
|
|
**/
|
|
|
@:native('ArrayAccess')
|
|
|
private extern interface ArrayAccess<K, V> {
|
|
@@ -267,4 +274,20 @@ private extern interface ArrayAccess<K, V> {
|
|
|
private function offsetGet(offset:K):V;
|
|
|
private function offsetSet(offset:K, value:V):Void;
|
|
|
private function offsetUnset(offset:K):Void;
|
|
|
+}
|
|
|
+
|
|
|
+@:native('JsonSerializable')
|
|
|
+private extern interface JsonSerializable<T> {
|
|
|
+ private function jsonSerialize():T;
|
|
|
+}
|
|
|
+
|
|
|
+@:native('IteratorAggregate')
|
|
|
+private extern interface IteratorAggregate<T> extends Traversable {
|
|
|
+ private function getIterator():Traversable;
|
|
|
+}
|
|
|
+
|
|
|
+@:native('Countable')
|
|
|
+private extern interface Countable {
|
|
|
+ @:native('count') //to not interfere with `Lambda.count`
|
|
|
+ private function _hx_count():Int;
|
|
|
}
|