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

nette / http / 8877511590

29 Apr 2024 11:05AM UTC coverage: 81.537% (-0.2%) from 81.776%
8877511590

push

github

dg
IRequest, IResponse: added typehints, unification (BC break)

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

53 existing lines in 5 files now uncovered.

870 of 1067 relevant lines covered (81.54%)

0.82 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

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

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

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

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

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

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

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

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

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

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

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

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

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