From 8c03d5f4b38b06a85aad6c119a04d1811684d37e Mon Sep 17 00:00:00 2001 From: 4n70w4 <38257723+4n70w4@users.noreply.github.com> Date: Thu, 2 May 2019 02:04:54 +0300 Subject: [PATCH] #23 possibility of change prefix in endpoint --- src/Endpoint/Categories.php | 2 +- src/Endpoint/Comments.php | 2 +- src/Endpoint/Media.php | 2 +- src/Endpoint/Pages.php | 2 +- src/Endpoint/PostStatuses.php | 2 +- src/Endpoint/PostTypes.php | 2 +- src/Endpoint/Posts.php | 2 +- src/Endpoint/Tags.php | 2 +- src/Endpoint/Users.php | 2 +- src/WpClient.php | 19 +++++++++++++++++-- 10 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Endpoint/Categories.php b/src/Endpoint/Categories.php index 607d468..98b2686 100644 --- a/src/Endpoint/Categories.php +++ b/src/Endpoint/Categories.php @@ -13,6 +13,6 @@ class Categories extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/categories'; + return '/wp/v2/categories'; } } diff --git a/src/Endpoint/Comments.php b/src/Endpoint/Comments.php index 611e4fe..853125d 100644 --- a/src/Endpoint/Comments.php +++ b/src/Endpoint/Comments.php @@ -13,6 +13,6 @@ class Comments extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/comments'; + return '/wp/v2/comments'; } } diff --git a/src/Endpoint/Media.php b/src/Endpoint/Media.php index 6647ffd..9f31bc9 100644 --- a/src/Endpoint/Media.php +++ b/src/Endpoint/Media.php @@ -13,6 +13,6 @@ class Media extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/media'; + return '/wp/v2/media'; } } diff --git a/src/Endpoint/Pages.php b/src/Endpoint/Pages.php index ac2f823..4161efe 100644 --- a/src/Endpoint/Pages.php +++ b/src/Endpoint/Pages.php @@ -13,6 +13,6 @@ class Pages extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/pages'; + return '/wp/v2/pages'; } } diff --git a/src/Endpoint/PostStatuses.php b/src/Endpoint/PostStatuses.php index 8e70d73..6276ed3 100644 --- a/src/Endpoint/PostStatuses.php +++ b/src/Endpoint/PostStatuses.php @@ -13,6 +13,6 @@ class PostStatuses extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/statuses'; + return '/wp/v2/statuses'; } } diff --git a/src/Endpoint/PostTypes.php b/src/Endpoint/PostTypes.php index 907347c..c844a32 100644 --- a/src/Endpoint/PostTypes.php +++ b/src/Endpoint/PostTypes.php @@ -13,6 +13,6 @@ class PostTypes extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/types'; + return '/wp/v2/types'; } } diff --git a/src/Endpoint/Posts.php b/src/Endpoint/Posts.php index 7bcc94b..a88417c 100644 --- a/src/Endpoint/Posts.php +++ b/src/Endpoint/Posts.php @@ -13,6 +13,6 @@ class Posts extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/posts'; + return '/wp/v2/posts'; } } diff --git a/src/Endpoint/Tags.php b/src/Endpoint/Tags.php index 8edd362..4b87d84 100644 --- a/src/Endpoint/Tags.php +++ b/src/Endpoint/Tags.php @@ -13,6 +13,6 @@ class Tags extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/tags'; + return '/wp/v2/tags'; } } diff --git a/src/Endpoint/Users.php b/src/Endpoint/Users.php index f007458..f52ddb9 100644 --- a/src/Endpoint/Users.php +++ b/src/Endpoint/Users.php @@ -13,6 +13,6 @@ class Users extends AbstractWpEndpoint */ protected function getEndpoint() { - return '/wp-json/wp/v2/users'; + return '/wp/v2/users'; } } diff --git a/src/WpClient.php b/src/WpClient.php index c35ebe0..eab1605 100644 --- a/src/WpClient.php +++ b/src/WpClient.php @@ -40,6 +40,11 @@ class WpClient */ private $wordpressUrl; + /** + * @var string + */ + private $restApiPrefix; + /** * @var array */ @@ -49,11 +54,13 @@ class WpClient * WpClient constructor. * @param ClientInterface $httpClient * @param string $wordpressUrl + * @param string $restApiPrefix */ - public function __construct(ClientInterface $httpClient, $wordpressUrl = '') + public function __construct(ClientInterface $httpClient, $wordpressUrl = '', $restApiPrefix = 'wp-json') { $this->httpClient = $httpClient; $this->wordpressUrl = $wordpressUrl; + $this->restApiPrefix = $restApiPrefix; } /** @@ -64,6 +71,14 @@ public function setWordpressUrl($wordpressUrl) $this->wordpressUrl = $wordpressUrl; } + /** + * @param $restApiPrefix + */ + public function setRestApiPrefix($restApiPrefix) + { + $this->restApiPrefix = $restApiPrefix; + } + /** * @param AuthInterface $auth */ @@ -102,7 +117,7 @@ public function send(RequestInterface $request) } $request = $request->withUri( - $this->httpClient->makeUri($this->wordpressUrl . $request->getUri()) + $this->httpClient->makeUri($this->wordpressUrl . "/{$this->restApiPrefix}" . $request->getUri()) ); return $this->httpClient->send($request);