mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Add a meta-extraction API endpoint and refactor store scrape strategies onto strongly-typed DTOs. - POST /api/meta-extraction endpoint with SSRF protection on the target URL - Typed scrape-strategy DTOs and enums (StandardStrategyDto, AvailabilityMatchDto, AvailabilityMatchType, AvailabilityStrategyDto, StoreScraperStrategySetDto) with a model cast for the stores.scrape_strategy column - Convert ScrapeUrl, StrategyExtractor and availability resolution to consume the typed strategy slots; preserve legacy plain-string availability match entries - Filament scrape_strategy form bridge plus DTO test coverage
56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Enums\AvailabilityMatchType;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use JsonSerializable;
|
|
|
|
/**
|
|
* One per-status availability match rule (e.g. out_of_stock => "Sold out").
|
|
*
|
|
* @implements Arrayable<string, string>
|
|
*/
|
|
class AvailabilityMatchDto implements Arrayable, JsonSerializable
|
|
{
|
|
public function __construct(
|
|
public AvailabilityMatchType $type,
|
|
public string $value,
|
|
) {}
|
|
|
|
/**
|
|
* Build from a stored match entry, or null when there is no usable value.
|
|
*
|
|
* @param array<string, mixed>|null $data
|
|
*/
|
|
public static function fromArray(?array $data): ?self
|
|
{
|
|
$value = $data['value'] ?? null;
|
|
|
|
if ($value === null || $value === '') {
|
|
return null;
|
|
}
|
|
|
|
return new self(
|
|
type: AvailabilityMatchType::tryFrom((string) ($data['type'] ?? 'match')) ?? AvailabilityMatchType::Match,
|
|
value: (string) $value,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return ['type' => $this->type->value, 'value' => $this->value];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function jsonSerialize(): array
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
}
|