123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
-
- namespace Illuminate\Session;
-
- use Illuminate\Support\Manager;
-
- class SessionManager extends Manager
- {
- /**
- * Call a custom driver creator.
- *
- * @param string $driver
- * @return mixed
- */
- protected function callCustomCreator($driver)
- {
- return $this->buildSession(parent::callCustomCreator($driver));
- }
-
- /**
- * Create an instance of the "array" session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createArrayDriver()
- {
- return $this->buildSession(new NullSessionHandler);
- }
-
- /**
- * Create an instance of the "cookie" session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createCookieDriver()
- {
- return $this->buildSession(new CookieSessionHandler(
- $this->app['cookie'], $this->app['config']['session.lifetime']
- ));
- }
-
- /**
- * Create an instance of the file session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createFileDriver()
- {
- return $this->createNativeDriver();
- }
-
- /**
- * Create an instance of the file session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createNativeDriver()
- {
- $lifetime = $this->app['config']['session.lifetime'];
-
- return $this->buildSession(new FileSessionHandler(
- $this->app['files'], $this->app['config']['session.files'], $lifetime
- ));
- }
-
- /**
- * Create an instance of the database session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createDatabaseDriver()
- {
- $table = $this->app['config']['session.table'];
-
- $lifetime = $this->app['config']['session.lifetime'];
-
- return $this->buildSession(new DatabaseSessionHandler(
- $this->getDatabaseConnection(), $table, $lifetime, $this->app
- ));
- }
-
- /**
- * Get the database connection for the database driver.
- *
- * @return \Illuminate\Database\Connection
- */
- protected function getDatabaseConnection()
- {
- $connection = $this->app['config']['session.connection'];
-
- return $this->app['db']->connection($connection);
- }
-
- /**
- * Create an instance of the APC session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createApcDriver()
- {
- return $this->createCacheBased('apc');
- }
-
- /**
- * Create an instance of the Memcached session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createMemcachedDriver()
- {
- return $this->createCacheBased('memcached');
- }
-
- /**
- * Create an instance of the Redis session driver.
- *
- * @return \Illuminate\Session\Store
- */
- protected function createRedisDriver()
- {
- $handler = $this->createCacheHandler('redis');
-
- $handler->getCache()->getStore()->setConnection(
- $this->app['config']['session.connection']
- );
-
- return $this->buildSession($handler);
- }
-
- /**
- * Create an instance of a cache driven driver.
- *
- * @param string $driver
- * @return \Illuminate\Session\Store
- */
- protected function createCacheBased($driver)
- {
- return $this->buildSession($this->createCacheHandler($driver));
- }
-
- /**
- * Create the cache based session handler instance.
- *
- * @param string $driver
- * @return \Illuminate\Session\CacheBasedSessionHandler
- */
- protected function createCacheHandler($driver)
- {
- $store = $this->app['config']->get('session.store') ?: $driver;
-
- return new CacheBasedSessionHandler(
- clone $this->app['cache']->store($store),
- $this->app['config']['session.lifetime']
- );
- }
-
- /**
- * Build the session instance.
- *
- * @param \SessionHandlerInterface $handler
- * @return \Illuminate\Session\Store
- */
- protected function buildSession($handler)
- {
- if ($this->app['config']['session.encrypt']) {
- return $this->buildEncryptedSession($handler);
- }
-
- return new Store($this->app['config']['session.cookie'], $handler);
- }
-
- /**
- * Build the encrypted session instance.
- *
- * @param \SessionHandlerInterface $handler
- * @return \Illuminate\Session\EncryptedStore
- */
- protected function buildEncryptedSession($handler)
- {
- return new EncryptedStore(
- $this->app['config']['session.cookie'], $handler, $this->app['encrypter']
- );
- }
-
- /**
- * Get the session configuration.
- *
- * @return array
- */
- public function getSessionConfig()
- {
- return $this->app['config']['session'];
- }
-
- /**
- * Get the default session driver name.
- *
- * @return string
- */
- public function getDefaultDriver()
- {
- return $this->app['config']['session.driver'];
- }
-
- /**
- * Set the default session driver name.
- *
- * @param string $name
- * @return void
- */
- public function setDefaultDriver($name)
- {
- $this->app['config']['session.driver'] = $name;
- }
- }
|