Files
pricebuddy/app/Dto/AvailabilityMatchDto.php
Jeremy 1a857e1582 feat: meta extraction API and typed scrape-strategy DTOs
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
2026-06-18 23:13:01 +10:00

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();
}
}