1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dwr\LottoClientBundle\Service; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Dwr\LottoClientBundle\Exception\LottoClientException; |
7
|
|
|
use Exception; |
8
|
|
|
use SoapClient; |
9
|
|
|
|
10
|
|
|
class LottoClient |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Types of bets |
14
|
|
|
*/ |
15
|
|
|
const DUZY_LOTEK = 'wynikiLotto'; |
16
|
|
|
const MINI_LOTEK = 'wynikiLotto'; |
17
|
|
|
const MULTI_LOTEK = 'wynikiMulti'; |
18
|
|
|
const JOKER = 'wynikiJoker'; |
19
|
|
|
const KASKADA = 'wynikiKaskada'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var SoapClient |
23
|
|
|
*/ |
24
|
|
|
private $client; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param SoapClient $client |
28
|
|
|
*/ |
29
|
|
|
public function __construct(SoapClient $client) |
30
|
|
|
{ |
31
|
|
|
$this->client = $client; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Gets recently results. |
36
|
|
|
* You can take from 1 to 10 recently results by specific type of bet. |
37
|
|
|
* |
38
|
|
|
* @param string $betType Bet type from constants. |
39
|
|
|
* @param int $numberOfResults From 1 to 10. |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getRecentlyResults($betType, $numberOfResults = 10) |
44
|
|
|
{ |
45
|
|
|
$today = new DateTime(); |
46
|
|
|
$results = $this->getResults($today, $betType); |
47
|
|
|
|
48
|
|
|
return array_slice($results, 0, $numberOfResults); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Gets recently results by date. |
53
|
|
|
* You can take from 1 to 10 recently results by specific date and type of bet. |
54
|
|
|
* |
55
|
|
|
* @param DateTime $date Date |
56
|
|
|
* @param string $betType Bet type from constants. |
57
|
|
|
* @param int $numberOfResults From 1 to 10. |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function getResultsByDate(DateTime $date, $betType, $numberOfResults = 10) |
62
|
|
|
{ |
63
|
|
|
$results = $this->getResults($date, $betType); |
64
|
|
|
|
65
|
|
|
return array_slice($results, 0, $numberOfResults); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Gets results from lotto server |
70
|
|
|
* |
71
|
|
|
* @param DateTime $date |
72
|
|
|
* @param $betType |
73
|
|
|
* |
74
|
|
|
* @return mixed |
75
|
|
|
* |
76
|
|
|
* @throws LottoClientException |
77
|
|
|
*/ |
78
|
|
|
private function getResults(DateTime $date, $betType) |
79
|
|
|
{ |
80
|
|
|
try { |
81
|
|
|
$results = $this->client |
82
|
|
|
->getSymbianWyniki($date->format('Y-m-d')) |
83
|
|
|
->$betType; |
84
|
|
|
$betName = ucfirst(str_replace('wyniki', 'wynik', $betType)); |
85
|
|
|
|
86
|
|
|
return $results->$betName; |
87
|
|
|
|
88
|
|
|
} catch (Exception $e) { |
89
|
|
|
throw new LottoClientException($e->getMessage()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|