Controller.php
5 years ago
Endpoint.php
5 years ago
PostsEndpoint.php
5 years ago
ViewLoggerEndpoint.php
5 years ago
WidgetEndpoint.php
5 years ago
Controller.php
64 lines
| 1 | <?php |
| 2 | namespace WordPressPopularPosts\Rest; |
| 3 | |
| 4 | class Controller { |
| 5 | |
| 6 | /** |
| 7 | * Posts Endpoint. |
| 8 | * |
| 9 | * @var \WordPressPopularPosts\Rest\PostsEndpoint |
| 10 | * @access private |
| 11 | */ |
| 12 | private $posts_endpoint; |
| 13 | |
| 14 | /** |
| 15 | * View Logger Endpoint. |
| 16 | * |
| 17 | * @var \WordPressPopularPosts\Rest\ViewLoggerEndpoint |
| 18 | * @access private |
| 19 | */ |
| 20 | private $view_logger_endpoint; |
| 21 | |
| 22 | /** |
| 23 | * View Logger Endpoint. |
| 24 | * |
| 25 | * @var \WordPressPopularPosts\Rest\WidgetEndpoint |
| 26 | * @access private |
| 27 | */ |
| 28 | private $widget_endpoint; |
| 29 | |
| 30 | /** |
| 31 | * Initialize class. |
| 32 | * |
| 33 | * @param \WordPressPopularPosts\Rest\PostsEndpoint |
| 34 | * @param \WordPressPopularPosts\Rest\ViewLoggerEndpoint |
| 35 | * @param \WordPressPopularPosts\Rest\WidgetEndpoint |
| 36 | */ |
| 37 | public function __construct(\WordPressPopularPosts\Rest\PostsEndpoint $posts_endpoint, \WordPressPopularPosts\Rest\ViewLoggerEndpoint $view_logger_endpoint, \WordPressPopularPosts\Rest\WidgetEndpoint $widget_endpoint) |
| 38 | { |
| 39 | $this->posts_endpoint = $posts_endpoint; |
| 40 | $this->view_logger_endpoint = $view_logger_endpoint; |
| 41 | $this->widget_endpoint = $widget_endpoint; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * WordPress hooks. |
| 46 | * |
| 47 | * @since 5.0.0 |
| 48 | */ |
| 49 | public function hooks() |
| 50 | { |
| 51 | add_action('rest_api_init', [$this, 'register_routes']); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Registers REST endpoints. |
| 56 | */ |
| 57 | public function register_routes() |
| 58 | { |
| 59 | $this->posts_endpoint->register(); |
| 60 | $this->view_logger_endpoint->register(); |
| 61 | $this->widget_endpoint->register(); |
| 62 | } |
| 63 | } |
| 64 |