Repository navigation
Expand file tree
/
Copy pathPredisFactory.php
More file actions
99 lines (83 loc) · 2.37 KB
/
Copy pathPredisFactory.php
File metadata and controls
99 lines (83 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Bolt\Session\Handler\Factory;
use Bolt\Common\Deprecated;
use Bolt\Session\OptionsBag;
use Predis;
/**
* Factory for creating Predis instances from Session options.
*
* @author Carson Full <carsonfull@gmail.com>
*/
class PredisFactory extends AbstractFactory
{
/**
* Constructor.
*/
public function __construct()
{
if (!class_exists('Predis\Client')) {
throw new \RuntimeException('Unable to use "predis" session handler as the Predis library is not installed.');
}
}
/**
* Creates a Predis instance from the session options.
*
* @param OptionsBag $sessionOptions
*
* @return Predis\Client
*/
public function create(OptionsBag $sessionOptions)
{
$connections = $this->parse($sessionOptions);
$options = $this->parseOptions($sessionOptions);
return new Predis\Client($connections, $options);
}
/**
* Parse Predis options from session options.
*
* @param OptionsBag $sessionOptions
*
* @return array
*/
protected function parseOptions(OptionsBag $sessionOptions)
{
$options = $sessionOptions->get('options', []);
if ($sessionOptions->get('prefix')) {
Deprecated::warn('Specifying "prefix" directly in session config', 1.0, 'Move it under the "options" key.');
$options['prefix'] = $sessionOptions->get('prefix');
}
return $options;
}
/**
* {@inheritdoc}
*/
protected function parseConnectionsFromOptions(OptionsBag $options)
{
$connections = parent::parseConnectionsFromOptions($options);
// If only one connection, don't give list to Predis since it will unnecessarily use cluster logic.
if (count($connections) === 1 && array_key_exists(0, $connections)) {
$connections = $connections[0];
}
return $connections;
}
/**
* {@inheritdoc}
*/
protected function parseConnectionItemFromOptions($item)
{
return $item;
}
/**
* {@inheritdoc}
*/
protected function parseConnectionsFromSavePath($savePath)
{
throw new \InvalidArgumentException('Using "save_path" is unsupported with "predis" session handler.');
}
/**
* {@inheritdoc}
*/
protected function parseConnectionItemFromSavePath($path)
{
}
}