Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Session;
4
 
5
use Illuminate\Support\Manager;
6
 
7
/**
8
 * @mixin \Illuminate\Session\Store
9
 */
10
class SessionManager extends Manager
11
{
12
    /**
13
     * Call a custom driver creator.
14
     *
15
     * @param  string  $driver
16
     * @return mixed
17
     */
18
    protected function callCustomCreator($driver)
19
    {
20
        return $this->buildSession(parent::callCustomCreator($driver));
21
    }
22
 
23
    /**
24
     * Create an instance of the "null" session driver.
25
     *
26
     * @return \Illuminate\Session\Store
27
     */
28
    protected function createNullDriver()
29
    {
30
        return $this->buildSession(new NullSessionHandler);
31
    }
32
 
33
    /**
34
     * Create an instance of the "array" session driver.
35
     *
36
     * @return \Illuminate\Session\Store
37
     */
38
    protected function createArrayDriver()
39
    {
40
        return $this->buildSession(new ArraySessionHandler(
41
            $this->config->get('session.lifetime')
42
        ));
43
    }
44
 
45
    /**
46
     * Create an instance of the "cookie" session driver.
47
     *
48
     * @return \Illuminate\Session\Store
49
     */
50
    protected function createCookieDriver()
51
    {
52
        return $this->buildSession(new CookieSessionHandler(
53
            $this->container->make('cookie'), $this->config->get('session.lifetime')
54
        ));
55
    }
56
 
57
    /**
58
     * Create an instance of the file session driver.
59
     *
60
     * @return \Illuminate\Session\Store
61
     */
62
    protected function createFileDriver()
63
    {
64
        return $this->createNativeDriver();
65
    }
66
 
67
    /**
68
     * Create an instance of the file session driver.
69
     *
70
     * @return \Illuminate\Session\Store
71
     */
72
    protected function createNativeDriver()
73
    {
74
        $lifetime = $this->config->get('session.lifetime');
75
 
76
        return $this->buildSession(new FileSessionHandler(
77
            $this->container->make('files'), $this->config->get('session.files'), $lifetime
78
        ));
79
    }
80
 
81
    /**
82
     * Create an instance of the database session driver.
83
     *
84
     * @return \Illuminate\Session\Store
85
     */
86
    protected function createDatabaseDriver()
87
    {
88
        $table = $this->config->get('session.table');
89
 
90
        $lifetime = $this->config->get('session.lifetime');
91
 
92
        return $this->buildSession(new DatabaseSessionHandler(
93
            $this->getDatabaseConnection(), $table, $lifetime, $this->container
94
        ));
95
    }
96
 
97
    /**
98
     * Get the database connection for the database driver.
99
     *
100
     * @return \Illuminate\Database\Connection
101
     */
102
    protected function getDatabaseConnection()
103
    {
104
        $connection = $this->config->get('session.connection');
105
 
106
        return $this->container->make('db')->connection($connection);
107
    }
108
 
109
    /**
110
     * Create an instance of the APC session driver.
111
     *
112
     * @return \Illuminate\Session\Store
113
     */
114
    protected function createApcDriver()
115
    {
116
        return $this->createCacheBased('apc');
117
    }
118
 
119
    /**
120
     * Create an instance of the Memcached session driver.
121
     *
122
     * @return \Illuminate\Session\Store
123
     */
124
    protected function createMemcachedDriver()
125
    {
126
        return $this->createCacheBased('memcached');
127
    }
128
 
129
    /**
130
     * Create an instance of the Redis session driver.
131
     *
132
     * @return \Illuminate\Session\Store
133
     */
134
    protected function createRedisDriver()
135
    {
136
        $handler = $this->createCacheHandler('redis');
137
 
138
        $handler->getCache()->getStore()->setConnection(
139
            $this->config->get('session.connection')
140
        );
141
 
142
        return $this->buildSession($handler);
143
    }
144
 
145
    /**
146
     * Create an instance of the DynamoDB session driver.
147
     *
148
     * @return \Illuminate\Session\Store
149
     */
150
    protected function createDynamodbDriver()
151
    {
152
        return $this->createCacheBased('dynamodb');
153
    }
154
 
155
    /**
156
     * Create an instance of a cache driven driver.
157
     *
158
     * @param  string  $driver
159
     * @return \Illuminate\Session\Store
160
     */
161
    protected function createCacheBased($driver)
162
    {
163
        return $this->buildSession($this->createCacheHandler($driver));
164
    }
165
 
166
    /**
167
     * Create the cache based session handler instance.
168
     *
169
     * @param  string  $driver
170
     * @return \Illuminate\Session\CacheBasedSessionHandler
171
     */
172
    protected function createCacheHandler($driver)
173
    {
174
        $store = $this->config->get('session.store') ?: $driver;
175
 
176
        return new CacheBasedSessionHandler(
177
            clone $this->container->make('cache')->store($store),
178
            $this->config->get('session.lifetime')
179
        );
180
    }
181
 
182
    /**
183
     * Build the session instance.
184
     *
185
     * @param  \SessionHandlerInterface  $handler
186
     * @return \Illuminate\Session\Store
187
     */
188
    protected function buildSession($handler)
189
    {
190
        return $this->config->get('session.encrypt')
191
                ? $this->buildEncryptedSession($handler)
192
                : new Store(
193
                    $this->config->get('session.cookie'),
194
                    $handler,
195
                    $id = null,
196
                    $this->config->get('session.serialization', 'php')
197
                );
198
    }
199
 
200
    /**
201
     * Build the encrypted session instance.
202
     *
203
     * @param  \SessionHandlerInterface  $handler
204
     * @return \Illuminate\Session\EncryptedStore
205
     */
206
    protected function buildEncryptedSession($handler)
207
    {
208
        return new EncryptedStore(
209
            $this->config->get('session.cookie'),
210
            $handler,
211
            $this->container['encrypter'],
212
            $id = null,
213
            $this->config->get('session.serialization', 'php'),
214
        );
215
    }
216
 
217
    /**
218
     * Determine if requests for the same session should wait for each to finish before executing.
219
     *
220
     * @return bool
221
     */
222
    public function shouldBlock()
223
    {
224
        return $this->config->get('session.block', false);
225
    }
226
 
227
    /**
228
     * Get the name of the cache store / driver that should be used to acquire session locks.
229
     *
230
     * @return string|null
231
     */
232
    public function blockDriver()
233
    {
234
        return $this->config->get('session.block_store');
235
    }
236
 
237
    /**
238
     * Get the session configuration.
239
     *
240
     * @return array
241
     */
242
    public function getSessionConfig()
243
    {
244
        return $this->config->get('session');
245
    }
246
 
247
    /**
248
     * Get the default session driver name.
249
     *
250
     * @return string
251
     */
252
    public function getDefaultDriver()
253
    {
254
        return $this->config->get('session.driver');
255
    }
256
 
257
    /**
258
     * Set the default session driver name.
259
     *
260
     * @param  string  $name
261
     * @return void
262
     */
263
    public function setDefaultDriver($name)
264
    {
265
        $this->config->set('session.driver', $name);
266
    }
267
}