|
@@ -8,14 +8,14 @@ use Opentalent\OtCore\Exception\ApiRequestException;
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
use Psr\Log\LoggerAwareInterface;
|
|
use Psr\Log\LoggerAwareInterface;
|
|
|
use Psr\Log\LoggerAwareTrait;
|
|
use Psr\Log\LoggerAwareTrait;
|
|
|
|
|
+use TYPO3\CMS\Core\Core\ApplicationContext;
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
|
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
|
|
-use TYPO3\CMS\Extbase\Persistence\Repository;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Base class for repositories based on the Opentalent API
|
|
* Base class for repositories based on the Opentalent API
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
-abstract class BaseApiRepository extends Repository implements LoggerAwareInterface
|
|
|
|
|
|
|
+abstract class BaseApiRepository implements LoggerAwareInterface
|
|
|
{
|
|
{
|
|
|
use LoggerAwareTrait;
|
|
use LoggerAwareTrait;
|
|
|
|
|
|
|
@@ -24,13 +24,38 @@ abstract class BaseApiRepository extends Repository implements LoggerAwareInterf
|
|
|
const HTTP_METHOD = 'GET';
|
|
const HTTP_METHOD = 'GET';
|
|
|
const DEFAULT_ITEMS_PER_PAGE = 8;
|
|
const DEFAULT_ITEMS_PER_PAGE = 8;
|
|
|
|
|
|
|
|
- private $client;
|
|
|
|
|
- private $context;
|
|
|
|
|
|
|
+ protected $client;
|
|
|
|
|
+ protected $context;
|
|
|
|
|
|
|
|
- public function __construct(ObjectManagerInterface $objectManager) {
|
|
|
|
|
- parent::__construct($objectManager);
|
|
|
|
|
- $this->client = new Client(['base_uri' => static::BASE_URI]);
|
|
|
|
|
- $this->context = \TYPO3\CMS\Core\Core\Environment::getContext();
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * BaseApiRepository constructor.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param ObjectManagerInterface $objectManager
|
|
|
|
|
+ * @param Client|null $client [For tests only]
|
|
|
|
|
+ * @param ApplicationContext|null $context [For tests only]
|
|
|
|
|
+ */
|
|
|
|
|
+ public function __construct(
|
|
|
|
|
+ ?Client $client = null,
|
|
|
|
|
+ ?ApplicationContext $context = null
|
|
|
|
|
+ ) {
|
|
|
|
|
+ if ($client === null) {
|
|
|
|
|
+ $this->client = new Client(['base_uri' => static::BASE_URI]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->client = $client;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($context === null) {
|
|
|
|
|
+ $this->context = \TYPO3\CMS\Core\Core\Environment::getContext();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->context = $context;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * [FOR TESTS ONLY]
|
|
|
|
|
+ * @param Client $client
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function injectClient(Client $client) {
|
|
|
|
|
+ $this->client = $client;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -43,7 +68,7 @@ abstract class BaseApiRepository extends Repository implements LoggerAwareInterf
|
|
|
* @throws ApiRequestException
|
|
* @throws ApiRequestException
|
|
|
*/
|
|
*/
|
|
|
protected function getApiRecords(string $uri, $params = []) {
|
|
protected function getApiRecords(string $uri, $params = []) {
|
|
|
- $body = $this->getJson($uri, $params);
|
|
|
|
|
|
|
+ $body = $this->getJsonDecoded($uri, $params);
|
|
|
|
|
|
|
|
$page = (int)($params['page'] ?? 1);
|
|
$page = (int)($params['page'] ?? 1);
|
|
|
|
|
|
|
@@ -100,7 +125,7 @@ abstract class BaseApiRepository extends Repository implements LoggerAwareInterf
|
|
|
* @return array
|
|
* @return array
|
|
|
* @throws ApiRequestException
|
|
* @throws ApiRequestException
|
|
|
*/
|
|
*/
|
|
|
- protected function getJson(string $uri, $params = [])
|
|
|
|
|
|
|
+ protected function getJsonDecoded(string $uri, $params = [])
|
|
|
{
|
|
{
|
|
|
return json_decode($this->getBody($uri, $params),true);
|
|
return json_decode($this->getBody($uri, $params),true);
|
|
|
}
|
|
}
|
|
@@ -116,7 +141,7 @@ abstract class BaseApiRepository extends Repository implements LoggerAwareInterf
|
|
|
*/
|
|
*/
|
|
|
protected function getBody(string $uri, $params = [])
|
|
protected function getBody(string $uri, $params = [])
|
|
|
{
|
|
{
|
|
|
- return (string)$this->get($uri, $params)->getBody();
|
|
|
|
|
|
|
+ return (string)$this->getResponse($uri, $params)->getBody();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -128,7 +153,7 @@ abstract class BaseApiRepository extends Repository implements LoggerAwareInterf
|
|
|
* @return ResponseInterface
|
|
* @return ResponseInterface
|
|
|
* @throws ApiRequestException
|
|
* @throws ApiRequestException
|
|
|
*/
|
|
*/
|
|
|
- protected function get(string $uri, $params = [])
|
|
|
|
|
|
|
+ protected function getResponse(string $uri, $params = [])
|
|
|
{
|
|
{
|
|
|
$uri = $uri . '?_format=json';
|
|
$uri = $uri . '?_format=json';
|
|
|
if(!isset($params['itemsPerPage'])) {
|
|
if(!isset($params['itemsPerPage'])) {
|