Audio
2 days ago
Video
2 days ago
AttachmentMetaData.php
2 days ago
AttachmentUrl.php
2 days ago
AudioPlayer.php
2 days ago
AvailableSizes.php
2 days ago
Dimensions.php
2 days ago
Download.php
2 days ago
ExifData.php
2 days ago
FileLinkToUrl.php
2 days ago
FileName.php
2 days ago
FileSize.php
2 days ago
Link.php
2 days ago
NestedAttachmentMetaData.php
2 days ago
NumberFormat.php
2 days ago
PostMimeType.php
2 days ago
PreviewViewLink.php
2 days ago
VideoEmbed.php
2 days ago
NestedAttachmentMetaData.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Media; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Helper; |
| 10 | use AC\Type\Value; |
| 11 | |
| 12 | class NestedAttachmentMetaData implements Formatter |
| 13 | { |
| 14 | private array $keys; |
| 15 | |
| 16 | public function __construct(array $keys) |
| 17 | { |
| 18 | $this->keys = $keys; |
| 19 | } |
| 20 | |
| 21 | public function format(Value $value): Value |
| 22 | { |
| 23 | $meta = get_post_meta($value->get_id(), '_wp_attachment_metadata', true); |
| 24 | |
| 25 | $attachment_meta = Helper\Arrays::create()->get_nested_value($meta, $this->keys); |
| 26 | |
| 27 | if (! is_scalar($attachment_meta)) { |
| 28 | throw ValueNotFoundException::from_id($value->get_id()); |
| 29 | } |
| 30 | |
| 31 | return $value->with_value($attachment_meta); |
| 32 | } |
| 33 | |
| 34 | } |
| 35 |