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.
42 lines
759 B
42 lines
759 B
--TEST--
|
|
Symfony Routing pattern: null comparison with route coalesce assignment
|
|
--FILE--
|
|
<?php
|
|
|
|
class RouteStore
|
|
{
|
|
public function __construct(private array $routes)
|
|
{
|
|
}
|
|
|
|
public function get(string $name): ?string
|
|
{
|
|
echo "lookup:$name\n";
|
|
return $this->routes[$name] ?? null;
|
|
}
|
|
}
|
|
|
|
function generate(RouteStore $routes, string $name): string
|
|
{
|
|
$route = null;
|
|
|
|
if (null === $route ??= $routes->get($name)) {
|
|
return 'missing';
|
|
}
|
|
|
|
return 'route:'.$route;
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
$routes = new RouteStore(['home' => '/']);
|
|
|
|
var_dump(generate($routes, 'home'));
|
|
var_dump(generate($routes, 'missing'));
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
lookup:home
|
|
string(7) "route:/"
|
|
lookup:missing
|
|
string(7) "missing"
|
|
|