Skip to content

Commit 4ac4921

Browse files
authored
fix(anthropic): Anthropic media mappers call validation method (#432)
1 parent 8930da1 commit 4ac4921

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/Contracts/ProviderMediaMapper.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
abstract class ProviderMediaMapper
1010
{
1111
public function __construct(public readonly Media $media)
12+
{
13+
$this->runValidation();
14+
}
15+
16+
abstract public function toPayload(): mixed;
17+
18+
abstract protected function provider(): string|Provider;
19+
20+
abstract protected function validateMedia(): bool;
21+
22+
protected function runValidation(): void
1223
{
1324
if ($this->validateMedia() === false) {
1425
$providerName = $this->provider() instanceof Provider ? $this->provider()->value : $this->provider();
@@ -18,10 +29,4 @@ public function __construct(public readonly Media $media)
1829
throw new PrismException("The $providerName provider does not support the mediums available in the provided `$calledClass`. Pleae consult the Prism documentation for more information on which mediums the $providerName provider supports.");
1930
}
2031
}
21-
22-
abstract public function toPayload(): mixed;
23-
24-
abstract protected function provider(): string|Provider;
25-
26-
abstract protected function validateMedia(): bool;
2732
}

src/Providers/Anthropic/Maps/DocumentMapper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public function __construct(
1919
public readonly Media $media,
2020
public ?array $cacheControl = null,
2121
public array $requestProviderOptions = [],
22-
) {}
22+
) {
23+
$this->runValidation();
24+
}
2325

2426
/**
2527
* @return array<string,mixed>

src/Providers/Anthropic/Maps/ImageMapper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class ImageMapper extends ProviderMediaMapper
1616
public function __construct(
1717
public readonly Media $media,
1818
public ?array $cacheControl = null,
19-
) {}
19+
) {
20+
$this->runValidation();
21+
}
2022

2123
/**
2224
* @return array<string,mixed>

0 commit comments

Comments
 (0)