modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-09-11 21:05:15 +04:00
parent d38d429489
commit 3eb5e3d028
3 changed files with 327 additions and 43 deletions

View File

@ -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>

View File

@ -347,25 +347,25 @@ namespace nur\sery\wip\php {
$func = [null, "->tmissing"]; self::assertFalse(func::verifix_static($func, true, $bound));
$func = [null, "->tmissing"]; self::assertFalse(func::verifix_static($func, false, $bound));
$func = [false, "tsimple"]; self::assertTrue(func::verifix_static($func, true, $bound));
$func = [false, "tsimple"]; self::assertTrue(func::verifix_static($func, false, $bound));
$func = [false, "tsimple"]; self::assertFalse(func::verifix_static($func, False, $bound));
$func = [false, "tsimple"]; self::assertFalse(func::verifix_static($func, false, $bound));
$func = [false, 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_static($func, true, $bound));
$func = [false, 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_static($func, False, $bound));
$func = [false, 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_static($func, false, $bound));
$func = [false, "tmissing"]; self::assertTrue(func::verifix_static($func, true, $bound));
$func = [false, "tmissing"]; self::assertTrue(func::verifix_static($func, false, $bound));
$func = [false, "tmissing"]; self::assertFalse(func::verifix_static($func, False, $bound));
$func = [false, "tmissing"]; self::assertFalse(func::verifix_static($func, false, $bound));
$func = [false, "::tstatic"]; self::assertTrue(func::verifix_static($func, true, $bound));
$func = [false, "::tstatic"]; self::assertTrue(func::verifix_static($func, false, $bound));
$func = [false, "::tstatic"]; self::assertFalse(func::verifix_static($func, False, $bound));
$func = [false, "::tstatic"]; self::assertFalse(func::verifix_static($func, false, $bound));
$func = [false, "->tmethod"]; self::assertFalse(func::verifix_static($func, true, $bound));
$func = [false, "->tmethod"]; self::assertFalse(func::verifix_static($func, False, $bound));
$func = [false, "->tmethod"]; self::assertFalse(func::verifix_static($func, false, $bound));
$func = [false, "::tmissing"]; self::assertTrue(func::verifix_static($func, true, $bound));
$func = [false, "::tmissing"]; self::assertTrue(func::verifix_static($func, false, $bound));
$func = [false, "::tmissing"]; self::assertFalse(func::verifix_static($func, False, $bound));
$func = [false, "::tmissing"]; self::assertFalse(func::verifix_static($func, false, $bound));
$func = [false, "->tmissing"]; self::assertFalse(func::verifix_static($func, true, $bound));
$func = [false, "->tmissing"]; self::assertFalse(func::verifix_static($func, False, $bound));
$func = [false, "->tmissing"]; self::assertFalse(func::verifix_static($func, false, $bound));
$func = ["", "tsimple"]; self::assertTrue(func::verifix_static($func, true, $bound));
@ -411,8 +411,193 @@ namespace nur\sery\wip\php {
$func = [MyClass::class, "->tmissing"]; self::assertFalse(func::verifix_static($func, false, $bound));
}
function testStaticResults() {
//function testStaticResults() {}
}
function testMethod() {
# scalaires
$func = null; self::assertFalse(func::verifix_method($func, true, $bound));
$func = null; self::assertFalse(func::verifix_method($func, false, $bound));
$func = false; self::assertFalse(func::verifix_method($func, true, $bound));
$func = false; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ""; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ""; self::assertFalse(func::verifix_method($func, false, $bound));
$func = "::"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = "::"; self::assertFalse(func::verifix_method($func, false, $bound));
$func = "->"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = "->"; self::assertFalse(func::verifix_method($func, false, $bound));
$func = "tsimple"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = "tsimple"; self::assertFalse(func::verifix_method($func, false, $bound));
$func = 'nur\sery\wip\php\impl\ntsimple'; self::assertFalse(func::verifix_method($func, true, $bound));
$func = 'nur\sery\wip\php\impl\ntsimple'; self::assertFalse(func::verifix_method($func, false, $bound));
$func = 'tmissing'; self::assertFalse(func::verifix_method($func, true, $bound));
$func = 'tmissing'; self::assertFalse(func::verifix_method($func, false, $bound));
$func = "::tmethod"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = "::tmethod"; self::assertFalse(func::verifix_method($func, false, $bound));
$func = "->tmethod"; self::assertTrue(func::verifix_method($func, true, $bound));
$func = "->tmethod"; self::assertTrue(func::verifix_method($func, false, $bound));
$func = "::tmissing"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = "::tmissing"; self::assertFalse(func::verifix_method($func, false, $bound));
$func = "->tmissing"; self::assertTrue(func::verifix_method($func, true, $bound));
$func = "->tmissing"; self::assertTrue(func::verifix_method($func, false, $bound));
$func = MyClass::class."::tmethod"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = MyClass::class."::tmethod"; self::assertFalse(func::verifix_method($func, false, $bound));
$func = MyClass::class."->tmethod"; self::assertTrue(func::verifix_method($func, true, $bound));
$func = MyClass::class."->tmethod"; self::assertTrue(func::verifix_method($func, false, $bound));
$func = MyClass::class."::tmissing"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = MyClass::class."::tmissing"; self::assertFalse(func::verifix_method($func, false, $bound));
$func = MyClass::class."->tmissing"; self::assertFalse(func::verifix_method($func, true, $bound));
$func = MyClass::class."->tmissing"; self::assertTrue(func::verifix_method($func, false, $bound));
# tableaux avec un seul scalaire
$func = []; self::assertFalse(func::verifix_method($func, true, $bound));
$func = []; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [null]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [null]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [false]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [false]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [""]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [""]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["::"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["::"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["->"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["->"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["tsimple"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["tsimple"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ['nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ['nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["::tmethod"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["::tmethod"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["->tmethod"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = ["->tmethod"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = ["::tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["::tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["->tmissing"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = ["->tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [MyClass::class."::tmethod"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [MyClass::class."::tmethod"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [MyClass::class."->tmethod"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [MyClass::class."->tmethod"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [MyClass::class."::tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [MyClass::class."::tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [MyClass::class."->tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [MyClass::class."->tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
# tableaux avec deux scalaires
$func = [null, "tsimple"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [null, "tsimple"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [null, 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [null, 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [null, "tmissing"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [null, "tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [null, "::tmethod"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [null, "::tmethod"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [null, "->tmethod"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [null, "->tmethod"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [null, "::tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [null, "::tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [null, "->tmissing"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [null, "->tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [false, "tsimple"]; self::assertFalse(func::verifix_method($func, False, $bound));
$func = [false, "tsimple"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [false, 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, False, $bound));
$func = [false, 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [false, "tmissing"]; self::assertFalse(func::verifix_method($func, False, $bound));
$func = [false, "tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [false, "::tmethod"]; self::assertFalse(func::verifix_method($func, False, $bound));
$func = [false, "::tmethod"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [false, "->tmethod"]; self::assertFalse(func::verifix_method($func, False, $bound));
$func = [false, "->tmethod"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [false, "::tmissing"]; self::assertFalse(func::verifix_method($func, False, $bound));
$func = [false, "::tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [false, "->tmissing"]; self::assertFalse(func::verifix_method($func, False, $bound));
$func = [false, "->tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["", "tsimple"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = ["", "tsimple"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = ["", 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["", 'nur\sery\wip\php\impl\ntsimple']; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["", "tmissing"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = ["", "tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = ["", "::tmethod"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["", "::tmethod"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["", "->tmethod"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = ["", "->tmethod"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = ["", "::tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = ["", "::tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = ["", "->tmissing"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = ["", "->tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [MyClass::class, "tmethod"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [MyClass::class, "tmethod"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [MyClass::class, "::tmethod"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [MyClass::class, "::tmethod"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [MyClass::class, "tmethod"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [MyClass::class, "tmethod"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [MyClass::class, "->tmethod"]; self::assertTrue(func::verifix_method($func, true, $bound));
$func = [MyClass::class, "->tmethod"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [MyClass::class, "tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [MyClass::class, "tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
$func = [MyClass::class, "::tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [MyClass::class, "::tmissing"]; self::assertFalse(func::verifix_method($func, false, $bound));
$func = [MyClass::class, "->tmissing"]; self::assertFalse(func::verifix_method($func, true, $bound));
$func = [MyClass::class, "->tmissing"]; self::assertTrue(func::verifix_method($func, false, $bound));
}
//function testMethodResults() {}
}
}

View File

@ -75,68 +75,69 @@ class func {
return true;
}
private static function parse_class_m(?string $cm, ?string &$c, ?string &$m): bool {
if (self::is_invalid($cm) || self::parse_method($cm)) return false;
$pos = strpos($cm, "::");
private static function parse_class_s(?string $cs, ?string &$c, ?string &$s): bool {
if (self::is_invalid($cs) || self::parse_method($cs)) return false;
$pos = strpos($cs, "::");
if ($pos === false) return false;
if ($pos === 0) return false;
$tmpc = substr($cm, 0, $pos);
$cm = substr($cm, $pos + 2);
if (self::is_nfunction($cm)) return false;
[$c, $m] = [$tmpc, cv::vn($cm)];
$tmpc = substr($cs, 0, $pos);
$cs = substr($cs, $pos + 2);
if (self::is_nfunction($cs)) return false;
[$c, $s] = [$tmpc, cv::vn($cs)];
return true;
}
private static function parse_c_method(?string $cm, ?string &$c, ?string &$m, ?bool &$bound): bool {
if (self::is_invalid($cm) || self::parse_method($cm)) return false;
$pos = strpos($cm, "::");
private static function parse_c_static(?string $cs, ?string &$c, ?string &$s, ?bool &$bound): bool {
if (self::is_invalid($cs) || self::parse_method($cs)) return false;
$pos = strpos($cs, "::");
if ($pos === false) return false;
if ($pos == strlen($cm) - 2) return false;
if ($pos == strlen($cs) - 2) return false;
if ($pos > 0) {
$tmpc = substr($cm, 0, $pos);
$tmpc = substr($cs, 0, $pos);
$bound = true;
} else {
$tmpc = null;
$bound = false;
}
$cm = substr($cm, $pos + 2);
if (self::is_nfunction($cm)) return false;
[$c, $m] = [$tmpc, cv::vn($cm)];
$cs = substr($cs, $pos + 2);
if (self::is_nfunction($cs)) return false;
[$c, $s] = [$tmpc, cv::vn($cs)];
return true;
}
/**
* vérifier que $func est une fonction statique, et la normaliser le cas
* échéant. retourner true si c'est une fonction statique, false sinon
* vérifier que $func est une méthode statique, et la normaliser le cas
* échéant. retourner true si c'est une méthode statique, false sinon
*
* les formes suivantes sont supportées (XXX étant null ou n'importe quelle
* valeur scalaire de n'importe quel type)
* valeur scalaire de n'importe quel type sauf false)
* - "XXX::function"
* - ["XXX::function", ...$args]
* - [XXX, "::function", ...$args]
* - [XXX, "function", ...$args] c'est la forme normalisée
*
* Si XXX est une classe, la fonction statique est liée. sinon, elle doit être
* Si XXX est une classe, la méthode statique est liée. sinon, elle doit être
* liée à une classe avant d'être utilisée
*
* @param bool $strict vérifier l'inexistence de la classe et l'existence de
* la fonction (ne pas uniquement faire une vérification syntaxique)
* @param bool $strict vérifier l'existence de la classe et de la méthode si
* la méthode est liée (ne pas uniquement faire une vérification syntaxique)
*/
static function verifix_static(&$func, bool $strict=true, ?bool &$bound=null): bool {
if (is_string($func)) {
if (!self::parse_c_method($func, $c, $f, $bound)) return false;
if (!self::parse_c_static($func, $c, $f, $bound)) return false;
$func = [$c, $f];
} elseif (is_array($func)) {
if (!array_key_exists(0, $func)) return false;
$c = $func[0];
if (self::parse_class_m($c, $c, $f)) {
if ($c === false) return false;
if (self::parse_class_s($c, $c, $f)) {
$func[0] = $c;
if ($f !== null) {
# ["class::method"] --> ["class", "method"]
array_splice($func, 1, 0, [$f]);
}
$bound = true;
} elseif (self::parse_c_method($c, $c, $f, $bound)) {
} elseif (self::parse_c_static($c, $c, $f, $bound)) {
# ["::method"] --> [null, "method"]
array_splice($func, 0, 0, [null]);
$func[1] = $f;
@ -149,7 +150,7 @@ class func {
if (!array_key_exists(1, $func)) return false;
$f = $func[1];
if (!is_string($f)) return false;
if (self::parse_c_method($f, $rc, $f, $rbound)) {
if (self::parse_c_static($f, $rc, $f, $rbound)) {
if ($rc !== null && $c === null) {
$c = $rc;
$bound = $rbound;
@ -170,16 +171,100 @@ class func {
return true;
}
static function verifix_method(&$func): bool {
private static function parse_class_m(?string $cm, ?string &$c, ?string &$m): bool {
if (self::is_invalid($cm) || self::parse_static($cm)) return false;
$pos = strpos($cm, "->");
if ($pos === false) return false;
if ($pos === 0) return false;
$tmpc = substr($cm, 0, $pos);
$cm = substr($cm, $pos + 2);
if (self::is_nfunction($cm)) return false;
[$c, $m] = [$tmpc, cv::vn($cm)];
return true;
}
private static function parse_c_method(?string $cm, ?string &$c, ?string &$m, ?bool &$bound): bool {
if (self::is_invalid($cm) || self::parse_static($cm)) return false;
$pos = strpos($cm, "->");
if ($pos === false) return false;
if ($pos == strlen($cm) - 2) return false;
if ($pos > 0) {
$tmpc = substr($cm, 0, $pos);
$bound = true;
} else {
$tmpc = null;
$bound = false;
}
$cm = substr($cm, $pos + 2);
if (self::is_nfunction($cm)) return false;
[$c, $m] = [$tmpc, cv::vn($cm)];
return true;
}
/**
* vérifier que $func est une méthode non statique, et la normaliser le cas
* échéant. retourner true si c'est une méthode non statique, false sinon
*
* les formes suivantes sont supportées (XXX étant null ou n'importe quelle
* valeur scalaire de n'importe quel type sauf false)
* - "XXX->function"
* - ["XXX->function", ...$args]
* - [XXX, "->function", ...$args]
* - [XXX, "function", ...$args] c'est la forme normalisée
*
* Si XXX est une classe, la méthode est liée. sinon, elle doit être liée à un
* objet avant d'être utilisée
*
* @param bool $strict vérifier l'existence de la classe et de la méthode si
* la méthode est liée (ne pas uniquement faire une vérification syntaxique)
*/
static function verifix_method(&$func, bool $strict=true, ?bool &$bound=null): bool {
if (is_string($func)) {
return true;
if (!self::parse_c_method($func, $c, $f, $bound)) return false;
$func = [$c, $f];
} elseif (is_array($func)) {
return true;
if (!array_key_exists(0, $func)) return false;
$c = $func[0];
if ($c === false) return false;
if (self::parse_class_m($c, $c, $f)) {
$func[0] = $c;
if ($f !== null) {
# ["class->method"] --> ["class", "method"]
array_splice($func, 1, 0, [$f]);
}
$bound = true;
} elseif (self::parse_c_method($c, $c, $f, $bound)) {
# ["->method"] --> [null, "method"]
array_splice($func, 0, 0, [null]);
$func[1] = $f;
} else {
if (self::is_invalid($c)) $c = null;
$func[0] = $c;
$bound = is_string($c);
}
#
if (!array_key_exists(1, $func)) return false;
$f = $func[1];
if (!is_string($f)) return false;
if (self::parse_c_method($f, $rc, $f, $rbound)) {
if ($rc !== null && $c === null) {
$c = $rc;
$bound = $rbound;
}
} elseif (self::is_invalid($f)) {
return false;
} elseif (self::is_nfunction($f)) {
return false;
} elseif (self::parse_static($f)) {
return false;
} elseif (self::parse_method($f)) {
}
$func[1] = $f;
} else {
return false;
}
if ($strict && $bound && !method_exists($c, $f)) return false;
return true;
}
static function verifix_cons(&$func): bool {