. */ declare(strict_types=1); namespace App\Services\InfoProviderSystem\DTOs; use App\Entity\Parts\ManufacturingStatus; /** * This DTO represents a search result for a part. * @see \App\Tests\Services\InfoProviderSystem\DTOs\SearchResultDTOTest */ class SearchResultDTO { /** @var string|null An URL to a preview image */ public readonly ?string $preview_image_url; /** @var FileDTO|null The preview image as FileDTO object */ public readonly ?FileDTO $preview_image_file; public function __construct( /** @var string The provider key (e.g. "digikey") */ public readonly string $provider_key, /** @var string The ID which identifies the part in the provider system */ public readonly string $provider_id, /** @var string The name of the part */ public readonly string $name, /** @var string A short description of the part */ public readonly string $description, /** @var string|null The category the distributor assumes for the part */ public readonly ?string $category = null, /** @var string|null The manufacturer of the part */ public readonly ?string $manufacturer = null, /** @var string|null The manufacturer part number */ public readonly ?string $mpn = null, /** @var string|null An URL to a preview image */ ?string $preview_image_url = null, /** @var ManufacturingStatus|null The manufacturing status of the part */ public readonly ?ManufacturingStatus $manufacturing_status = null, /** @var string|null A link to the part on the providers page */ public readonly ?string $provider_url = null, /** @var string|null A footprint representation of the providers page */ public readonly ?string $footprint = null, ) { if ($preview_image_url !== null) { //Utilize the escaping mechanism of FileDTO to ensure that the preview image URL is correctly encoded //See issue #521: https://github.com/Part-DB/Part-DB-server/issues/521 $this->preview_image_file = new FileDTO($preview_image_url); $this->preview_image_url = $this->preview_image_file->url; } else { $this->preview_image_file = null; $this->preview_image_url = null; } } }