mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-13 16:59:36 +03:00
26 lines
814 B
PHP
26 lines
814 B
PHP
<?php
|
|
|
|
namespace OpenCCK\App\Controller;
|
|
|
|
use OpenCCK\Domain\Entity\Site;
|
|
use OpenCCK\Domain\Factory\SiteFactory;
|
|
|
|
class JsonController extends AbstractIPListController {
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getBody(): string {
|
|
$this->setHeaders(['content-type' => 'application/json']);
|
|
|
|
$sites = SiteFactory::normalizeArray($this->request->getQueryParameters()['site'] ?? []);
|
|
$data = $this->request->getQueryParameter('data') ?? '';
|
|
|
|
if (count($sites)) {
|
|
$items = array_filter($this->getSites(), fn(Site $siteEntity) => in_array($siteEntity->name, $sites));
|
|
} else {
|
|
$items = $this->getSites();
|
|
}
|
|
return json_encode($data == '' ? $items : array_map(fn(Site $siteEntity) => $siteEntity->$data, $items));
|
|
}
|
|
}
|