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

nette / http / 21832799728

09 Feb 2026 04:17PM UTC coverage: 83.62% (-0.2%) from 83.772%
21832799728

push

github

dg
Request::isSameSite() is silently deprecated

924 of 1105 relevant lines covered (83.62%)

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
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\Bridges\HttpDI;
11

12
use Nette;
13
use Nette\Http\IResponse;
14
use Nette\Schema\Expect;
15

16

17
/**
18
 * Session extension for Nette DI.
19
 */
20
class SessionExtension extends Nette\DI\CompilerExtension
21
{
22
        public function __construct(
1✔
23
                private readonly bool $debugMode = false,
24
                private readonly bool $cliMode = false,
25
        ) {
26
        }
1✔
27

28

29
        public function getConfigSchema(): Nette\Schema\Schema
30
        {
31
                return Expect::structure([
1✔
32
                        'debugger' => Expect::bool(false),
1✔
33
                        'autoStart' => Expect::anyOf('smart', 'always', 'never', true, false)->firstIsDefault(),
1✔
34
                        'expiration' => Expect::string()->dynamic(),
1✔
35
                        'handler' => Expect::string()->dynamic(),
1✔
36
                        'readAndClose' => Expect::bool(),
1✔
37
                        'cookieSamesite' => Expect::anyOf(IResponse::SameSiteLax, IResponse::SameSiteStrict, IResponse::SameSiteNone)
1✔
38
                                ->firstIsDefault(),
1✔
39
                ])->otherItems('mixed');
1✔
40
        }
41

42

43
        public function loadConfiguration(): void
44
        {
45
                $builder = $this->getContainerBuilder();
1✔
46
                $config = $this->config;
1✔
47
                \assert($config instanceof \stdClass);
48

49
                $session = $builder->addDefinition($this->prefix('session'))
1✔
50
                        ->setFactory(Nette\Http\Session::class);
1✔
51

52
                if ($config->expiration) {
1✔
53
                        $session->addSetup('setExpiration', [$config->expiration]);
×
54
                }
55

56
                if ($config->handler) {
1✔
57
                        $session->addSetup('setHandler', [$config->handler]);
1✔
58
                }
59

60
                if (($config->cookieDomain ?? null) === 'domain') {
1✔
61
                        $config->cookieDomain = $builder::literal('$this->getByType(Nette\Http\IRequest::class)->getUrl()->getDomain(2)');
1✔
62
                }
63

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

66
                if ($this->debugMode && $config->debugger) {
1✔
67
                        $session->addSetup('@Tracy\Bar::addPanel', [
×
68
                                new Nette\DI\Definitions\Statement(Nette\Bridges\HttpTracy\SessionPanel::class),
×
69
                        ]);
70
                }
71

72
                $options = (array) $config;
1✔
73
                unset($options['expiration'], $options['handler'], $options['autoStart'], $options['debugger']);
1✔
74
                if ($config->autoStart === 'never') {
1✔
75
                        $options['autoStart'] = false;
×
76
                }
77

78
                if ($config->readAndClose === null) {
1✔
79
                        unset($options['readAndClose']);
1✔
80
                }
81

82
                if (!empty($options)) {
1✔
83
                        $session->addSetup('setOptions', [$options]);
1✔
84
                }
85

86
                if ($this->name === 'session') {
1✔
87
                        $builder->addAlias('session', $this->prefix('session'));
1✔
88
                }
89

90
                if (!$this->cliMode) {
1✔
91
                        $name = $this->prefix('session');
×
92

93
                        if ($config->autoStart === 'smart') {
×
94
                                $this->initialization->addBody('$this->getService(?)->autoStart(false);', [$name]);
×
95

96
                        } elseif ($config->autoStart === 'always' || $config->autoStart === true) {
×
97
                                $this->initialization->addBody('$this->getService(?)->start();', [$name]);
×
98
                        }
99
                }
100
        }
1✔
101
}
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