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

nette / application / 20834855301

08 Jan 2026 10:54PM UTC coverage: 84.605% (+1.7%) from 82.856%
20834855301

push

github

dg
added CLAUDE.md

1940 of 2293 relevant lines covered (84.61%)

0.85 hits per line

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

38.1
/src/Application/UI/Form.php
1
<?php
2

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

8
declare(strict_types=1);
9

10
namespace Nette\Application\UI;
11

12
use Nette;
13
use function func_num_args;
14

15

16
/**
17
 * Web form adapted for Presenter.
18
 */
19
class Form extends Nette\Forms\Form implements SignalReceiver
20
{
21
        /** @var array<callable(self): void>  Occurs when form is attached to presenter */
22
        public array $onAnchor = [];
23

24

25
        /**
26
         * Application form constructor.
27
         */
28
        public function __construct(?Nette\ComponentModel\IContainer $parent = null, ?string $name = null)
1✔
29
        {
30
                parent::__construct();
1✔
31
                $parent?->addComponent($this, $name);
1✔
32
        }
1✔
33

34

35
        protected function validateParent(Nette\ComponentModel\IContainer $parent): void
1✔
36
        {
37
                parent::validateParent($parent);
1✔
38

39
                $this->monitor(Presenter::class, function (Presenter $presenter): void {
1✔
40
                        if (!isset($this->getElementPrototype()->id)) {
1✔
41
                                $this->getElementPrototype()->id = 'frm-' . $this->lookupPath(Presenter::class);
1✔
42
                        }
43

44
                        if (!$this->getAction()) {
1✔
45
                                $this->setAction(new Link($presenter, 'this'));
1✔
46
                        }
47

48
                        $controls = $this->getControls();
1✔
49
                        if (iterator_count($controls) && $this->isSubmitted()) {
1✔
50
                                foreach ($controls as $control) {
51
                                        if (!$control->isDisabled()) {
52
                                                $control->loadHttpData();
53
                                        }
54
                                }
55
                        }
56

57
                        Nette\Utils\Arrays::invoke($this->onAnchor, $this);
1✔
58
                });
1✔
59
        }
1✔
60

61

62
        /**
63
         * Returns the presenter where this component belongs to.
64
         */
65
        final public function getPresenter(): Presenter
66
        {
67
                return $this->lookup(Presenter::class);
×
68
        }
69

70

71
        /**
72
         * Returns the presenter where this component belongs to.
73
         */
74
        final public function getPresenterIfExists(): ?Presenter
75
        {
76
                return $this->lookup(Presenter::class, throw: false);
×
77
        }
78

79

80
        /** @deprecated */
81
        public function hasPresenter(): bool
82
        {
83
                return (bool) $this->lookup(Presenter::class, throw: false);
×
84
        }
85

86

87
        /**
88
         * Tells if the form is anchored.
89
         */
90
        public function isAnchored(): bool
91
        {
92
                return $this->hasPresenter();
×
93
        }
94

95

96
        #[\Deprecated('use allowCrossOrigin()')]
97
        public function disableSameSiteProtection(): void
98
        {
99
                $this->allowCrossOrigin();
×
100
        }
101

102

103
        /**
104
         * Internal: returns submitted HTTP data or null when form was not submitted.
105
         */
106
        protected function receiveHttpData(): ?array
107
        {
108
                $presenter = $this->getPresenter();
×
109
                if (!$presenter->isSignalReceiver($this, 'submit')) {
×
110
                        return null;
×
111
                }
112

113
                $request = $presenter->getRequest();
×
114
                if ($request->isMethod('forward') || $request->isMethod('post') !== $this->isMethod('post')) {
×
115
                        return null;
×
116
                }
117

118
                return $this->isMethod('post')
×
119
                        ? Nette\Utils\Arrays::mergeTree($request->getPost(), $request->getFiles())
×
120
                        : $request->getParameters();
×
121
        }
122

123

124
        protected function beforeRender(): void
125
        {
126
                parent::beforeRender();
×
127
                $key = ($this->isMethod('post') ? '_' : '') . Presenter::SignalKey;
×
128
                if (!isset($this[$key]) && $this->getAction() !== '') {
×
129
                        $do = $this->lookupPath(Presenter::class) . self::NameSeparator . 'submit';
×
130
                        $this[$key] = (new Nette\Forms\Controls\HiddenField($do))->setOmitted();
×
131
                }
132
        }
133

134

135
        /********************* interface SignalReceiver ****************d*g**/
136

137

138
        /**
139
         * This method is called by presenter.
140
         */
141
        public function signalReceived(string $signal): void
142
        {
143
                if ($signal !== 'submit') {
×
144
                        $class = static::class;
×
145
                        throw new BadSignalException("Missing handler for signal '$signal' in $class.");
×
146

147
                } elseif (!$this->crossOrigin && !$this->getPresenter()->getHttpRequest()->isSameSite()) {
×
148
                        $this->getPresenter()->detectedCsrf();
×
149

150
                } elseif (!$this->getPresenter()->getRequest()->hasFlag(Nette\Application\Request::RESTORED)) {
×
151
                        $this->fireEvents();
×
152
                }
153
        }
154
}
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