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.
32 lines
806 B
32 lines
806 B
--TEST--
|
|
Symfony pattern: nullsafe __invoke callback check
|
|
--FILE--
|
|
<?php
|
|
|
|
class SymfonyLikeTraceableDispatcher
|
|
{
|
|
public function __construct(private ?Closure $disabled = null)
|
|
{
|
|
}
|
|
|
|
public function dispatch(string $name): string
|
|
{
|
|
if ($this->disabled?->__invoke()) {
|
|
return 'disabled';
|
|
}
|
|
|
|
return 'dispatch:'.$name;
|
|
}
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
var_dump((new SymfonyLikeTraceableDispatcher())->dispatch('kernel.request'));
|
|
var_dump((new SymfonyLikeTraceableDispatcher(static fn () => false))->dispatch('kernel.response'));
|
|
var_dump((new SymfonyLikeTraceableDispatcher(static fn () => true))->dispatch('kernel.exception'));
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
string(23) "dispatch:kernel.request"
|
|
string(24) "dispatch:kernel.response"
|
|
string(8) "disabled"
|
|
|