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

craue / CraueConfigBundle / 5901672069

pending completion
5901672069

Pull #62

github

web-flow
Merge 668619b46 into 288728580
Pull Request #62: also update the cache when updating a setting entity directly

7 of 7 new or added lines in 2 files covered. (100.0%)

200 of 210 relevant lines covered (95.24%)

17.79 hits per line

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

86.96
/CacheAdapter/SymfonyCacheComponentAdapter.php
1
<?php
2

3
namespace Craue\ConfigBundle\CacheAdapter;
4

5
use Psr\Cache\CacheItemPoolInterface;
6
use Psr\SimpleCache\CacheInterface;
7
use Symfony\Component\Cache\Adapter\Psr16Adapter;
8

9
/**
10
 * @author Christian Raue <christian.raue@gmail.com>
11
 * @copyright 2011-2023 Christian Raue
12
 * @license http://opensource.org/licenses/mit-license.php MIT License
13
 */
14
class SymfonyCacheComponentAdapter implements CacheAdapterInterface {
15

16
        /**
17
         * @var CacheItemPoolInterface
18
         */
19
        private $cache;
20

21
        public function __construct($cache) {
22
                if ($cache instanceof CacheItemPoolInterface) {
21✔
23
                        $this->cache = $cache;
19✔
24
                        return;
19✔
25
                }
26

27
                if ($cache instanceof CacheInterface) {
2✔
28
                        @trigger_error(sprintf('Configuring a cache of type %s is deprecated since CraueConfigBundle 2.2.1. Use %s instead.', CacheInterface::class, CacheItemPoolInterface::class), E_USER_DEPRECATED);
×
29

30
                        $this->cache = new Psr16Adapter($cache);
×
31
                        return;
×
32
                }
33

34
                throw new \InvalidArgumentException(sprintf('Expected argument of type "%s" or "%s", but "%s" given.',
2✔
35
                                CacheItemPoolInterface::class,
2✔
36
                                CacheInterface::class,
2✔
37
                                is_object($cache) ? get_class($cache) : gettype($cache)));
2✔
38
        }
39

40
        public function clear() {
41
                return $this->cache->clear();
14✔
42
        }
43

44
        public function has($key) {
45
                return $this->cache->hasItem($key);
18✔
46
        }
47

48
        public function get($key) {
49
                return $this->cache->getItem($key)->get();
14✔
50
        }
51

52
        public function set($key, $value) {
53
                $cacheItem = $this->cache->getItem($key);
14✔
54
                $cacheItem->set($value);
14✔
55

56
                return $this->cache->save($cacheItem);
14✔
57
        }
58

59
        public function setMultiple(array $keysAndValues) {
60
                foreach ($keysAndValues as $key => $value) {
7✔
61
                        $cacheItem = $this->cache->getItem($key);
7✔
62
                        $cacheItem->set($value);
7✔
63
                        if (!$this->cache->saveDeferred($cacheItem)) {
7✔
64
                                return false;
1✔
65
                        }
66
                }
67

68
                return $this->cache->commit();
6✔
69
        }
70

71
}
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