TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
855 B
36 lines
855 B
--TEST--
|
|
Symfony Routing pattern: provider returns callable invoked with unpacked args
|
|
--FILE--
|
|
<?php
|
|
|
|
class FunctionProvider
|
|
{
|
|
/** @var array<string, callable> */
|
|
private array $functions = [];
|
|
|
|
public function set(string $name, callable $function): void
|
|
{
|
|
$this->functions[$name] = $function;
|
|
}
|
|
|
|
public function get(string $name): callable
|
|
{
|
|
return $this->functions[$name];
|
|
}
|
|
}
|
|
|
|
function evaluate(FunctionProvider $provider, string $function, array $args): string
|
|
{
|
|
return $provider->get($function)(...$args);
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
$provider = new FunctionProvider();
|
|
$provider->set('format', static fn (string $prefix, string $value): string => $prefix.':'.strtoupper($value));
|
|
|
|
var_dump(evaluate($provider, 'format', ['name', 'symfony']));
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
string(12) "name:SYMFONY"
|
|
|