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