1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cp; |
4
|
|
|
|
5
|
|
|
use Cocur\Slugify\Slugify; |
6
|
|
|
use Cp\Calendar\Builder\CalendarBuilder; |
7
|
|
|
use Cp\DomainObject\Configuration; |
8
|
|
|
use Cp\Manager\ConfigurationManager; |
9
|
|
|
use Cp\Provider\PlanProvider; |
10
|
|
|
use Cp\Provider\TypeProvider; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class CapSniffer |
14
|
|
|
*/ |
15
|
|
|
class CapSniffer |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var TypeProvider |
19
|
|
|
*/ |
20
|
|
|
private $typeProvider; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var PlanProvider |
24
|
|
|
*/ |
25
|
|
|
private $planProvider; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Slugify |
29
|
|
|
*/ |
30
|
|
|
private $slug; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var CalendarBuilder |
34
|
|
|
*/ |
35
|
|
|
private $calendarBuilder; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ConfigurationManager |
39
|
|
|
*/ |
40
|
|
|
private $configurationManager; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* CapSniffer constructor. |
44
|
|
|
* |
45
|
|
|
* @param TypeProvider $typeProvider |
46
|
|
|
* @param PlanProvider $planProvider |
47
|
|
|
* @param CalendarBuilder $calendarBuilder |
48
|
|
|
* @param Slugify $slug |
49
|
|
|
* @param ConfigurationManager $configurationManager |
50
|
|
|
*/ |
51
|
3 |
|
public function __construct( |
52
|
|
|
TypeProvider $typeProvider, |
53
|
|
|
PlanProvider $planProvider, |
54
|
|
|
CalendarBuilder $calendarBuilder, |
55
|
|
|
Slugify $slug, |
56
|
|
|
ConfigurationManager $configurationManager |
57
|
|
|
) { |
58
|
3 |
|
$this->typeProvider = $typeProvider; |
59
|
3 |
|
$this->planProvider = $planProvider; |
60
|
3 |
|
$this->calendarBuilder = $calendarBuilder; |
61
|
3 |
|
$this->slug = $slug; |
62
|
3 |
|
$this->configurationManager = $configurationManager; |
63
|
3 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $typeName |
67
|
|
|
* @param string $week |
68
|
|
|
* @param string $seance |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
2 |
|
public function generateCalendar($typeName, $week, $seance) |
73
|
|
|
{ |
74
|
2 |
|
return $this->calendarBuilder->exportCalendar($this->getPlan($typeName, $week, $seance)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $typeName |
79
|
|
|
* @param string $week |
80
|
|
|
* @param string $seance |
81
|
|
|
*/ |
82
|
1 |
|
public function writeCalendar($typeName, $week, $seance) |
83
|
|
|
{ |
84
|
1 |
|
file_put_contents( |
85
|
1 |
|
__DIR__.'/../../'.$this->getFileName($typeName, $week, $seance), |
86
|
1 |
|
$this->generateCalendar($typeName, $week, $seance) |
87
|
1 |
|
); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $typeName |
92
|
|
|
* @param string $week |
93
|
|
|
* @param string $seance |
94
|
|
|
* |
95
|
|
|
* @return Plan |
|
|
|
|
96
|
|
|
*/ |
97
|
3 |
|
public function getPlan($typeName, $week, $seance) |
98
|
|
|
{ |
99
|
3 |
|
$configuration = $this->configurationManager->createConfiguration($typeName, $week, $seance); |
100
|
3 |
|
$plan = $this->planProvider->getPlanByConfiguration($configuration); |
101
|
3 |
|
$plan->setConfiguration($configuration); |
102
|
|
|
|
103
|
3 |
|
return $plan; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $typeName |
108
|
|
|
* @param string $week |
109
|
|
|
* @param string $seance |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
2 |
|
public function getFileName($typeName, $week, $seance) |
114
|
|
|
{ |
115
|
2 |
|
return $this->slug->slugify($this->getPlan($typeName, $week, $seance)->getName()).'.ics'; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function testConfigurationParse() |
119
|
|
|
{ |
120
|
|
|
$result = $this->configurationManager->findConfigurationsByType('plan-entrainement-10km'); |
121
|
|
|
var_dump($result); die; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.