@@ -12,7 +12,7 @@ abstract class Wordpress
1212{
1313 const WP_JSON_URL_PREFIX = '/wp-json/wp/v2/ ' ;
1414
15- public $ type = '' ;
15+ public ? string $ type = null ;
1616
1717 /**
1818 * @var \Symfony\Contracts\HttpClient\HttpClientInterface
@@ -52,6 +52,9 @@ public function setBaseUrl(string $baseUrl)
5252 */
5353 public function all (int $ pageSize = 10 , array $ filters = []): \Generator
5454 {
55+ if (is_null ($ this ->type )) {
56+ throw new \Exception ("Type is required for HTTPClient " );
57+ }
5558 $ peekHeaders = $ this ->peek ($ pageSize );
5659
5760 if (empty ($ peekHeaders ['x-wp-total ' ])) {
@@ -95,13 +98,21 @@ public function all(int $pageSize = 10, array $filters = []): \Generator
9598 */
9699 public function get (int $ id ): array
97100 {
101+ if (is_null ($ this ->type )) {
102+ throw new \Exception ("Type is required for HTTPClient " );
103+ }
104+
98105 $ response = $ this ->client ->request ('GET ' , static ::WP_JSON_URL_PREFIX . $ this ->type . '/ ' . $ id );
99106
100107 return json_decode ($ response ->getContent (), true );
101108 }
102109
103110 public function postMetaDataToPage (int $ pageId , string $ key , string $ value , string $ authentication )
104111 {
112+ if (is_null ($ this ->type )) {
113+ throw new \Exception ("Type is required for HTTPClient " );
114+ }
115+
105116 try {
106117 $ response = $ this ->client ->request (
107118 'POST ' ,
@@ -128,6 +139,10 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
128139 */
129140 public function peek (int $ pageSize ): array
130141 {
142+ if (is_null ($ this ->type )) {
143+ throw new \Exception ("Type is required for HTTPClient " );
144+ }
145+
131146 $ peekResponse = $ this ->client ->request ('HEAD ' , static ::WP_JSON_URL_PREFIX . $ this ->type . '?per_page= ' . $ pageSize );
132147
133148 return $ peekResponse ->getHeaders ();
0 commit comments