diff --git a/php/src/db/CapacitorStorage.php b/php/src/db/CapacitorStorage.php index c5cf345..1f6c759 100644 --- a/php/src/db/CapacitorStorage.php +++ b/php/src/db/CapacitorStorage.php @@ -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; diff --git a/php/src/file/tab/AbstractBuilder.php b/php/src/file/tab/AbstractBuilder.php index 23ab27a..2affcc8 100644 --- a/php/src/file/tab/AbstractBuilder.php +++ b/php/src/file/tab/AbstractBuilder.php @@ -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) { diff --git a/php/src/php/func.php b/php/src/php/func.php index d81b416..79e9c78 100644 --- a/php/src/php/func.php +++ b/php/src/php/func.php @@ -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); diff --git a/php/tests/php/funcTest.php b/php/tests/php/funcTest.php index 0f5200b..45a0581 100644 --- a/php/tests/php/funcTest.php +++ b/php/tests/php/funcTest.php @@ -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()); } } }