Files
033f0c84da v4.7 (#12478)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Co-authored-by: Aditya Tripathi <aditya@climactic.co>
2026-11-06 14:25:02 +01:00

52 lines
1.4 KiB
PHP

<?php
namespace App\Services\ImageScan;
final readonly class Package
{
/**
* @param list<string> $licenses
*/
public function __construct(
public string $id,
public string $name,
public string $version,
public string $type,
public array $licenses,
public string $purl,
public string $layerId,
) {}
/**
* @return array{id: string, name: string, version: string, type: string, licenses: list<string>, purl: string, layerId: string}
*/
public function toArray(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'version' => $this->version,
'type' => $this->type,
'licenses' => $this->licenses,
'purl' => $this->purl,
'layerId' => $this->layerId,
];
}
/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): self
{
return new self(
id: (string) ($data['id'] ?? ''),
name: (string) ($data['name'] ?? ''),
version: (string) ($data['version'] ?? ''),
type: (string) ($data['type'] ?? ''),
licenses: array_values(array_map('strval', (array) ($data['licenses'] ?? []))),
purl: (string) ($data['purl'] ?? ''),
layerId: (string) ($data['layerId'] ?? ''),
);
}
}