From c6f0c7d8f7c14d383f8a06bee61d56f4889cb17e Mon Sep 17 00:00:00 2001 From: conky Date: Thu, 13 Oct 2022 23:52:21 +0300 Subject: [PATCH] Described a bit topic base class and methods. --- src/Client.php | 8 +++++++- src/ClientInterface.php | 8 ++++++++ src/Topic/TopicBase.php | 31 ++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 32d940d..69d2c8c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -54,6 +54,13 @@ class Client implements ClientInterface { $this->logger = $logger; } + /** + * {@inheritDoc} + */ + public function getBaseUrl(): string { + return $this->base_url; + } + /** * {@inheritDoc} */ @@ -82,5 +89,4 @@ class Client implements ClientInterface { // TODO: Implement getTopic() method. } - } diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 7b383f8..041c70f 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -4,6 +4,14 @@ namespace Toloka\PhpApi; interface ClientInterface { + /** + * Get Toloka base url. + * + * @return string + * Absolute URL to toloka. + */ + public function getBaseUrl(): string; + /** * Login using credentials. * diff --git a/src/Topic/TopicBase.php b/src/Topic/TopicBase.php index 1424607..342a88b 100644 --- a/src/Topic/TopicBase.php +++ b/src/Topic/TopicBase.php @@ -2,8 +2,37 @@ namespace Toloka\PhpApi; -abstract class TopicBase implements TopicInterface { +class TopicBase implements TopicInterface { + protected Client $client; + protected int $id; + + public function __construct( + Client $client + ) { + $this->client = $client; + } + + /** + * @return int + */ + public function id(): int { + return $this->id; + } + + /** + * @param int $id + */ + public function setId(int $id): void { + $this->id = $id; + } + + /** + * {@inheritDoc} + */ + public function url(bool $absolute = TRUE): string { + return $this->client->getBaseUrl() . 't' . $this->id(); + } }