feat(*.php): refactor, clean up and abstract dynamic page code
This commit is contained in:
parent
2f9038dccb
commit
60be0ed01d
30 changed files with 318 additions and 401 deletions
29
api/Classes/PageFetcher.php
Normal file
29
api/Classes/PageFetcher.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Classes;
|
||||
|
||||
use App\Classes\BaseHandler;
|
||||
|
||||
abstract class PageFetcher extends BaseHandler
|
||||
{
|
||||
protected function cacheGet(string $key): mixed
|
||||
{
|
||||
return $this->cache && $this->cache->exists($key) ? json_decode($this->cache->get($key), true) : null;
|
||||
}
|
||||
|
||||
protected function cacheSet(string $key, mixed $value, int $ttl = 3600): void
|
||||
{
|
||||
if ($this->cache) $this->cache->setex($key, $ttl, json_encode($value));
|
||||
}
|
||||
|
||||
protected function fetchSingleFromApi(string $endpoint, string $url): ?array
|
||||
{
|
||||
$data = $this->fetchFromApi($endpoint, "url=eq./{$url}");
|
||||
return $data[0] ?? null;
|
||||
}
|
||||
|
||||
protected function fetchPostRpc(string $endpoint, array $body): ?array
|
||||
{
|
||||
return $this->makeRequest("POST", $endpoint, ['json' => $body]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue