| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\Llms_Txt\Application\Configuration; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 7 |
use Yoast\WP\SEO\Helpers\Post_Type_Helper; |
| 8 |
use Yoast\WP\SEO\Llms_Txt\Application\Health_Check\File_Runner; |
| 9 |
|
| 10 |
/** |
| 11 |
* Responsible for the llms.txt configuration. |
| 12 |
*/ |
| 13 |
class Llms_Txt_Configuration { |
| 14 |
|
| 15 |
/** |
| 16 |
* Runs the health check. |
| 17 |
* |
| 18 |
* @var File_Runner |
| 19 |
*/ |
| 20 |
private $runner; |
| 21 |
|
| 22 |
/** |
| 23 |
* The post type helper. |
| 24 |
* |
| 25 |
* @var Post_Type_Helper |
| 26 |
*/ |
| 27 |
private $post_type_helper; |
| 28 |
|
| 29 |
/** |
| 30 |
* The options helper. |
| 31 |
* |
| 32 |
* @var Options_Helper |
| 33 |
*/ |
| 34 |
private $options_helper; |
| 35 |
|
| 36 |
/** |
| 37 |
* The constructor. |
| 38 |
* |
| 39 |
* @param File_Runner $runner The File_Generation health check runner. |
| 40 |
* @param Post_Type_Helper $post_type_helper The post type helper. |
| 41 |
* @param Options_Helper $options_helper The options helper. |
| 42 |
*/ |
| 43 |
public function __construct( |
| 44 |
File_Runner $runner, |
| 45 |
Post_Type_Helper $post_type_helper, |
| 46 |
Options_Helper $options_helper |
| 47 |
) { |
| 48 |
$this->runner = $runner; |
| 49 |
$this->post_type_helper = $post_type_helper; |
| 50 |
$this->options_helper = $options_helper; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Returns a configuration |
| 55 |
* |
| 56 |
* @return array<string, array<string>|array<string, string|array<string, array<string, int>>>> |
| 57 |
*/ |
| 58 |
public function get_configuration(): array { |
| 59 |
$this->runner->run(); |
| 60 |
|
| 61 |
$configuration = [ |
| 62 |
'generationFailure' => ! $this->runner->is_successful(), |
| 63 |
'generationFailureReason' => $this->runner->get_generation_failure_reason(), |
| 64 |
'llmsTxtUrl' => \home_url( 'llms.txt' ), |
| 65 |
'disabledPageIndexables' => ( $this->post_type_helper->is_of_indexable_post_type( 'page' ) === false ), |
| 66 |
'otherIncludedPagesLimit' => $this->options_helper->get_other_included_pages_limit(), |
| 67 |
]; |
| 68 |
|
| 69 |
return $configuration; |
| 70 |
} |
| 71 |
} |
| 72 |
|