Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • HttpExtension
  • SessionExtension
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
 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: namespace Nette\Bridges\HttpDI;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Session extension for Nette DI.
15:  */
16: class SessionExtension extends Nette\DI\CompilerExtension
17: {
18:     public $defaults = [
19:         'debugger' => FALSE,
20:         'autoStart' => 'smart', // true|false|smart
21:         'expiration' => NULL,
22:     ];
23: 
24:     /** @var bool */
25:     private $debugMode;
26: 
27:     /** @var bool */
28:     private $cliMode;
29: 
30: 
31:     public function __construct($debugMode = FALSE, $cliMode = FALSE)
32:     {
33:         $this->debugMode = $debugMode;
34:         $this->cliMode = $cliMode;
35:     }
36: 
37: 
38:     public function loadConfiguration()
39:     {
40:         $builder = $this->getContainerBuilder();
41:         $config = $this->getConfig() + $this->defaults;
42:         $this->setConfig($config);
43: 
44:         $session = $builder->addDefinition($this->prefix('session'))
45:             ->setClass(Nette\Http\Session::class);
46: 
47:         if ($config['expiration']) {
48:             $session->addSetup('setExpiration', [$config['expiration']]);
49:         }
50: 
51:         if ($this->debugMode && $config['debugger']) {
52:             $session->addSetup('@Tracy\Bar::addPanel', [
53:                 new Nette\DI\Statement(Nette\Bridges\HttpTracy\SessionPanel::class)
54:             ]);
55:         }
56: 
57:         unset($config['expiration'], $config['autoStart'], $config['debugger']);
58:         if (!empty($config)) {
59:             $session->addSetup('setOptions', [$config]);
60:         }
61: 
62:         if ($this->name === 'session') {
63:             $builder->addAlias('session', $this->prefix('session'));
64:         }
65:     }
66: 
67: 
68:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
69:     {
70:         if ($this->cliMode) {
71:             return;
72:         }
73: 
74:         $initialize = $class->getMethod('initialize');
75:         $config = $this->getConfig();
76:         $name = $this->prefix('session');
77: 
78:         if ($config['autoStart'] === 'smart') {
79:             $initialize->addBody('$this->getService(?)->exists() && $this->getService(?)->start();', [$name, $name]);
80: 
81:         } elseif ($config['autoStart']) {
82:             $initialize->addBody('$this->getService(?)->start();', [$name]);
83:         }
84:     }
85: 
86: }
87: 
Nette 2.4-20161109 API API documentation generated by ApiGen 2.8.0