Comment.php
1 day ago
CommentServiceFactory.php
1 day ago
Media.php
1 day ago
MediaServiceFactory.php
1 day ago
Post.php
1 day ago
PostServiceFactory.php
1 day ago
User.php
1 day ago
UserServiceFactory.php
1 day ago
Comment.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\TableScreen\ManageValue; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\Exception\HookTimingException; |
| 9 | use AC\TableScreen\ManageValueService; |
| 10 | use AC\Type\ColumnId; |
| 11 | use AC\Type\Value; |
| 12 | |
| 13 | class Comment implements ManageValueService |
| 14 | { |
| 15 | private AC\Table\ManageValue\RenderFactory $factory; |
| 16 | |
| 17 | private int $priority; |
| 18 | |
| 19 | public function __construct( |
| 20 | AC\Table\ManageValue\RenderFactory $factory, |
| 21 | int $priority = 100 |
| 22 | ) { |
| 23 | $this->factory = $factory; |
| 24 | $this->priority = $priority; |
| 25 | } |
| 26 | |
| 27 | public function register(): void |
| 28 | { |
| 29 | if (did_action('manage_comments_custom_column')) { |
| 30 | throw HookTimingException::called_too_late('manage_comments_custom_column'); |
| 31 | } |
| 32 | |
| 33 | add_action('manage_comments_custom_column', [$this, 'render_value'], $this->priority, 2); |
| 34 | } |
| 35 | |
| 36 | public function render_value(...$args): void |
| 37 | { |
| 38 | [$column_id, $row_id] = $args; |
| 39 | |
| 40 | $formatter = $this->factory->create(new ColumnId((string)$column_id)); |
| 41 | |
| 42 | if ($formatter) { |
| 43 | echo $formatter->format(new Value((int)$row_id)); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | } |
| 48 |