|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IBM\Watson\ToneAnalyzer; |
|
4
|
|
|
|
|
5
|
|
|
use Http\Client\HttpClient; |
|
6
|
|
|
use Http\Discovery\HttpClientDiscovery; |
|
7
|
|
|
use IBM\Watson\Common\HttpClient\Builder; |
|
8
|
|
|
use IBM\Watson\Common\Hydrator\HydratorInterface; |
|
9
|
|
|
use IBM\Watson\Common\Hydrator\ModelHydrator; |
|
10
|
|
|
use IBM\Watson\Common\RequestBuilder; |
|
11
|
|
|
|
|
12
|
|
|
final class Client |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Base tone analyzer uri |
|
16
|
|
|
*/ |
|
17
|
|
|
const BASE_URI = 'https://gateway.watsonplatform.net/tone-analyzer'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Http\Client\HttpClient |
|
21
|
|
|
*/ |
|
22
|
|
|
private $httpClient; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \IBM\Watson\Common\Hydrator\ModelHydrator |
|
26
|
|
|
*/ |
|
27
|
|
|
private $hydrator; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \IBM\Watson\Common\RequestBuilder |
|
31
|
|
|
*/ |
|
32
|
|
|
private $requestBuilder; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Client constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param \Http\Client\HttpClient|null $httpClient |
|
38
|
|
|
* @param \IBM\Watson\Common\Hydrator\HydratorInterface|null $hydrator |
|
39
|
|
|
* @param \IBM\Watson\Common\RequestBuilder|null $requestBuilder |
|
40
|
|
|
* |
|
41
|
|
|
* @throws \Http\Discovery\Exception\NotFoundException |
|
42
|
|
|
*/ |
|
43
|
9 |
|
public function __construct( |
|
44
|
|
|
HttpClient $httpClient = null, |
|
45
|
|
|
HydratorInterface $hydrator = null, |
|
46
|
|
|
RequestBuilder $requestBuilder = null |
|
47
|
|
|
) { |
|
48
|
9 |
|
$this->httpClient = $httpClient ?: HttpClientDiscovery::find(); |
|
49
|
9 |
|
$this->hydrator = $hydrator ?: new ModelHydrator; |
|
|
|
|
|
|
50
|
9 |
|
$this->requestBuilder = $requestBuilder ?: new RequestBuilder; |
|
51
|
9 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Create tone analyzer client with username and password |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $username |
|
57
|
|
|
* @param string $password |
|
58
|
|
|
* |
|
59
|
|
|
* @return \IBM\Watson\ToneAnalyzer\Client |
|
60
|
|
|
* |
|
61
|
|
|
* @throws \Http\Discovery\Exception\NotFoundException |
|
62
|
|
|
* @throws \RuntimeException |
|
63
|
|
|
* @throws \InvalidArgumentException |
|
64
|
|
|
*/ |
|
65
|
9 |
|
public static function create($username, $password) |
|
66
|
|
|
{ |
|
67
|
9 |
|
$httpClient = (new Builder()) |
|
68
|
9 |
|
->withEndpoint(static::BASE_URI) |
|
69
|
9 |
|
->withCredentials($username, $password) |
|
70
|
9 |
|
->createConfiguredClient(); |
|
71
|
|
|
|
|
72
|
9 |
|
return new self($httpClient); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Create tone api request |
|
77
|
|
|
* |
|
78
|
|
|
* @return \IBM\Watson\ToneAnalyzer\Api\Tone |
|
79
|
|
|
*/ |
|
80
|
3 |
|
public function tone() |
|
81
|
|
|
{ |
|
82
|
3 |
|
return new Api\Tone($this->httpClient, $this->hydrator, $this->requestBuilder); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Create tone chat api request |
|
87
|
|
|
* |
|
88
|
|
|
* @return \IBM\Watson\ToneAnalyzer\Api\ToneChat |
|
89
|
|
|
*/ |
|
90
|
3 |
|
public function toneChat() |
|
91
|
|
|
{ |
|
92
|
3 |
|
return new Api\ToneChat($this->httpClient, $this->hydrator, $this->requestBuilder); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.