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

nette / http / 22293514258

23 Feb 2026 04:58AM UTC coverage: 83.62%. Remained the same
22293514258

push

github

dg
added CLAUDE.md

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 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
class SessionExtension extends Nette\DI\CompilerExtension
19
{
20
        public function __construct(
1✔
21
                private readonly bool $debugMode = false,
22
                private readonly bool $cliMode = false,
23
        ) {
24
        }
1✔
25

26

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

40

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

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

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

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

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

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

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

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

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

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

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

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

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

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