Files
pricebuddy/app/Casts/StoreScraperStrategySetCast.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

42 lines
1.2 KiB
PHP

<?php
namespace App\Casts;
use App\Dto\StoreScraperStrategySetDto;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
/**
* Casts the stores.scrape_strategy JSON column to/from a StoreScraperStrategySetDto.
*
* @implements CastsAttributes<StoreScraperStrategySetDto, StoreScraperStrategySetDto|array<string, mixed>>
*/
class StoreScraperStrategySetCast implements CastsAttributes
{
/**
* @param array<string, mixed> $attributes
*/
public function get(Model $model, string $key, mixed $value, array $attributes): StoreScraperStrategySetDto
{
$decoded = is_string($value) ? json_decode($value, true) : $value;
return StoreScraperStrategySetDto::fromArray(is_array($decoded) ? $decoded : null);
}
/**
* @param array<string, mixed> $attributes
*/
public function set(Model $model, string $key, mixed $value, array $attributes): ?string
{
if ($value === null) {
return null;
}
if ($value instanceof StoreScraperStrategySetDto) {
return json_encode($value->toArray());
}
return json_encode(StoreScraperStrategySetDto::fromArray($value)->toArray());
}
}