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

nette / http / 26458288420

26 May 2026 03:31PM UTC coverage: 84.24% (+0.7%) from 83.513%
26458288420

push

github

dg
added Request::isFrom() WIP

11 of 11 new or added lines in 1 file covered. (100.0%)

32 existing lines in 4 files now uncovered.

1053 of 1250 relevant lines covered (84.24%)

0.84 hits per line

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

78.57
/src/Bridges/HttpDI/SessionExtension.php
1
<?php declare(strict_types=1);
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
namespace Nette\Bridges\HttpDI;
9

10
use Nette;
11
use Nette\Http\IResponse;
12
use Nette\Schema\Expect;
13

14

15
/**
16
 * Session extension for Nette DI.
17
 *
18
 * @property object{
19
 *     debugger: bool,
20
 *     autoStart: 'smart'|'always'|'never'|bool,
21
 *     expiration: string|null,
22
 *     handler: string|null,
23
 *     readAndClose: bool|null,
24
 *     cookieSamesite: 'Lax'|'Strict'|'None',
25
 *     ...
26
 * } $config
27
 */
28
class SessionExtension extends Nette\DI\CompilerExtension
29
{
30
        public function __construct(
1✔
31
                private readonly bool $debugMode = false,
32
                private readonly bool $cliMode = false,
33
        ) {
34
        }
1✔
35

36

37
        public function getConfigSchema(): Nette\Schema\Schema
38
        {
39
                return Expect::structure([
1✔
40
                        'debugger' => Expect::bool(false),
1✔
41
                        'autoStart' => Expect::anyOf('smart', 'always', 'never', true, false)->firstIsDefault(),
1✔
42
                        'expiration' => Expect::string()->dynamic(),
1✔
43
                        'handler' => Expect::string()->dynamic(),
1✔
44
                        'readAndClose' => Expect::bool(),
1✔
45
                        'cookieSamesite' => Expect::anyOf(IResponse::SameSiteLax, IResponse::SameSiteStrict, IResponse::SameSiteNone)
1✔
46
                                ->firstIsDefault(),
1✔
47
                ])->otherItems('mixed');
1✔
48
        }
49

50

51
        public function loadConfiguration(): void
52
        {
53
                $builder = $this->getContainerBuilder();
1✔
54
                $config = $this->config;
1✔
55

56
                $session = $builder->addDefinition($this->prefix('session'))
1✔
57
                        ->setFactory(Nette\Http\Session::class);
1✔
58

59
                if ($config->expiration) {
1✔
UNCOV
60
                        $session->addSetup('setExpiration', [$config->expiration]);
×
61
                }
62

63
                if ($config->handler) {
1✔
64
                        $session->addSetup('setHandler', [$config->handler]);
1✔
65
                }
66

67
                if (($config->cookieDomain ?? null) === 'domain') {
1✔
68
                        $config->cookieDomain = $builder::literal('$this->getByType(Nette\Http\IRequest::class)->getUrl()->getDomain(2)');
1✔
69
                }
70

71
                $this->compiler->addExportedType(Nette\Http\IRequest::class);
1✔
72

73
                if ($this->debugMode && $config->debugger) {
1✔
UNCOV
74
                        $session->addSetup('@Tracy\Bar::addPanel', [
×
UNCOV
75
                                new Nette\DI\Definitions\Statement(Nette\Bridges\HttpTracy\SessionPanel::class),
×
76
                        ]);
77
                }
78

79
                $options = (array) $config;
1✔
80
                unset($options['expiration'], $options['handler'], $options['autoStart'], $options['debugger']);
1✔
81
                if ($config->autoStart === 'never') {
1✔
UNCOV
82
                        $options['autoStart'] = false;
×
83
                }
84

85
                if ($config->readAndClose === null) {
1✔
86
                        unset($options['readAndClose']);
1✔
87
                }
88

89
                if (!empty($options)) {
1✔
90
                        $session->addSetup('setOptions', [$options]);
1✔
91
                }
92

93
                if ($this->name === 'session') {
1✔
94
                        $builder->addAlias('session', $this->prefix('session'));
1✔
95
                }
96

97
                if (!$this->cliMode) {
1✔
UNCOV
98
                        $name = $this->prefix('session');
×
99

UNCOV
100
                        if ($config->autoStart === 'smart') {
×
UNCOV
101
                                $this->initialization->addBody('$this->getService(?)->autoStart(false);', [$name]);
×
102

UNCOV
103
                        } elseif ($config->autoStart === 'always' || $config->autoStart === true) {
×
UNCOV
104
                                $this->initialization->addBody('$this->getService(?)->start();', [$name]);
×
105
                        }
106
                }
107
        }
1✔
108
}
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