1515
1616namespace JBZoo \HttpClient ;
1717
18- use JBZoo \Data \JSON ;
18+ use JBZoo \Data \Data ;
19+
20+ use function JBZoo \Utils \bool ;
21+ use function JBZoo \Utils \int ;
1922
2023/**
2124 * Class Options
2225 * @package JBZoo\HttpClient
2326 */
24- class Options extends JSON
27+ class Options
2528{
2629 public const DEFAULT_METHOD = 'GET ' ;
2730 public const DEFAULT_DRIVER = 'Guzzle ' ;
@@ -36,7 +39,7 @@ class Options extends JSON
3639 * @var array
3740 */
3841 protected $ default = [
39- 'auth ' => false ,
42+ 'auth ' => [] ,
4043 'headers ' => [],
4144 'driver ' => self ::DEFAULT_DRIVER ,
4245 'timeout ' => self ::DEFAULT_TIMEOUT ,
@@ -47,86 +50,99 @@ class Options extends JSON
4750 'user_agent ' => self ::DEFAULT_USER_AGENT ,
4851 ];
4952
53+ /**
54+ * @var Data
55+ */
56+ protected $ data ;
57+
5058 /**
5159 * Response constructor.
5260 * @param array $data
5361 */
54- public function __construct ($ data = [])
62+ public function __construct (array $ data = [])
5563 {
56- $ data = array_merge ($ this ->default , $ data );
57- parent ::__construct ($ data );
64+ $ this ->data = new Data (array_merge ($ this ->default , $ data ));
5865 }
5966
6067 /**
61- * @return array
68+ * @return array|null
6269 */
63- public function getAuth ()
70+ public function getAuth (): ? array
6471 {
65- return $ this ->get ('auth ' , false ) ;
72+ return ( array ) $ this ->data -> get ('auth ' , []) ?: null ;
6673 }
6774
6875 /**
6976 * @return array
7077 */
71- public function getHeaders ()
78+ public function getHeaders (): array
7279 {
73- return $ this ->get ('headers ' , []);
80+ return ( array ) $ this -> data ->get ('headers ' , []);
7481 }
7582
7683 /**
7784 * @return string
7885 */
79- public function getDriver ()
86+ public function getDriver (): string
8087 {
81- return $ this ->get ('driver ' , self ::DEFAULT_DRIVER , 'ucfirst ' );
88+ return ( string ) $ this -> data ->get ('driver ' , self ::DEFAULT_DRIVER , 'ucfirst ' );
8289 }
8390
8491 /**
8592 * @return int
8693 */
87- public function getTimeout ()
94+ public function getTimeout (): int
8895 {
89- return $ this ->get ('timeout ' , self ::DEFAULT_TIMEOUT , 'int ' );
96+ return int ( $ this ->data -> get ('timeout ' , self ::DEFAULT_TIMEOUT , 'int ' ) );
9097 }
9198
9299 /**
93100 * @return bool
94101 */
95- public function isVerify ()
102+ public function isVerify (): bool
96103 {
97- return $ this ->get ('verify ' , self ::DEFAULT_VERIFY , 'bool ' );
104+ return bool ( $ this ->data -> get ('verify ' , self ::DEFAULT_VERIFY , 'bool ' ) );
98105 }
99106
100107 /**
101108 * @return bool
102109 */
103- public function showException ()
110+ public function allowException (): bool
104111 {
105- return $ this ->get ('exceptions ' , self ::DEFAULT_EXCEPTIONS , 'bool ' );
112+ return bool ( $ this ->data -> get ('exceptions ' , self ::DEFAULT_EXCEPTIONS , 'bool ' ) );
106113 }
107114
108115 /**
109116 * @return bool
110117 */
111- public function isAllowRedirects ()
118+ public function isAllowRedirects (): bool
112119 {
113- return $ this ->get ('allow_redirects ' , self ::DEFAULT_ALLOW_REDIRECTS , 'bool ' );
120+ return bool ( $ this ->data -> get ('allow_redirects ' , self ::DEFAULT_ALLOW_REDIRECTS , 'bool ' ) );
114121 }
115122
116123 /**
117124 * @return int
118125 */
119- public function getMaxRedirects ()
126+ public function getMaxRedirects (): int
120127 {
121- return $ this ->get ('max_redirects ' , self ::DEFAULT_MAX_REDIRECTS , 'int ' );
128+ return int ( $ this ->data -> get ('max_redirects ' , self ::DEFAULT_MAX_REDIRECTS , 'int ' ) );
122129 }
123130
124131 /**
125132 * @param string $suffix
126133 * @return string
127134 */
128- public function getUserAgent ($ suffix )
135+ public function getUserAgent (string $ suffix ): string
136+ {
137+ $ packageName = (string )$ this ->data ->get ('user_agent ' , self ::DEFAULT_USER_AGENT );
138+ return "{$ packageName } ( {$ suffix }) " ;
139+ }
140+
141+ /**
142+ * @return array
143+ */
144+ public function toArray (): array
129145 {
130- return $ this ->get ( ' user_agent ' , self :: DEFAULT_USER_AGENT ) . " ( { $ suffix } ) " ;
146+ return $ this ->data -> getArrayCopy () ;
131147 }
132148}
0 commit comments