modifs.mineures sans commentaires
This commit is contained in:
parent
be38f7eb6e
commit
2ce513c174
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpTestFrameworkVersionCache">
|
||||
<tools_cache>
|
||||
<tool tool_name="PHPUnit">
|
||||
<cache>
|
||||
<versions>
|
||||
<info id="Local/vendor/autoload.php" version="9.6.20" />
|
||||
</versions>
|
||||
</cache>
|
||||
</tool>
|
||||
</tools_cache>
|
||||
</component>
|
||||
</project>
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
namespace {
|
||||
function tsimple(): int { return 0; }
|
||||
function tm1($a): array { return [$a]; }
|
||||
function to1($b=9): array { return [$b]; }
|
||||
function tv(...$c): array { return [...$c]; }
|
||||
function tm1o1($a, $b=9): array { return [$a, $b]; }
|
||||
function tm1v($a, ...$c): array { return [$a, ...$c]; }
|
||||
function tm1o1v($a, $b=9, ...$c): array { return [$a, $b, ...$c]; }
|
||||
function to1v($b=9, ...$c): array { return [$b, ...$c]; }
|
||||
}
|
||||
|
||||
namespace nur\sery\wip\php\impl {
|
||||
|
@ -10,6 +17,8 @@ namespace nur\sery\wip\php\impl {
|
|||
|
||||
namespace nur\sery\wip\php {
|
||||
use nulib\tests\TestCase;
|
||||
use nur\sery\wip\php\impl\C0;
|
||||
use nur\sery\wip\php\impl\C1;
|
||||
use nur\sery\wip\php\impl\SC;
|
||||
|
||||
class funcTest extends TestCase {
|
||||
|
@ -913,5 +922,111 @@ namespace nur\sery\wip\php {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testInvokeFunction() {
|
||||
# m1
|
||||
self::assertSame([null], func::call("tm1"));
|
||||
self::assertSame([null], func::call("tm1", null));
|
||||
self::assertSame([null], func::call("tm1", null, null));
|
||||
self::assertSame([null], func::call("tm1", null, null, null));
|
||||
self::assertSame([null], func::call("tm1", null, null, null, null));
|
||||
self::assertSame([1], func::call("tm1", 1));
|
||||
self::assertSame([1], func::call("tm1", 1, 2));
|
||||
self::assertSame([1], func::call("tm1", 1, 2, 3));
|
||||
self::assertSame([1], func::call("tm1", 1, 2, 3, 4));
|
||||
|
||||
# o1
|
||||
self::assertSame([9], func::call("to1"));
|
||||
self::assertSame([null], func::call("to1", null));
|
||||
self::assertSame([null], func::call("to1", null, null));
|
||||
self::assertSame([null], func::call("to1", null, null, null));
|
||||
self::assertSame([null], func::call("to1", null, null, null, null));
|
||||
self::assertSame([1], func::call("to1", 1));
|
||||
self::assertSame([1], func::call("to1", 1, 2));
|
||||
self::assertSame([1], func::call("to1", 1, 2, 3));
|
||||
self::assertSame([1], func::call("to1", 1, 2, 3, 4));
|
||||
|
||||
# v
|
||||
self::assertSame([], func::call("tv"));
|
||||
self::assertSame([null], func::call("tv", null));
|
||||
self::assertSame([null, null], func::call("tv", null, null));
|
||||
self::assertSame([null, null, null], func::call("tv", null, null, null));
|
||||
self::assertSame([null, null, null, null], func::call("tv", null, null, null, null));
|
||||
self::assertSame([1], func::call("tv", 1));
|
||||
self::assertSame([1, 2], func::call("tv", 1, 2));
|
||||
self::assertSame([1, 2, 3], func::call("tv", 1, 2, 3));
|
||||
self::assertSame([1, 2, 3, 4], func::call("tv", 1, 2, 3, 4));
|
||||
|
||||
# m1o1
|
||||
self::assertSame([null, 9], func::call("tm1o1"));
|
||||
self::assertSame([null, 9], func::call("tm1o1", null));
|
||||
self::assertSame([null, null], func::call("tm1o1", null, null));
|
||||
self::assertSame([null, null], func::call("tm1o1", null, null, null));
|
||||
self::assertSame([null, null], func::call("tm1o1", null, null, null, null));
|
||||
self::assertSame([1, 9], func::call("tm1o1", 1));
|
||||
self::assertSame([1, 2], func::call("tm1o1", 1, 2));
|
||||
self::assertSame([1, 2], func::call("tm1o1", 1, 2, 3));
|
||||
self::assertSame([1, 2], func::call("tm1o1", 1, 2, 3, 4));
|
||||
|
||||
# m1v
|
||||
self::assertSame([null], func::call("tm1v"));
|
||||
self::assertSame([null], func::call("tm1v", null));
|
||||
self::assertSame([null, null], func::call("tm1v", null, null));
|
||||
self::assertSame([null, null, null], func::call("tm1v", null, null, null));
|
||||
self::assertSame([null, null, null, null], func::call("tm1v", null, null, null, null));
|
||||
self::assertSame([1], func::call("tm1v", 1));
|
||||
self::assertSame([1, 2], func::call("tm1v", 1, 2));
|
||||
self::assertSame([1, 2, 3], func::call("tm1v", 1, 2, 3));
|
||||
self::assertSame([1, 2, 3, 4], func::call("tm1v", 1, 2, 3, 4));
|
||||
|
||||
# m1o1v
|
||||
self::assertSame([null, 9], func::call("tm1o1v"));
|
||||
self::assertSame([null, 9], func::call("tm1o1v", null));
|
||||
self::assertSame([null, null], func::call("tm1o1v", null, null));
|
||||
self::assertSame([null, null, null], func::call("tm1o1v", null, null, null));
|
||||
self::assertSame([null, null, null, null], func::call("tm1o1v", null, null, null, null));
|
||||
self::assertSame([1, 9], func::call("tm1o1v", 1));
|
||||
self::assertSame([1, 2], func::call("tm1o1v", 1, 2));
|
||||
self::assertSame([1, 2, 3], func::call("tm1o1v", 1, 2, 3));
|
||||
self::assertSame([1, 2, 3, 4], func::call("tm1o1v", 1, 2, 3, 4));
|
||||
|
||||
# o1v
|
||||
self::assertSame([9], func::call("to1v"));
|
||||
self::assertSame([null], func::call("to1v", null));
|
||||
self::assertSame([null, null], func::call("to1v", null, null));
|
||||
self::assertSame([null, null, null], func::call("to1v", null, null, null));
|
||||
self::assertSame([null, null, null, null], func::call("to1v", null, null, null, null));
|
||||
self::assertSame([1], func::call("to1v", 1));
|
||||
self::assertSame([1, 2], func::call("to1v", 1, 2));
|
||||
self::assertSame([1, 2, 3], func::call("to1v", 1, 2, 3));
|
||||
self::assertSame([1, 2, 3, 4], func::call("to1v", 1, 2, 3, 4));
|
||||
}
|
||||
|
||||
function testInvokeClass() {
|
||||
$func = func::with(SC::class);
|
||||
self::assertInstanceOf(SC::class, $func->invoke());
|
||||
self::assertInstanceOf(SC::class, $func->invoke([]));
|
||||
self::assertInstanceOf(SC::class, $func->invoke([1]));
|
||||
self::assertInstanceOf(SC::class, $func->invoke([1, 2]));
|
||||
self::assertInstanceOf(SC::class, $func->invoke([1, 2, 3]));
|
||||
|
||||
$func = func::with(C0::class);
|
||||
self::assertInstanceOf(C0::class, $func->invoke());
|
||||
self::assertInstanceOf(C0::class, $func->invoke([]));
|
||||
self::assertInstanceOf(C0::class, $func->invoke([1]));
|
||||
self::assertInstanceOf(C0::class, $func->invoke([1, 2]));
|
||||
self::assertInstanceOf(C0::class, $func->invoke([1, 2, 3]));
|
||||
|
||||
$func = func::with(C1::class);
|
||||
/** @var C1 $i1 */
|
||||
$i1 = $func->invoke();
|
||||
self::assertInstanceOf(C1::class, $i1); self::assertSame(null, $i1->first);
|
||||
$i1 = $func->invoke([]);
|
||||
self::assertInstanceOf(C1::class, $i1); self::assertSame(null, $i1->first);
|
||||
$i1 = $func->invoke([1]);
|
||||
self::assertInstanceOf(C1::class, $i1); self::assertSame(1, $i1->first);
|
||||
$i1 = $func->invoke([1, 2]);
|
||||
self::assertInstanceOf(C1::class, $i1); self::assertSame(1, $i1->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace nur\sery\wip\php\impl;
|
||||
|
||||
class CC {
|
||||
class C0 {
|
||||
function __construct() {
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
namespace nur\sery\wip\php\impl;
|
||||
|
||||
class C1 {
|
||||
function __construct($first) {
|
||||
$this->first = $first;
|
||||
}
|
||||
|
||||
public $first;
|
||||
|
||||
static function tstatic(): int {
|
||||
return 10;
|
||||
}
|
||||
|
||||
function tmethod(): int {
|
||||
return 11;
|
||||
}
|
||||
}
|
|
@ -67,15 +67,17 @@ class func {
|
|||
}
|
||||
if ($func instanceof ReflectionFunction) return true;
|
||||
if (is_string($func)) {
|
||||
$func = [false, $func];
|
||||
$c = false;
|
||||
$f = $func;
|
||||
} elseif (is_array($func)) {
|
||||
if (!array_key_exists(0, $func)) return false;
|
||||
$c = $func[0];
|
||||
if (!array_key_exists(1, $func)) return false;
|
||||
$f = $func[1];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if ($func[0] !== false) return false;
|
||||
$f = $func[1];
|
||||
if ($c !== false) return false;
|
||||
if (!is_string($f)) return false;
|
||||
if (self::_is_invalid($f)) return false;
|
||||
if (self::_parse_static($f)) return false;
|
||||
|
@ -91,6 +93,7 @@ class func {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
$func = [false, $f];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -123,25 +126,28 @@ class func {
|
|||
}
|
||||
if ($func instanceof ReflectionClass) return true;
|
||||
if (is_string($func)) {
|
||||
$func = [$func, false];
|
||||
$c = $func;
|
||||
$f = false;
|
||||
} elseif (is_array($func)) {
|
||||
if (!array_key_exists(0, $func)) return false;
|
||||
$c = $func[0];
|
||||
if (!array_key_exists(1, $func)) return false;
|
||||
$f = $func[1];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
$c = $func[0];
|
||||
if (!is_string($c)) return false;
|
||||
if (self::_is_invalid($c)) return false;
|
||||
if (self::_parse_static($f)) return false;
|
||||
if (self::_parse_method($f)) return false;
|
||||
if ($func[1] !== false) return false;
|
||||
if (self::_parse_static($c)) return false;
|
||||
if (self::_parse_method($c)) return false;
|
||||
if ($f !== false) return false;
|
||||
if ($strict) {
|
||||
if (!class_exists($c)) {
|
||||
$reason = "$msg: class not found";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$func = [$c, false];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -504,7 +510,7 @@ class func {
|
|||
|
||||
#############################################################################
|
||||
|
||||
const TYPE_CLOSURE = 0, TYPE_SIMPLE = 1, TYPE_STATIC = 2, TYPE_METHOD = 3, TYPE_CLASS = 4;
|
||||
const TYPE_CLOSURE = 0, TYPE_SIMPLE = 1, TYPE_CLASS = 2, TYPE_STATIC = 3, TYPE_METHOD = 4;
|
||||
|
||||
function __construct($func) {
|
||||
$object = null;
|
||||
|
@ -516,12 +522,12 @@ class func {
|
|||
} elseif ($func instanceof ReflectionFunction) {
|
||||
$type = self::TYPE_SIMPLE;
|
||||
$reflection = $func;
|
||||
} elseif ($func instanceof ReflectionMethod) {
|
||||
$type = self::TYPE_STATIC;
|
||||
$reflection = $func;
|
||||
} elseif ($func instanceof ReflectionClass) {
|
||||
$type = self::TYPE_CLASS;
|
||||
$reflection = $func;
|
||||
} elseif ($func instanceof ReflectionMethod) {
|
||||
$type = self::TYPE_STATIC;
|
||||
$reflection = $func;
|
||||
} elseif (is_array($func)) {
|
||||
if (count($func) > 2) {
|
||||
$prefixArgs = array_slice($func, 2);
|
||||
|
|
Loading…
Reference in New Issue