PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / bulk-editor / application / posts / posts-repository.php

posts-repository.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at src/bulk-editor/application/posts/posts-repository.php

72 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Bulk_Editor\Application\Posts;
5
6 use Yoast\WP\SEO\Bulk_Editor\Domain\Posts\Posts_Page;
7 use Yoast\WP\SEO\Bulk_Editor\Domain\Posts\Posts_Query;
8 use Yoast\WP\SEO\Bulk_Editor\Infrastructure\Posts\Indexable_Posts_Collector;
9 use Yoast\WP\SEO\Bulk_Editor\Infrastructure\Posts\Post_Meta_Posts_Collector;
10 use Yoast\WP\SEO\Helpers\Indexable_Helper;
11
12 /**
13 * The repository to get posts for the bulk editor.
14 */
15 class Posts_Repository {
16
17 /**
18 * The collector that reads from the indexable table.
19 *
20 * @var Indexable_Posts_Collector
21 */
22 private $indexable_posts_collector;
23
24 /**
25 * The collector that reads from post meta.
26 *
27 * @var Post_Meta_Posts_Collector
28 */
29 private $post_meta_posts_collector;
30
31 /**
32 * The indexable helper.
33 *
34 * @var Indexable_Helper
35 */
36 private $indexable_helper;
37
38 /**
39 * The constructor.
40 *
41 * @param Indexable_Posts_Collector $indexable_posts_collector The collector that reads from the indexable table.
42 * @param Post_Meta_Posts_Collector $post_meta_posts_collector The collector that reads from post meta.
43 * @param Indexable_Helper $indexable_helper The indexable helper.
44 */
45 public function __construct(
46 Indexable_Posts_Collector $indexable_posts_collector,
47 Post_Meta_Posts_Collector $post_meta_posts_collector,
48 Indexable_Helper $indexable_helper
49 ) {
50 $this->indexable_posts_collector = $indexable_posts_collector;
51 $this->post_meta_posts_collector = $post_meta_posts_collector;
52 $this->indexable_helper = $indexable_helper;
53 }
54
55 /**
56 * Returns a page of posts for the given query.
57 *
58 * Reads from the indexable table when indexables are active, and falls back to post meta otherwise.
59 *
60 * @param Posts_Query $query The query describing the page to get.
61 *
62 * @return Posts_Page The posts together with the totals for pagination.
63 */
64 public function get_posts( Posts_Query $query ): Posts_Page {
65 if ( $this->indexable_helper->should_index_indexables() ) {
66 return $this->indexable_posts_collector->get_posts( $query );
67 }
68
69 return $this->post_meta_posts_collector->get_posts( $query );
70 }
71 }
72