maj ordre func

This commit is contained in:
Jephté Clain 2025-04-10 15:04:37 +04:00
parent bab9ba81fe
commit 5c6d55ed46
4 changed files with 19 additions and 17 deletions

View File

@ -276,7 +276,7 @@ EOT;
$pvalues = $this->unserialize($channel, $prow);
}
$updates = $initFunc->prependArgs(null, [$item, $values, $pvalues])->invoke();
$updates = $initFunc->prependArgs([$item, $values, $pvalues])->invoke();
if ($updates === [false]) return 0;
if (is_array($updates) && $updates) {
if ($insert === null) $insert = false;
@ -289,7 +289,7 @@ EOT;
if ($func !== null) {
$updates = func::with($func)
->prependArgs(null, [$item, $values, $pvalues])
->prependArgs([$item, $values, $pvalues])
->bind($channel, true)
->invoke();
if ($updates === [false]) return 0;

View File

@ -81,7 +81,7 @@ abstract class AbstractBuilder extends TempStream implements IBuilder {
protected function cookRow(?array $row): ?array {
if ($this->cookFunc !== null) {
$row = $this->cookFunc->prependArgs(null, [$row])->invoke();
$row = $this->cookFunc->prependArgs([$row])->invoke();
}
if ($row !== null) {
foreach ($row as &$col) {

View File

@ -597,14 +597,14 @@ class func {
return $this;
}
function prependArgs(?int $stripCount=null, ?array $args=null): self {
function prependArgs(?array $args, ?int $stripCount=null): self {
if ($stripCount !== null || $args !== null) {
array_splice($this->prefixArgs, 0, $stripCount ?? 0, $args);
}
return $this;
}
function appendArgs(?int $stripCount=null, ?array $args=null): self {
function appendArgs(?array $args, ?int $stripCount=null): self {
if ($stripCount !== null || $args !== null) {
$stripCount ??= 0;
if ($stripCount > 0) array_splice($this->prefixArgs, -$stripCount);

View File

@ -1103,8 +1103,10 @@ namespace nulib\php {
function testRebind() {
$func = func::with([C1::class, "tmethod"]);
// objets du même type
self::assertSame(11, $func->bind(new C1(0))->invoke());
self::assertSame(12, $func->bind(new C1(1))->invoke());
// objets de type différent
self::assertException(ValueException::class, function() use ($func) {
$func->bind(new C0())->invoke();
});
@ -1116,19 +1118,19 @@ namespace nulib\php {
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->replaceArgs(["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z", "a", "b", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(null, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z", "a", "b", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(0, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z", "b", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(1, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(2, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->prependArgs(3, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->prependArgs(4, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z", "a", "b", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z", "a", "b", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(["x", "y", "z"], 0)->invoke());
self::assertSame(["x", "y", "z", "b", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(["x", "y", "z"], 1)->invoke());
self::assertSame(["x", "y", "z", "c"], func::with($closure, ["a", "b", "c"])->prependArgs(["x", "y", "z"], 2)->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->prependArgs(["x", "y", "z"], 3)->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->prependArgs(["x", "y", "z"], 4)->invoke());
self::assertSame(["a", "b", "c", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(null, ["x", "y", "z"])->invoke());
self::assertSame(["a", "b", "c", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(0, ["x", "y", "z"])->invoke());
self::assertSame(["a", "b", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(1, ["x", "y", "z"])->invoke());
self::assertSame(["a", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(2, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(3, ["x", "y", "z"])->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(4, ["x", "y", "z"])->invoke());
self::assertSame(["a", "b", "c", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(["x", "y", "z"])->invoke());
self::assertSame(["a", "b", "c", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(["x", "y", "z"], 0)->invoke());
self::assertSame(["a", "b", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(["x", "y", "z"], 1)->invoke());
self::assertSame(["a", "x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(["x", "y", "z"], 2)->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(["x", "y", "z"], 3)->invoke());
self::assertSame(["x", "y", "z"], func::with($closure, ["a", "b", "c"])->appendArgs(["x", "y", "z"], 4)->invoke());
}
}
}