HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/ste.komma.pro/vendor/komma/feedback-company/src/Base/Endpoint.php
<?php


namespace Komma\FeedbackCompany\Base;


use Komma\FeedbackCompany\FeedbackCompanyApi;
use Komma\FeedbackCompany\Resources\Question;
use Komma\FeedbackCompany\Resources\Review;
use Komma\FeedbackCompany\Resources\Shop;
use Komma\FeedbackCompany\Resources\Statistic;

abstract class Endpoint
{

    protected FeedbackCompanyApi $apiClient;

    protected string $resourcePath;

    /**
     * @param  FeedbackCompanyApi  $apiClient
     */
    public function __construct(FeedbackCompanyApi $apiClient)
    {
        $this->apiClient = $apiClient;
    }

    /**
     * @param array $filters
     * @return string
     */
    protected function buildQueryString(array $filters): string
    {
        if (empty($filters)) {
            return "";
        }

        foreach ($filters as $key => $value) {
            if ($value === true) {
                $filters[$key] = "true";
            }

            if ($value === false) {
                $filters[$key] = "false";
            }
        }

        return "?" . http_build_query($filters, "", "&");
    }

    /**
     * Get the header for a GET request
     *
     * @param  array  $headers
     * @return array
     */
    protected function buildGetHeaders($headers = []): array
    {
        $headers = array_merge($headers, [
            'Accept' => "application/json",
            'Content-Type' => 'application/json',
            'Authorization' => 'Bearer '.FeedbackCompanyApi::$accessToken,
        ]);

        return $headers;
    }

    /**
     * Resolve the response into Resources
     *
     * @param  object  $response
     * @return mixed
     */
    protected function resolve(object $response)
    {
        if(isset($response->shop)) $response->shop = ResourceFactory::createFromApiResult($response->shop, new Shop());
        if(isset($response->review)) $response->review = ResourceFactory::createFromApiResult($response->review, new Review());
        if(isset($response->reviews)) $response->reviews = ResourceFactory::createFromApiResultArray($response->reviews, Review::class);
        if(isset($response->questions)) $response->questions = ResourceFactory::createFromApiResultArray($response->questions, Question::class);
        if(isset($response->statistics)) $response->statistics = ResourceFactory::createFromApiResultArray($response->statistics, Statistic::class);

        return $response;
    }
}