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
      • Reflection
      • 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
  • Other releases
  • Nette homepage
 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 = array(
19:         'debugger' => FALSE,
20:         'autoStart' => 'smart', // true|false|smart
21:         'expiration' => NULL,
22:     );
23: 
24:     /** @var bool */
25:     private $debugMode;
26: 
27: 
28:     public function __construct($debugMode = FALSE)
29:     {
30:         $this->debugMode = $debugMode;
31:     }
32: 
33: 
34:     public function loadConfiguration()
35:     {
36:         $container = $this->getContainerBuilder();
37:         $config = $this->getConfig() + $this->defaults;
38:         $this->setConfig($config);
39: 
40:         $session = $container->addDefinition($this->prefix('session'))
41:             ->setClass('Nette\Http\Session');
42: 
43:         if ($config['expiration']) {
44:             $session->addSetup('setExpiration', array($config['expiration']));
45:         }
46: 
47:         if ($this->debugMode && $config['debugger']) {
48:             $session->addSetup('@Tracy\Bar::addPanel', array(
49:                 new Nette\DI\Statement('Nette\Bridges\HttpTracy\SessionPanel'),
50:             ));
51:         }
52: 
53:         unset($config['expiration'], $config['autoStart'], $config['debugger']);
54:         if (!empty($config)) {
55:             $session->addSetup('setOptions', array($config));
56:         }
57: 
58:         if ($this->name === 'session') {
59:             $container->addAlias('session', $this->prefix('session'));
60:         }
61:     }
62: 
63: 
64:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
65:     {
66:         if (PHP_SAPI === 'cli') {
67:             return;
68:         }
69: 
70:         $initialize = $class->getMethod('initialize');
71:         $config = $this->getConfig();
72:         $name = $this->prefix('session');
73: 
74:         if ($config['autoStart'] === 'smart') {
75:             $initialize->addBody('$this->getService(?)->exists() && $this->getService(?)->start();', array($name, $name));
76: 
77:         } elseif ($config['autoStart']) {
78:             $initialize->addBody('$this->getService(?)->start();', array($name));
79:         }
80:     }
81: 
82: }
83: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0