88use Symfony \Component \HttpClient \HttpClient ;
99use Symfony \Contracts \HttpClient \Exception \TransportExceptionInterface ;
1010
11- class Wordpress
11+ abstract class Wordpress
1212{
1313 const WP_JSON_URL_PREFIX = '/wp-json/wp/v2/ ' ;
14- public const WP_JSON_URL_SUFFIX = '' ;
14+
15+ public $ type = '' ;
1516
1617 /**
1718 * @var \Symfony\Contracts\HttpClient\HttpClientInterface
@@ -65,7 +66,7 @@ public function all(int $pageSize = 10, array $filters = []): \Generator
6566 $ response = $ this ->client ->request (
6667 'GET ' ,
6768 static ::WP_JSON_URL_PREFIX .
68- static :: WP_JSON_URL_SUFFIX .
69+ $ this -> type .
6970 '? ' .
7071 http_build_query (
7172 array_merge ([
@@ -94,7 +95,7 @@ public function all(int $pageSize = 10, array $filters = []): \Generator
9495 */
9596 public function get (int $ id ): array
9697 {
97- $ response = $ this ->client ->request ('GET ' , static ::WP_JSON_URL_PREFIX . static :: WP_JSON_URL_SUFFIX . '/ ' . $ id );
98+ $ response = $ this ->client ->request ('GET ' , static ::WP_JSON_URL_PREFIX . $ this -> type . '/ ' . $ id );
9899
99100 return json_decode ($ response ->getContent (), true );
100101 }
@@ -104,7 +105,7 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
104105 try {
105106 $ response = $ this ->client ->request (
106107 'POST ' ,
107- static ::WP_JSON_URL_PREFIX . static :: WP_JSON_URL_SUFFIX . '/ ' . $ pageId . '? ' . $ key . '= ' . $ value ,
108+ static ::WP_JSON_URL_PREFIX . $ this -> type . '/ ' . $ pageId . '? ' . $ key . '= ' . $ value ,
108109
109110 [
110111 'auth_basic ' => $ authentication
@@ -127,7 +128,7 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
127128 */
128129 public function peek (int $ pageSize ): array
129130 {
130- $ peekResponse = $ this ->client ->request ('HEAD ' , static ::WP_JSON_URL_PREFIX . static :: WP_JSON_URL_SUFFIX . '?per_page= ' . $ pageSize );
131+ $ peekResponse = $ this ->client ->request ('HEAD ' , static ::WP_JSON_URL_PREFIX . $ this -> type . '?per_page= ' . $ pageSize );
131132
132133 return $ peekResponse ->getHeaders ();
133134 }
0 commit comments