Proje dosyaları eklendi
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Serp\Data;
|
||||
|
||||
final readonly class ProviderHealth
|
||||
{
|
||||
public function __construct(public string $providerKey, public int $balanceMicros, public int $statusCode, public \DateTimeInterface $checkedAt) {}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Serp\Data;
|
||||
|
||||
final readonly class SerpQuery
|
||||
{
|
||||
public function __construct(public string $phrase, public string $searchEngine, public string $countryCode, public string $languageCode, public string $device, public int $limit) {}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Serp\Data;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final readonly class SerpResponse
|
||||
{
|
||||
public array $results;
|
||||
|
||||
public function __construct(public string $providerKey, array $results, public ?string $referenceId = null, int $limit = 100, public string|int|float|null $cost = null, public string $currency = 'USD', public ?int $statusCode = null)
|
||||
{
|
||||
if (count($results) > $limit) {
|
||||
throw new InvalidArgumentException('Sonuç limiti aşıldı.');
|
||||
}foreach ($results as $r) {
|
||||
if (! $r instanceof SerpResultData) {
|
||||
throw new InvalidArgumentException('Geçersiz sonuç verisi.');
|
||||
}
|
||||
}$positions = array_map(fn ($r) => $r->position, $results);
|
||||
if (count($positions) !== count(array_unique($positions))) {
|
||||
throw new InvalidArgumentException('Tekrarlanan sonuç pozisyonu.');
|
||||
}$this->results = array_values($results);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Serp\Data;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final readonly class SerpResultData
|
||||
{
|
||||
public function __construct(public int $position, public string $url, public ?string $title = null, public ?string $displayUrl = null, public ?string $snippet = null, public string $resultType = 'organic')
|
||||
{
|
||||
if ($position < 1) {
|
||||
throw new InvalidArgumentException('Position pozitif olmalıdır.');
|
||||
}
|
||||
if ($resultType !== 'organic') {
|
||||
throw new InvalidArgumentException('Desteklenmeyen sonuç türü.');
|
||||
}
|
||||
if (strlen($url) > 2048 || ! filter_var($url, FILTER_VALIDATE_URL) || ! in_array(strtolower((string) parse_url($url, PHP_URL_SCHEME)), ['http', 'https'], true)) {
|
||||
throw new InvalidArgumentException('Geçersiz sonuç URL adresi.');
|
||||
}
|
||||
if (($title !== null && mb_strlen($title) > 500) || ($displayUrl !== null && mb_strlen($displayUrl) > 500) || ($snippet !== null && mb_strlen($snippet) > 5000)) {
|
||||
throw new InvalidArgumentException('Sonuç alanı izin verilen uzunluğu aşıyor.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Serp\Data;
|
||||
|
||||
final readonly class SerpSubmission
|
||||
{
|
||||
public function __construct(public string $providerKey, public string $taskId, public ?float $cost = null, public string $currency = 'USD', public ?int $statusCode = null) {}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Serp\Data;
|
||||
|
||||
final readonly class SerpTaskResult
|
||||
{
|
||||
private function __construct(public bool $ready, public ?SerpResponse $response, public ?float $cost, public string $currency, public ?int $statusCode) {}
|
||||
|
||||
public static function waiting(?int $statusCode = null): self
|
||||
{
|
||||
return new self(false, null, null, 'USD', $statusCode);
|
||||
}
|
||||
|
||||
public static function ready(SerpResponse $response, ?float $cost = null, string $currency = 'USD', ?int $statusCode = null): self
|
||||
{
|
||||
return new self(true, $response, $cost, $currency, $statusCode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user