Completed
Push — 8.7 ( b6d8c1...3ac046 )
by Markus
06:49
created

IdStore::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace DMK\MKSamlAuth\Store;
4
5
use LightSaml\Store\Id\IdStoreInterface;
6
use TYPO3\CMS\Core\Cache\CacheManager;
7
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
8
use TYPO3\CMS\Core\SingletonInterface;
9
10
class IdStore implements IdStoreInterface, SingletonInterface
11
{
12
    const CACHE_KEY = 'mksamlauth_idstore';
13
14
    /**
15
     * @var FrontendInterface
16
     */
17
    private $cache;
18
19
    public function injectCacheManager(CacheManager $cacheManager)
20
    {
21
        $this->cache = $cacheManager->getCache(self::CACHE_KEY);
22
    }
23
24
    public function set($entityId, $id, \DateTime $expiryTime)
25
    {
26
        $now = new \DateTime();
27
28
        $this->cache->set(
29
            md5($entityId.$id),
30
            md5($entityId.$id),
31
            [],
32
            $expiryTime->getTimestamp() - $now->getTimestamp()
33
        );
34
    }
35
36
    public function has($entityId, $id)
37
    {
38
        return $this->cache->has(md5($entityId.$id));
39
    }
40
}
41