diff --git a/src/Endpoint/AbstractWpSubEndpoint.php b/src/Endpoint/AbstractWpSubEndpoint.php new file mode 100644 index 0000000..4cb314e --- /dev/null +++ b/src/Endpoint/AbstractWpSubEndpoint.php @@ -0,0 +1,47 @@ +postRevisions()->setParent(45)->get(); + * + * @package Vnn\WpApiClient\Endpoint + */ +abstract class AbstractWpSubEndpoint extends AbstractWpEndpoint +{ + /** + * The ID of the parent entity. + * @var int + */ + private $parentId = null; + + /** + * Set the ID of the parent entity. + * @param int $parent + * @return AbstractWpEndpoint + */ + public function setParent($parent) + { + $this->parentId = $parent; + return $this; + } + + /** + * Builds the actual endpoint URL using the provided parent ID and the endpoint pattern. + * @param string $pattern + * @return string + * @throws \LogicException + */ + protected function buildEndpoint($pattern) + { + if ($this->parentId === null) { + throw new \LogicException(static::class . '::setParent() not called!', 1539454211); + } + return sprintf($pattern, $this->parentId); + } +} diff --git a/src/Endpoint/PostRevisions.php b/src/Endpoint/PostRevisions.php new file mode 100644 index 0000000..eb2e23d --- /dev/null +++ b/src/Endpoint/PostRevisions.php @@ -0,0 +1,18 @@ +buildEndpoint('/wp-json/wp/v2/posts/%d/revisions'); + } +} diff --git a/src/WpClient.php b/src/WpClient.php index c35ebe0..20f81b9 100644 --- a/src/WpClient.php +++ b/src/WpClient.php @@ -22,6 +22,7 @@ * @method Endpoint\PostTypes postTypes() * @method Endpoint\Tags tags() * @method Endpoint\Users users() + * @method Endpoint\PostRevisions postRevisions() */ class WpClient {