Author.php
1 day ago
CommentLink.php
1 day ago
CommentObject.php
1 day ago
CommentText.php
1 day ago
Content.php
1 day ago
LinkableCommentDate.php
1 day ago
Meta.php
1 day ago
MetaDateAndAuthor.php
1 day ago
ParentId.php
1 day ago
Property.php
1 day ago
ReplyToLink.php
1 day ago
StatusLabel.php
1 day ago
UserId.php
1 day ago
UserId.php
28 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Comment; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Type\Value; |
| 10 | |
| 11 | class UserId implements Formatter |
| 12 | { |
| 13 | public function format(Value $value): Value |
| 14 | { |
| 15 | $comment = get_comment($value->get_id()); |
| 16 | $user_id = $comment->user_id ?? null; |
| 17 | |
| 18 | if (! $user_id) { |
| 19 | throw ValueNotFoundException::from_id($value->get_id()); |
| 20 | } |
| 21 | |
| 22 | return new Value( |
| 23 | (int)$user_id |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | } |
| 28 |