mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-06-02 15:34:37 +00:00
XOMW: More XomwHooks implementation [#632]
This commit is contained in:
parent
0c3cb1ba3d
commit
a6b128422e
@ -247,4 +247,29 @@ public class XophpArray_ {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// REF.PHP: https://www.php.net/manual/en/function.array-shift.php
|
||||||
|
// Returns the shifted value, or NULL if array is empty or is not an array.
|
||||||
|
public static Object array_shift(XophpArray array) {
|
||||||
|
if (array == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int len = array.Len();
|
||||||
|
if (len == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
XophpArrayItm[] itms = array.To_ary();
|
||||||
|
array.Clear();
|
||||||
|
int idx = 0;
|
||||||
|
for (int i = 1; i < len; i++) {
|
||||||
|
XophpArrayItm itm = itms[i];
|
||||||
|
if (itm.Key_is_int()) {
|
||||||
|
array.Add(idx++, itm.Val());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
array.Add(itm.Key(), itm.Val());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return itms[0].Val();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,9 +19,8 @@ package gplx.xowa.mediawiki.includes;
|
|||||||
import gplx.xowa.mediawiki.*;
|
import gplx.xowa.mediawiki.*;
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
* $wgHooks
|
* class XophpClosure: https://www.php.net/manual/en/class.closure.php
|
||||||
* array_shift
|
* array_filter: https://www.php.net/manual/en/function.array-filter.php
|
||||||
* Closure?
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,9 +77,7 @@ public class XomwHooks {
|
|||||||
* @return bool True if the hook has a function registered to it
|
* @return bool True if the hook has a function registered to it
|
||||||
*/
|
*/
|
||||||
public static boolean isRegistered(String name) {
|
public static boolean isRegistered(String name) {
|
||||||
// global $wgHooks;
|
return !XophpObject_.empty_obj(XomwDefaultSettings.wgHooks.Get_by(name)) || !XophpObject_.empty_obj(handlers.Get_by(name));
|
||||||
// return !XophpArray_.empty($wgHooks[$name]) || !XophpArray_.empty(handlers[$name]);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,17 +90,14 @@ public class XomwHooks {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static XophpArray getHandlers(String name) {
|
public static XophpArray getHandlers(String name) {
|
||||||
// global $wgHooks;
|
|
||||||
|
|
||||||
if (!isRegistered(name)) {
|
if (!isRegistered(name)) {
|
||||||
return XophpArray.New();
|
return XophpArray.New();
|
||||||
// } else if (!XophpArray_.isset(handlers, name)) {
|
} else if (!XophpArray_.isset(handlers, name)) {
|
||||||
// return $wgHooks[name];
|
return XomwDefaultSettings.wgHooks.Get_by_ary(name);
|
||||||
// } else if (!isset($wgHooks[name])) {
|
} else if (!XophpArray_.isset(XomwDefaultSettings.wgHooks, name)) {
|
||||||
// return handlers[name];
|
return handlers.Get_by_ary(name);
|
||||||
} else {
|
} else {
|
||||||
// return XophpArray_.array_merge(handlers.Get_by_ary(name), $wgHooks[name]);
|
return XophpArray_.array_merge(handlers.Get_by_ary(name), XomwDefaultSettings.wgHooks.Get_by_ary(name));
|
||||||
return XophpArray_.array_merge(handlers.Get_by_ary(name));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,10 +13,15 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
package gplx.xowa.mediawiki;
|
||||||
import org.junit.*; import gplx.core.tests.*;
|
|
||||||
public class XophpArray__tst { // REF:https://www.php.net/manual/en/function.array-merge.php
|
import gplx.Bool_;
|
||||||
|
import gplx.core.tests.Gftest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class XophpArray__tst {
|
||||||
private final XophpArray__fxt fxt = new XophpArray__fxt();
|
private final XophpArray__fxt fxt = new XophpArray__fxt();
|
||||||
|
// REF.PHP:https://www.php.net/manual/en/function.array-merge.php
|
||||||
@Test public void array_merge__basic() {
|
@Test public void array_merge__basic() {
|
||||||
XophpArray ary1 = fxt.Make().Add("key1", "val1").Add("a");
|
XophpArray ary1 = fxt.Make().Add("key1", "val1").Add("a");
|
||||||
XophpArray ary2 = fxt.Make().Add("key2", "val2").Add("b");
|
XophpArray ary2 = fxt.Make().Add("key2", "val2").Add("b");
|
||||||
@ -276,6 +281,58 @@ public class XophpArray__tst { // REF:https://www.php.net/manual/en/function.arr
|
|||||||
Gftest.Eq__bool(Bool_.N, XophpArray_.in_array(XophpArray.New('f', 'i'), array));
|
Gftest.Eq__bool(Bool_.N, XophpArray_.in_array(XophpArray.New('f', 'i'), array));
|
||||||
Gftest.Eq__bool(Bool_.Y, XophpArray_.in_array('o', array));
|
Gftest.Eq__bool(Bool_.Y, XophpArray_.in_array('o', array));
|
||||||
}
|
}
|
||||||
|
@Test public void array_shift() {
|
||||||
|
XophpArray array;
|
||||||
|
String shifted;
|
||||||
|
|
||||||
|
// key is int
|
||||||
|
array = XophpArray.New("a", "b");
|
||||||
|
shifted = (String)XophpArray_.array_shift(array);
|
||||||
|
|
||||||
|
Gftest.Eq__str("a", shifted);
|
||||||
|
fxt.Test__eq
|
||||||
|
( XophpArray.New().Add(0, "b")
|
||||||
|
, array
|
||||||
|
);
|
||||||
|
|
||||||
|
// key is str and int
|
||||||
|
array = XophpArray.New().Add("a", "a").Add(2, "b").Add(5, "c");
|
||||||
|
shifted = (String)XophpArray_.array_shift(array);
|
||||||
|
|
||||||
|
Gftest.Eq__str("a", shifted);
|
||||||
|
fxt.Test__eq
|
||||||
|
( XophpArray.New().Add(0, "b").Add(1, "c")
|
||||||
|
, array
|
||||||
|
);
|
||||||
|
|
||||||
|
// empty
|
||||||
|
array = XophpArray.New();
|
||||||
|
shifted = (String)XophpArray_.array_shift(array);
|
||||||
|
|
||||||
|
Gftest.Eq__bool_y(shifted == null);
|
||||||
|
fxt.Test__eq
|
||||||
|
( XophpArray.New()
|
||||||
|
, array
|
||||||
|
);
|
||||||
|
|
||||||
|
// null
|
||||||
|
array = null;
|
||||||
|
shifted = (String)XophpArray_.array_shift(array);
|
||||||
|
|
||||||
|
Gftest.Eq__bool_y(shifted == null);
|
||||||
|
Gftest.Eq__bool_y(array == null);
|
||||||
|
|
||||||
|
// PHP samples
|
||||||
|
// Example #1
|
||||||
|
array = XophpArray.New("orange", "banana", "apple", "strawberry");
|
||||||
|
shifted = (String)XophpArray_.array_shift(array);
|
||||||
|
|
||||||
|
Gftest.Eq__str("orange", shifted);
|
||||||
|
fxt.Test__eq
|
||||||
|
( XophpArray.New().Add(0, "banana").Add(1, "apple").Add(2, "strawberry")
|
||||||
|
, array
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class XophpArray__fxt {
|
class XophpArray__fxt {
|
||||||
public XophpArray Make() {return new XophpArray();}
|
public XophpArray Make() {return new XophpArray();}
|
Loading…
Reference in New Issue
Block a user