Projekt

Obecné

Profil

Stáhnout (5.65 KB) Statistiky
| Větev: | Revize:
1 cb15593b Cajova-Houba
<?php
2
3
namespace Illuminate\Session;
4
5
use Illuminate\Support\Manager;
6
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
7
8
class SessionManager extends Manager
9
{
10
    /**
11
     * Call a custom driver creator.
12
     *
13
     * @param  string  $driver
14
     * @return mixed
15
     */
16
    protected function callCustomCreator($driver)
17
    {
18
        return $this->buildSession(parent::callCustomCreator($driver));
19
    }
20
21
    /**
22
     * Create an instance of the "array" session driver.
23
     *
24
     * @return \Illuminate\Session\Store
25
     */
26
    protected function createArrayDriver()
27
    {
28
        return $this->buildSession(new NullSessionHandler);
29
    }
30
31
    /**
32
     * Create an instance of the "cookie" session driver.
33
     *
34
     * @return \Illuminate\Session\Store
35
     */
36
    protected function createCookieDriver()
37
    {
38
        $lifetime = $this->app['config']['session.lifetime'];
39
40
        return $this->buildSession(new CookieSessionHandler($this->app['cookie'], $lifetime));
41
    }
42
43
    /**
44
     * Create an instance of the file session driver.
45
     *
46
     * @return \Illuminate\Session\Store
47
     */
48
    protected function createFileDriver()
49
    {
50
        return $this->createNativeDriver();
51
    }
52
53
    /**
54
     * Create an instance of the file session driver.
55
     *
56
     * @return \Illuminate\Session\Store
57
     */
58
    protected function createNativeDriver()
59
    {
60
        $path = $this->app['config']['session.files'];
61
62
        $lifetime = $this->app['config']['session.lifetime'];
63
64
        return $this->buildSession(new FileSessionHandler($this->app['files'], $path, $lifetime));
65
    }
66
67
    /**
68
     * Create an instance of the database session driver.
69
     *
70
     * @return \Illuminate\Session\Store
71
     */
72
    protected function createDatabaseDriver()
73
    {
74
        $connection = $this->getDatabaseConnection();
75
76
        $table = $this->app['config']['session.table'];
77
78
        $lifetime = $this->app['config']['session.lifetime'];
79
80
        return $this->buildSession(new DatabaseSessionHandler($connection, $table, $lifetime, $this->app));
81
    }
82
83
    /**
84
     * Create an instance of the legacy database session driver.
85
     *
86
     * @return \Illuminate\Session\Store
87
     *
88
     * @deprecated since version 5.2.
89
     */
90
    protected function createLegacyDatabaseDriver()
91
    {
92
        $connection = $this->getDatabaseConnection();
93
94
        $table = $this->app['config']['session.table'];
95
96
        $lifetime = $this->app['config']['session.lifetime'];
97
98
        return $this->buildSession(new LegacyDatabaseSessionHandler($connection, $table, $lifetime));
99
    }
100
101
    /**
102
     * Get the database connection for the database driver.
103
     *
104
     * @return \Illuminate\Database\Connection
105
     */
106
    protected function getDatabaseConnection()
107
    {
108
        $connection = $this->app['config']['session.connection'];
109
110
        return $this->app['db']->connection($connection);
111
    }
112
113
    /**
114
     * Create an instance of the APC session driver.
115
     *
116
     * @return \Illuminate\Session\Store
117
     */
118
    protected function createApcDriver()
119
    {
120
        return $this->createCacheBased('apc');
121
    }
122
123
    /**
124
     * Create an instance of the Memcached session driver.
125
     *
126
     * @return \Illuminate\Session\Store
127
     */
128
    protected function createMemcachedDriver()
129
    {
130
        return $this->createCacheBased('memcached');
131
    }
132
133
    /**
134
     * Create an instance of the Wincache session driver.
135
     *
136
     * @return \Illuminate\Session\Store
137
     */
138
    protected function createWincacheDriver()
139
    {
140
        return $this->createCacheBased('wincache');
141
    }
142
143
    /**
144
     * Create an instance of the Redis session driver.
145
     *
146
     * @return \Illuminate\Session\Store
147
     */
148
    protected function createRedisDriver()
149
    {
150
        $handler = $this->createCacheHandler('redis');
151
152
        $handler->getCache()->getStore()->setConnection($this->app['config']['session.connection']);
153
154
        return $this->buildSession($handler);
155
    }
156
157
    /**
158
     * Create an instance of a cache driven driver.
159
     *
160
     * @param  string  $driver
161
     * @return \Illuminate\Session\Store
162
     */
163
    protected function createCacheBased($driver)
164
    {
165
        return $this->buildSession($this->createCacheHandler($driver));
166
    }
167
168
    /**
169
     * Create the cache based session handler instance.
170
     *
171
     * @param  string  $driver
172
     * @return \Illuminate\Session\CacheBasedSessionHandler
173
     */
174
    protected function createCacheHandler($driver)
175
    {
176
        $minutes = $this->app['config']['session.lifetime'];
177
178
        return new CacheBasedSessionHandler(clone $this->app['cache']->driver($driver), $minutes);
179
    }
180
181
    /**
182
     * Build the session instance.
183
     *
184
     * @param  \SessionHandlerInterface  $handler
185
     * @return \Illuminate\Session\Store
186
     */
187
    protected function buildSession($handler)
188
    {
189
        if ($this->app['config']['session.encrypt']) {
190
            return new EncryptedStore(
191
                $this->app['config']['session.cookie'], $handler, $this->app['encrypter']
192
            );
193
        } else {
194
            return new Store($this->app['config']['session.cookie'], $handler);
195
        }
196
    }
197
198
    /**
199
     * Get the session configuration.
200
     *
201
     * @return array
202
     */
203
    public function getSessionConfig()
204
    {
205
        return $this->app['config']['session'];
206
    }
207
208
    /**
209
     * Get the default session driver name.
210
     *
211
     * @return string
212
     */
213
    public function getDefaultDriver()
214
    {
215
        return $this->app['config']['session.driver'];
216
    }
217
218
    /**
219
     * Set the default session driver name.
220
     *
221
     * @param  string  $name
222
     * @return void
223
     */
224
    public function setDefaultDriver($name)
225
    {
226
        $this->app['config']['session.driver'] = $name;
227
    }
228
}