1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Client; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Client\Api\ActivityProfileApiClient; |
15
|
|
|
use Xabbuh\XApi\Client\Api\AgentProfileApiClient; |
16
|
|
|
use Xabbuh\XApi\Client\Api\ApiClient; |
17
|
|
|
use Xabbuh\XApi\Client\Api\StateApiClient; |
18
|
|
|
use Xabbuh\XApi\Client\Api\StatementsApiClient; |
19
|
|
|
use Xabbuh\XApi\Client\Request\HandlerInterface; |
20
|
|
|
use Xabbuh\XApi\Serializer\SerializerRegistryInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* An Experience API client. |
24
|
|
|
* |
25
|
|
|
* @author Christian Flothmann <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
final class XApiClient implements XApiClientInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var SerializerRegistryInterface |
31
|
|
|
*/ |
32
|
|
|
private $serializerRegistry; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param HandlerInterface $requestHandler The HTTP request handler |
36
|
|
|
* @param SerializerRegistryInterface $serializerRegistry The serializer registry |
37
|
|
|
* @param string $version The xAPI version |
38
|
|
|
*/ |
39
|
|
|
public function __construct(HandlerInterface $requestHandler, SerializerRegistryInterface $serializerRegistry, $version) |
40
|
|
|
{ |
41
|
|
|
$this->requestHandler = $requestHandler; |
|
|
|
|
42
|
|
|
$this->serializerRegistry = $serializerRegistry; |
43
|
|
|
$this->version = $version; |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritDoc} |
48
|
|
|
*/ |
49
|
|
|
public function getStatementsApiClient() |
50
|
|
|
{ |
51
|
|
|
return new StatementsApiClient( |
52
|
|
|
$this->requestHandler, |
53
|
|
|
$this->version, |
54
|
|
|
$this->serializerRegistry->getStatementSerializer(), |
|
|
|
|
55
|
|
|
$this->serializerRegistry->getStatementResultSerializer(), |
|
|
|
|
56
|
|
|
$this->serializerRegistry->getActorSerializer() |
|
|
|
|
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritDoc} |
62
|
|
|
*/ |
63
|
|
|
public function getStateApiClient() |
64
|
|
|
{ |
65
|
|
|
return new StateApiClient( |
66
|
|
|
$this->requestHandler, |
67
|
|
|
$this->version, |
68
|
|
|
$this->serializerRegistry->getDocumentDataSerializer(), |
|
|
|
|
69
|
|
|
$this->serializerRegistry->getActorSerializer() |
|
|
|
|
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritDoc} |
75
|
|
|
*/ |
76
|
|
|
public function getActivityProfileApiClient() |
77
|
|
|
{ |
78
|
|
|
return new ActivityProfileApiClient( |
79
|
|
|
$this->requestHandler, |
80
|
|
|
$this->version, |
81
|
|
|
$this->serializerRegistry->getDocumentDataSerializer() |
|
|
|
|
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
|
|
public function getAgentProfileApiClient() |
89
|
|
|
{ |
90
|
|
|
return new AgentProfileApiClient( |
91
|
|
|
$this->requestHandler, |
92
|
|
|
$this->version, |
93
|
|
|
$this->serializerRegistry->getDocumentDataSerializer(), |
|
|
|
|
94
|
|
|
$this->serializerRegistry->getActorSerializer() |
|
|
|
|
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: