1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dekalee\AdbackAnalyticsBundle\Driver; |
4
|
|
|
|
5
|
|
|
use Dekalee\AdbackAnalytics\Driver\ScriptCacheInterface; |
6
|
|
|
use Dekalee\AdbackAnalytics\Driver\SqlScriptCache; |
7
|
|
|
use Dekalee\AdbackAnalyticsBundle\Entity\ApiCache; |
8
|
|
|
use Dekalee\AdbackAnalyticsBundle\Repository\ApiCacheRepository; |
9
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DoctrineScriptCache |
13
|
|
|
*/ |
14
|
|
|
class DoctrineScriptCache extends SqlScriptCache implements ScriptCacheInterface |
15
|
|
|
{ |
16
|
|
|
protected $repository; |
17
|
|
|
protected $entityManager; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param ApiCacheRepository $repository |
21
|
|
|
* @param ObjectManager $manager |
22
|
|
|
*/ |
23
|
|
|
public function __construct(ApiCacheRepository $repository, ObjectManager $manager) |
24
|
|
|
{ |
25
|
|
|
$this->repository = $repository; |
26
|
|
|
$this->entityManager = $manager; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $key |
31
|
|
|
* |
32
|
|
|
* @return string|null |
33
|
|
|
*/ |
34
|
|
|
protected function get($key) |
35
|
|
|
{ |
36
|
|
|
$element = $this->repository->findOneByKey($key); |
37
|
|
|
|
38
|
|
|
if ($element instanceof ApiCache) { |
39
|
|
|
return $element->getValue(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return null; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $key |
47
|
|
|
* @param string $value |
48
|
|
|
*/ |
49
|
|
|
protected function set($key, $value) |
50
|
|
|
{ |
51
|
|
|
$element = $this->repository->findOneByKey($key); |
52
|
|
|
|
53
|
|
|
if (!$element instanceof ApiCache) { |
54
|
|
|
$element = new ApiCache(); |
55
|
|
|
$element->setKey($key); |
56
|
|
|
$this->entityManager->persist($element); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$element->setValue($value); |
60
|
|
|
|
61
|
|
|
$this->entityManager->flush($element); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $key |
66
|
|
|
*/ |
67
|
|
|
protected function clear($key) |
68
|
|
|
{ |
69
|
|
|
$element = $this->repository->findOneByKey($key); |
70
|
|
|
|
71
|
|
|
if (!$element instanceof ApiCache) { |
72
|
|
|
$this->entityManager->remove($element); |
|
|
|
|
73
|
|
|
$this->entityManager->flush($element); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: