Controller.php
2 years ago
Endpoint.php
2 years ago
PostsEndpoint.php
2 years ago
TaxonomiesEndpoint.php
2 years ago
ThemesEndpoint.php
2 years ago
ThumbnailsEndpoint.php
2 years ago
ViewLoggerEndpoint.php
2 years ago
WidgetEndpoint.php
2 years ago
Controller.php
97 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 | * Themes Endpoint. |
| 32 | * |
| 33 | * @var \WordPressPopularPosts\Rest\ThemesEndpoint |
| 34 | * @access private |
| 35 | */ |
| 36 | private $themes_endpoint; |
| 37 | |
| 38 | /** |
| 39 | * Themes Endpoint. |
| 40 | * |
| 41 | * @var \WordPressPopularPosts\Rest\ThumbnailsEndpoint |
| 42 | * @access private |
| 43 | */ |
| 44 | private $thumbnails_endpoint; |
| 45 | |
| 46 | /** |
| 47 | * Themes Endpoint. |
| 48 | * |
| 49 | * @var \WordPressPopularPosts\Rest\TaxonomiesEndpoint |
| 50 | * @access private |
| 51 | */ |
| 52 | private $taxonomies_endpoint; |
| 53 | |
| 54 | /** |
| 55 | * Initialize class. |
| 56 | * |
| 57 | * @param \WordPressPopularPosts\Rest\PostsEndpoint |
| 58 | * @param \WordPressPopularPosts\Rest\ViewLoggerEndpoint |
| 59 | * @param \WordPressPopularPosts\Rest\WidgetEndpoint |
| 60 | * @param \WordPressPopularPosts\Rest\ThemesEndpoint |
| 61 | * @param \WordPressPopularPosts\Rest\ThumbnailsEndpoint |
| 62 | * @param \WordPressPopularPosts\Rest\TaxonomiesEndpoint |
| 63 | */ |
| 64 | public function __construct(PostsEndpoint $posts_endpoint, ViewLoggerEndpoint $view_logger_endpoint, WidgetEndpoint $widget_endpoint, ThemesEndpoint $themes_endpoint, ThumbnailsEndpoint $thumbnails_endpoint, TaxonomiesEndpoint $taxonomies_endpoint) |
| 65 | { |
| 66 | $this->posts_endpoint = $posts_endpoint; |
| 67 | $this->view_logger_endpoint = $view_logger_endpoint; |
| 68 | $this->widget_endpoint = $widget_endpoint; |
| 69 | $this->themes_endpoint = $themes_endpoint; |
| 70 | $this->thumbnails_endpoint = $thumbnails_endpoint; |
| 71 | $this->taxonomies_endpoint = $taxonomies_endpoint; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * WordPress hooks. |
| 76 | * |
| 77 | * @since 5.0.0 |
| 78 | */ |
| 79 | public function hooks() |
| 80 | { |
| 81 | add_action('rest_api_init', [$this, 'register_routes']); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Registers REST endpoints. |
| 86 | */ |
| 87 | public function register_routes() |
| 88 | { |
| 89 | $this->posts_endpoint->register(); |
| 90 | $this->view_logger_endpoint->register(); |
| 91 | $this->widget_endpoint->register(); |
| 92 | $this->themes_endpoint->register(); |
| 93 | $this->thumbnails_endpoint->register(); |
| 94 | $this->taxonomies_endpoint->register(); |
| 95 | } |
| 96 | } |
| 97 |