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

rich-id / maintenance-bundle / #21

pending completion
#21

push

web-flow
Merge 87a5766ae into 6218b6a03

22 of 22 new or added lines in 1 file covered. (100.0%)

132 of 154 relevant lines covered (85.71%)

2.59 hits per line

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

0.0
/src/Infrastructure/Driver/RedisDriver.php
1
<?php
2

3
namespace RichId\MaintenanceBundle\Infrastructure\Driver;
4

5
use Lexik\Bundle\MaintenanceBundle\Drivers\AbstractDriver;
6
use Lexik\Bundle\MaintenanceBundle\Drivers\DriverTtlInterface;
7
use Symfony\Component\Cache\Traits\RedisTrait;
8

9
class RedisDriver extends AbstractDriver implements DriverTtlInterface
10
{
11
    use RedisTrait;
12

13
    const VALUE_TO_STORE = "maintenance";
14

15
    /** @param array<string, mixed> $options */
16
    public function __construct(array $options = array())
17
    {
18
        parent::__construct($options);
×
19

20
        if (!isset($options['key_name'])) {
×
21
            throw new \InvalidArgumentException('$options[\'key_name\'] must be defined if Driver Redis configuration is used');
×
22
        }
23

24
        if (!isset($options['redis_dsn'])) {
×
25
            throw new \InvalidArgumentException('$options[\'redis_dsn\'] must be defined if Driver Redis configuration is used');
×
26
        }
27

28
        if (isset($options['ttl']) && !is_int($options['ttl'])) {
×
29
            throw new \InvalidArgumentException('$options[\'ttl\'] should be an integer if Driver Redis configuration is used');
×
30
        }
31

32
        $this->redis = self::createConnection($options['redis_dsn']);
×
33
    }
×
34

35
    protected function createLock()
36
    {
37
        if (!isset($this->options['ttl']) || $this->options['ttl'] <= 0) {
×
38
            return $this->redis->set($this->options['key_name'], self::VALUE_TO_STORE);
×
39
        }
40

41
        return $this->redis->setex($this->options['key_name'], $this->options['ttl'], self::VALUE_TO_STORE);
×
42
    }
43

44
    protected function createUnlock()
45
    {
46
        return $this->redis->del($this->options['key_name']) > 0;
×
47
    }
48

49
    public function isExists()
50
    {
51
        return $this->redis->exists($this->options['key_name']) > 0;
×
52
    }
53

54
    public function getMessageLock($resultTest)
55
    {
56
        $key = $resultTest ? 'lexik_maintenance.success_lock_redis' : 'lexik_maintenance.not_success_lock';
×
57

58
        return $this->translator->trans($key, array(), 'maintenance');
×
59
    }
60

61
    public function getMessageUnlock($resultTest)
62
    {
63
        $key = $resultTest ? 'lexik_maintenance.success_unlock' : 'lexik_maintenance.not_success_unlock';
×
64

65
        return $this->translator->trans($key, array(), 'maintenance');
×
66
    }
67

68
    public function setTtl($value): void
69
    {
70
        $this->options['ttl'] = $value;
×
71
    }
×
72

73
    public function getTtl()
74
    {
75
        return $this->options['ttl'];
×
76
    }
77

78
    public function hasTtl()
79
    {
80
        return isset($this->options['ttl']);
×
81
    }
82
}
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

© 2025 Coveralls, Inc