1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the fnayou/instapush-php project. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017. Aymen FNAYOU <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Fnayou\InstapushPHP; |
12
|
|
|
|
13
|
|
|
use Fnayou\InstapushPHP\Transformer\ModelTransformer; |
14
|
|
|
use Fnayou\InstapushPHP\Transformer\TransformerInterface; |
15
|
|
|
use Http\Client\HttpClient; |
16
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
17
|
|
|
use Http\Message\RequestFactory; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class InstapushClient. |
21
|
|
|
*/ |
22
|
|
|
final class InstapushClient |
23
|
|
|
{ |
24
|
|
|
/** @var \Http\Client\HttpClient */ |
25
|
|
|
private $httpClient; |
26
|
|
|
|
27
|
|
|
/** @var \Http\Message\RequestFactory */ |
28
|
|
|
private $requestFactory; |
29
|
|
|
|
30
|
|
|
/** @var \Fnayou\InstapushPHP\Transformer\TransformerInterface */ |
31
|
|
|
private $transformer; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param \Http\Client\HttpClient $httpClient |
35
|
|
|
* @param \Http\Message\RequestFactory|null $requestFactory |
36
|
|
|
* @param \Fnayou\InstapushPHP\Transformer\TransformerInterface|null $transformer |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
HttpClient $httpClient, |
40
|
|
|
RequestFactory $requestFactory = null, |
41
|
|
|
TransformerInterface $transformer = null |
42
|
|
|
) { |
43
|
|
|
$this->httpClient = $httpClient; |
44
|
|
|
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); |
45
|
|
|
$this->transformer = $transformer ?: new ModelTransformer(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param \Fnayou\InstapushPHP\HttpClientConfigurator $httpClientConfigurator |
50
|
|
|
* @param \Http\Message\RequestFactory|null $requestFactory |
51
|
|
|
* @param \Fnayou\InstapushPHP\Transformer\TransformerInterface|null $hydrator |
52
|
|
|
* |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public static function configure( |
56
|
|
|
HttpClientConfigurator $httpClientConfigurator, |
57
|
|
|
RequestFactory $requestFactory = null, |
58
|
|
|
TransformerInterface $hydrator = null |
59
|
|
|
) { |
60
|
|
|
$httpClient = $httpClientConfigurator->createConfiguredClient(); |
61
|
|
|
|
62
|
|
|
return new static($httpClient, $hydrator, $requestFactory); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $userToken |
67
|
|
|
* @param string $appIdentifier |
68
|
|
|
* @param string $appSecret |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public static function create(string $userToken, string $appIdentifier, string $appSecret) |
73
|
|
|
{ |
74
|
|
|
$httpClientConfigurator = new HttpClientConfigurator(); |
75
|
|
|
$httpClientConfigurator->setApiCredentials($userToken, $appIdentifier, $appSecret); |
76
|
|
|
|
77
|
|
|
return static::configure($httpClientConfigurator); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.