for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Lifeboat\Services;
use Lifeboat\Connector;
use Lifeboat\Exceptions\ApiException;
use Lifeboat\Exceptions\OAuthException;
use Lifeboat\Factory\ObjectFactory;
use Lifeboat\Models\Model;
/**
* Class ApiService
* @package Lifeboat\Services
*
* @property Connector $client
*/
abstract class ApiService {
/** @var Connector $client */
protected Connector $client;
* @param int $id
* @return Model|null
abstract public function fetch(int $id = -1): ?Model;
public function __construct(Connector $client)
{
$this->setClient($client);
}
* @return Connector
public function getClient(): Connector
return $this->client;
* @param Connector $client
* @return $this
public function setClient(Connector $client): ApiService
$this->client = $client;
return $this;
* @see ObjectFactory::make()
* @see Connector::curl_api()
* @param string $url
* @param array $params
* @throws ApiException
* @throws OAuthException
protected function retrieve(string $url, array $params = []): ?Model
$curl = $this->getClient()->curl_api($url, 'GET', $params);
if ($curl->isValid() && $curl->isJSON()) {
return ObjectFactory::make($this->getClient(), $curl->getJSON());
return Lifeboat\Factory\...nt(), $curl->getJSON())
Lifeboat\Resource\ObjectResource
Lifeboat\Models\Model|null
throw new ApiException($curl->getError());