1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mpyw\Cowitter\Traits; |
4
|
|
|
|
5
|
|
|
use mpyw\Cowitter\Helpers\CurlOptionNormalizer; |
6
|
|
|
use mpyw\Cowitter\Components\CurlInitializer; |
7
|
|
|
use mpyw\Cowitter\Components\Credential; |
8
|
|
|
|
9
|
|
|
trait BaseClientTrait |
10
|
|
|
{ |
11
|
|
|
abstract protected function getInternalCredential(); |
12
|
|
|
abstract protected function getInternalOptions(); |
13
|
|
|
abstract protected function getInternalCurl(); |
14
|
|
|
abstract protected function setInternalCredential(Credential $credential); |
15
|
|
|
abstract protected function setInternalOptions(array $options); |
16
|
|
|
abstract protected function setInternalCurl(CurlInitializer $curl); |
17
|
|
|
|
18
|
69 |
|
public function __construct(array $credentials, array $options = []) |
19
|
69 |
|
{ |
20
|
69 |
|
$this->setInternalCredential(new Credential($credentials)); |
21
|
68 |
|
$this->setInternalOptions(CurlOptionNormalizer::numerifyAll($options)); |
22
|
68 |
|
$this->setInternalCurl(new CurlInitializer($this->getInternalCredential(), $this->getInternalOptions())); |
23
|
68 |
|
} |
24
|
|
|
|
25
|
10 |
|
public function offsetGet($offset) |
26
|
10 |
|
{ |
27
|
10 |
|
return $this->getInternalCredential()->offsetGet($offset); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function offsetSet($offset, $value) |
31
|
|
|
{ |
32
|
|
|
return $this->getInternalCredential()->offsetSet($offset, $value); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function offsetUnset($offset) |
36
|
|
|
{ |
37
|
|
|
return $this->getInternalCredential()->offsetUnset($offset); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function offsetExists($offset) |
41
|
|
|
{ |
42
|
|
|
return $this->getInternalCredential()->offsetExists($offset); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function __get($key) |
46
|
|
|
{ |
47
|
|
|
return $this->getInternalCredential()->$key; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function __isset($key) |
51
|
|
|
{ |
52
|
|
|
return isset($this->getInternalCredential()->$key); |
53
|
|
|
} |
54
|
|
|
|
55
|
12 |
|
public function withCredentials(array $credentials) |
56
|
12 |
|
{ |
57
|
12 |
|
return new static( |
58
|
12 |
|
array_replace($this->getInternalCredential()->toArray(), $credentials), |
59
|
12 |
|
$this->getInternalOptions() |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
6 |
|
public function withOptions(array $options) |
64
|
6 |
|
{ |
65
|
6 |
|
return new static( |
66
|
6 |
|
$this->getInternalCredential()->toArray(), |
67
|
6 |
|
array_replace($this->getInternalOptions(), $options) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getCredentials($assoc = false) |
72
|
|
|
{ |
73
|
|
|
return $this->getInternalCredential()->toArray($assoc); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getOptions($stringify = false) |
77
|
|
|
{ |
78
|
|
|
return $stringify ? CurlOptionNormalizer::stringifyAll($this->getInternalOptions()) : $this->getInternalOptions(); |
79
|
|
|
} |
80
|
|
|
|
81
|
4 |
|
public function getAuthorizeUrl($force_login = false) |
82
|
4 |
|
{ |
83
|
4 |
|
return $this->getInternalCredential()->getAuthorizeUrl($force_login); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getAuthenticateUrl($force_login = false) |
87
|
|
|
{ |
88
|
|
|
return $this->getInternalCredential()->getAuthenticateUrl($force_login); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|