• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / latte / 15809643126

22 Jun 2025 06:35PM UTC coverage: 93.67% (+0.09%) from 93.583%
15809643126

push

github

dg
added {include?} {import?} {embed?} {sandbox?}

34 of 36 new or added lines in 7 files covered. (94.44%)

164 existing lines in 43 files now uncovered.

5164 of 5513 relevant lines covered (93.67%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/src/Latte/Runtime/FunctionExecutor.php
1
<?php
2

3
/**
4
 * This file is part of the Latte (https://latte.nette.org)
5
 * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Latte\Runtime;
11

12
use Latte\Helpers;
13
use function array_keys;
14

15

16
/**
17
 * Functions executor.
18
 * @internal
19
 */
20
#[\AllowDynamicProperties]
21
class FunctionExecutor
22
{
23
        /** @var callable[] */
24
        private array $_list = [];
25

26
        /** @var bool[] */
27
        private array $_aware = [];
28

29

30
        /**
31
         * Registers run-time function.
32
         */
33
        public function add(string $name, callable $callback): static
1✔
34
        {
35
                $this->_list[$name] = $callback;
1✔
36
                unset($this->$name, $this->_aware[$name]);
1✔
37
                return $this;
1✔
38
        }
39

40

41
        /**
42
         * Returns all run-time functions.
43
         * @return callable[]
44
         */
45
        public function getAll(): array
46
        {
47
                return $this->_list;
1✔
48
        }
49

50

51
        public function __get(string $name): callable
1✔
52
        {
53
                $callback = $this->_list[$name] ?? null;
1✔
54
                if (!$callback) {
1✔
55
                        $hint = ($t = Helpers::getSuggestion(array_keys($this->_list), $name))
1✔
UNCOV
56
                                ? ", did you mean '$t'?"
×
57
                                : '.';
1✔
58
                        throw new \LogicException("Function '$name' is not defined$hint");
1✔
59

60
                } elseif (!isset($this->_aware[$name])) {
1✔
61
                        $params = Helpers::toReflection($callback)->getParameters();
1✔
62
                        $this->_aware[$name] = $params && (string) $params[0]->getType() === Template::class;
1✔
63
                }
64

65
                return $this->$name = $this->_aware[$name]
1✔
66
                        ? $callback
1✔
67
                        : fn($info, ...$args) => $callback(...$args);
1✔
68
        }
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc