ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
CheckClosureTrait.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use Closure;
24 use LogicException;
26 use ReflectionType;
27 use Throwable;
28 
32 trait CheckClosureTrait
33 {
34  private function checkClosureForSignature(Closure $c, string $signature): void
35  {
36  $error_message = 'first argument and return type of closure must be type-hinted to ' . $signature;
37  try {
38  $r = new ReflectionFunction($c);
39  if (count($r->getParameters()) !== 1) {
40  throw new LogicException($error_message);
41  }
42  $first_param_type = $r->getParameters()[0]->getType();
43  if ($first_param_type instanceof ReflectionType && $first_param_type->getName() !== $signature) {
44  throw new LogicException($error_message);
45  }
46  $return_type = $r->getReturnType();
47  if ($return_type === null) {
48  throw new LogicException($error_message);
49  }
50  if ($return_type->getName() !== $signature) {
51  throw new LogicException($error_message);
52  }
53  } catch (Throwable) {
54  throw new LogicException($error_message);
55  }
56  }
57 }
$c
Definition: deliver.php:25
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$r