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
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • 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 (http://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\Bridges\HttpDI;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Session extension for Nette DI.
15:  *
16:  * @author     David Grudl
17:  */
18: class SessionExtension extends Nette\DI\CompilerExtension
19: {
20:     public $defaults = array(
21:         'debugger' => FALSE,
22:         'autoStart' => 'smart', // true|false|smart
23:         'expiration' => NULL,
24:     );
25: 
26:     /** @var bool */
27:     private $debugMode;
28: 
29: 
30:     public function __construct($debugMode = FALSE)
31:     {
32:         $this->debugMode = $debugMode;
33:     }
34: 
35: 
36:     public function loadConfiguration()
37:     {
38:         $container = $this->getContainerBuilder();
39:         $config = $this->getConfig() + $this->defaults;
40:         $this->setConfig($config);
41: 
42:         $session = $container->addDefinition($this->prefix('session'))
43:             ->setClass('Nette\Http\Session');
44: 
45:         if ($config['expiration']) {
46:             $session->addSetup('setExpiration', array($config['expiration']));
47:         }
48: 
49:         if ($this->debugMode && $config['debugger']) {
50:             $session->addSetup('@Tracy\Bar::addPanel', array(
51:                 new Nette\DI\Statement('Nette\Bridges\HttpTracy\SessionPanel')
52:             ));
53:         }
54: 
55:         unset($config['expiration'], $config['autoStart'], $config['debugger']);
56:         if (!empty($config)) {
57:             $session->addSetup('setOptions', array($config));
58:         }
59: 
60:         if ($this->name === 'session') {
61:             $container->addAlias('session', $this->prefix('session'));
62:         }
63:     }
64: 
65: 
66:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
67:     {
68:         if (PHP_SAPI === 'cli') {
69:             return;
70:         }
71: 
72:         $initialize = $class->getMethod('initialize');
73:         $config = $this->getConfig();
74:         $name = $this->prefix('session');
75: 
76:         if ($config['autoStart'] === 'smart') {
77:             $initialize->addBody('$this->getService(?)->exists() && $this->getService(?)->start();', array($name, $name));
78: 
79:         } elseif ($config['autoStart']) {
80:             $initialize->addBody('$this->getService(?)->start();', array($name));
81:         }
82:     }
83: 
84: }
85: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0