Open Journal Systems  3.3.0
SessionHandlerFactory.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
14 use Doctrine\DBAL\DriverManager;
15 use Symfony\Component\Cache\Adapter\AbstractAdapter;
16 use Symfony\Component\Cache\Traits\RedisClusterProxy;
17 use Symfony\Component\Cache\Traits\RedisProxy;
18 
23 {
27  public static function createHandler($connection): AbstractSessionHandler
28  {
29  if (!\is_string($connection) && !\is_object($connection)) {
30  throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, \gettype($connection)));
31  }
32 
33  switch (true) {
34  case $connection instanceof \Redis:
35  case $connection instanceof \RedisArray:
36  case $connection instanceof \RedisCluster:
37  case $connection instanceof \Predis\ClientInterface:
38  case $connection instanceof RedisProxy:
39  case $connection instanceof RedisClusterProxy:
40  return new RedisSessionHandler($connection);
41 
42  case $connection instanceof \Memcached:
43  return new MemcachedSessionHandler($connection);
44 
45  case $connection instanceof \PDO:
46  return new PdoSessionHandler($connection);
47 
48  case !\is_string($connection):
49  throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', \get_class($connection)));
50  case 0 === strpos($connection, 'file://'):
51  return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7)));
52 
53  case 0 === strpos($connection, 'redis:'):
54  case 0 === strpos($connection, 'rediss:'):
55  case 0 === strpos($connection, 'memcached:'):
56  if (!class_exists(AbstractAdapter::class)) {
57  throw new \InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection));
58  }
59  $handlerClass = 0 === strpos($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class;
60  $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
61 
62  return new $handlerClass($connection);
63 
64  case 0 === strpos($connection, 'pdo_oci://'):
65  if (!class_exists(DriverManager::class)) {
66  throw new \InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require doctrine/dbal".', $connection));
67  }
68  $connection = DriverManager::getConnection(['url' => $connection])->getWrappedConnection();
69  // no break;
70 
71  case 0 === strpos($connection, 'mssql://'):
72  case 0 === strpos($connection, 'mysql://'):
73  case 0 === strpos($connection, 'mysql2://'):
74  case 0 === strpos($connection, 'pgsql://'):
75  case 0 === strpos($connection, 'postgres://'):
76  case 0 === strpos($connection, 'postgresql://'):
77  case 0 === strpos($connection, 'sqlsrv://'):
78  case 0 === strpos($connection, 'sqlite://'):
79  case 0 === strpos($connection, 'sqlite3://'):
80  return new PdoSessionHandler($connection);
81  }
82 
83  throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
84  }
85 }
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
Definition: lib/vendor/symfony/http-foundation/Session/Storage/Handler/PdoSessionHandler.php:41
Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory
Definition: SessionHandlerFactory.php:22
Symfony\Component\HttpFoundation\Session\Storage\Handler
Definition: lib/vendor/symfony/http-foundation/Session/Storage/Handler/MemcachedSessionHandler.php:12
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
Definition: lib/vendor/symfony/http-foundation/Session/Storage/Handler/MemcachedSessionHandler.php:24
Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler
Definition: RedisSessionHandler.php:24
Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler
Definition: AbstractSessionHandler.php:23
Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler
Definition: StrictSessionHandler.php:19
Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory\createHandler
static createHandler($connection)
Definition: SessionHandlerFactory.php:27
Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler
Definition: lib/vendor/symfony/http-foundation/Session/Storage/Handler/NativeFileSessionHandler.php:21