1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cp\Manager; |
4
|
|
|
|
5
|
|
|
use Cp\DomainObject\Configuration; |
6
|
|
|
use Cp\Parser\ConfigurationParser; |
7
|
|
|
use Cp\Provider\TypeProvider; |
8
|
|
|
use Doctrine\Common\Cache\MemcachedCache; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ConfigurationManager |
12
|
|
|
*/ |
13
|
|
|
class ConfigurationManager |
14
|
|
|
{ |
15
|
|
|
const CACHE_KEY = 'configuration.list'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var TypeProvider |
19
|
|
|
*/ |
20
|
|
|
private $typeProvider; |
21
|
|
|
|
22
|
|
|
/** |
23
|
1 |
|
* @var ConfigurationParser |
24
|
|
|
*/ |
25
|
1 |
|
protected $configurationParser; |
26
|
1 |
|
|
27
|
|
|
/** |
28
|
|
|
* @var MemcachedCache |
29
|
|
|
*/ |
30
|
|
|
protected $memcache; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* ConfigurationManager constructor. |
34
|
|
|
* |
35
|
1 |
|
* @param TypeProvider $typeProvider |
36
|
|
|
* @param ConfigurationParser $configurationParser |
37
|
1 |
|
* @param MemcachedCache $memcachedCache |
38
|
|
|
*/ |
39
|
1 |
|
public function __construct( |
40
|
1 |
|
TypeProvider $typeProvider, |
41
|
1 |
|
ConfigurationParser $configurationParser, |
42
|
1 |
|
MemcachedCache $memcachedCache |
43
|
|
|
) { |
44
|
1 |
|
$this->typeProvider = $typeProvider; |
45
|
|
|
$this->configurationParser = $configurationParser; |
46
|
|
|
$this->memcache = $memcachedCache; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $typeName |
51
|
|
|
* @param int $week |
52
|
|
|
* @param int $seance |
53
|
|
|
* |
54
|
|
|
* @return Configuration |
55
|
|
|
*/ |
56
|
|
|
public function createConfiguration($typeName, $week, $seance) |
57
|
|
|
{ |
58
|
|
|
$type = $this->typeProvider->getTypeByName($typeName); |
59
|
|
|
|
60
|
|
|
$configuration = new Configuration(); |
61
|
|
|
$configuration->setType($type); |
62
|
|
|
$configuration->setNumberOfWeek($week); |
63
|
|
|
$configuration->setNumberOfSeance($seance); |
64
|
|
|
|
65
|
|
|
return $configuration; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $typeName |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function findConfigurationsByType($typeName) |
74
|
|
|
{ |
75
|
|
|
$configurationForType = $this->memcache->fetch(self::CACHE_KEY.$typeName); |
76
|
|
|
|
77
|
|
|
if (false === $configurationForType) { |
78
|
|
|
$configurationForType = json_decode( |
79
|
|
|
$this |
80
|
|
|
->configurationParser |
81
|
|
|
->parseToJson('/Users/perso/Workspace/cap-sniffer-api/web/mock/plan-10-home.html') |
82
|
|
|
, true); |
83
|
|
|
$this->memcache->save(self::CACHE_KEY.$typeName, $configurationForType, 3600); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$configurationList = []; |
87
|
|
|
foreach ($configurationForType as $conf) { |
88
|
|
|
$configuration = new Configuration(); |
89
|
|
|
$configuration->setType($typeName); |
90
|
|
|
$configuration->setNumberOfSeance($conf['seance']); |
91
|
|
|
$configuration->setNumberOfWeek($conf['week']); |
92
|
|
|
|
93
|
|
|
$configurationList[] = $configuration; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $configurationList; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|