• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

predis / predis / 14450042814

14 Apr 2025 03:51PM UTC coverage: 92.662% (-0.09%) from 92.752%
14450042814

push

github

web-flow
Merge pull request #1527 from predis/vv-readme-8.0-support

7147 of 7713 relevant lines covered (92.66%)

111.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/src/Configuration/Options.php
1
<?php
2

3
/*
4
 * This file is part of the Predis package.
5
 *
6
 * (c) 2009-2020 Daniele Alessandri
7
 * (c) 2021-2025 Till Krüss
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

13
namespace Predis\Configuration;
14

15
/**
16
 * Default client options container for Predis\Client.
17
 *
18
 * Pre-defined options have their specialized handlers that can filter, convert
19
 * an lazily initialize values in a mini-DI container approach.
20
 *
21
 * {@inheritdoc}
22
 */
23
class Options implements OptionsInterface
24
{
25
    /** @var array */
26
    protected $handlers = [
27
        'aggregate' => Option\Aggregate::class,
28
        'cluster' => Option\Cluster::class,
29
        'replication' => Option\Replication::class,
30
        'connections' => Option\Connections::class,
31
        'commands' => Option\Commands::class,
32
        'exceptions' => Option\Exceptions::class,
33
        'prefix' => Option\Prefix::class,
34
        'crc16' => Option\CRC16::class,
35
    ];
36

37
    /** @var array */
38
    protected $options = [];
39

40
    /** @var array */
41
    protected $input;
42

43
    /**
44
     * @param array|null $options Named array of client options
45
     */
46
    public function __construct(?array $options = null)
1,685✔
47
    {
48
        $this->input = $options ?? [];
1,685✔
49
    }
50

51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getDefault($option)
1,667✔
55
    {
56
        if (isset($this->handlers[$option])) {
1,667✔
57
            $handler = $this->handlers[$option];
1,666✔
58
            $handler = new $handler();
1,666✔
59

60
            return $handler->getDefault($this);
1,666✔
61
        }
62
    }
63

64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function defined($option)
1,564✔
68
    {
69
        return
1,564✔
70
            array_key_exists($option, $this->options)
1,564✔
71
            || array_key_exists($option, $this->input)
1,564✔
72
        ;
1,564✔
73
    }
74

75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function __isset($option)
229✔
79
    {
80
        return (
229✔
81
            array_key_exists($option, $this->options)
229✔
82
            || array_key_exists($option, $this->input)
229✔
83
        ) && $this->__get($option) !== null;
229✔
84
    }
85

86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function __get($option)
1,679✔
90
    {
91
        if (isset($this->options[$option]) || array_key_exists($option, $this->options)) {
1,679✔
92
            return $this->options[$option];
48✔
93
        }
94

95
        if (isset($this->input[$option]) || array_key_exists($option, $this->input)) {
1,679✔
96
            $value = $this->input[$option];
1,495✔
97
            unset($this->input[$option]);
1,495✔
98

99
            if (isset($this->handlers[$option])) {
1,495✔
100
                $handler = $this->handlers[$option];
1,493✔
101
                $handler = new $handler();
1,493✔
102
                $value = $handler->filter($this, $value);
1,493✔
103
            } elseif (is_object($value) && method_exists($value, '__invoke')) {
4✔
104
                $value = $value($this);
1✔
105
            }
106

107
            return $this->options[$option] = $value;
1,495✔
108
        }
109

110
        if (isset($this->handlers[$option])) {
1,666✔
111
            return $this->options[$option] = $this->getDefault($option);
1,665✔
112
        }
113

114
        return;
30✔
115
    }
116

117
    /**
118
     * {@inheritDoc}
119
     */
120
    public function __set($option, $value)
×
121
    {
122
        $this->options[$option] = $value;
×
123
    }
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc