| 1 |
<?php |
| 2 |
/** |
| 3 |
* Email Report Manager (Boot) |
| 4 |
* |
| 5 |
* The single component the plugin's DI container instantiates. Wires |
| 6 |
* together the config, registry, renderer, mailer, generator, and |
| 7 |
* scheduler, then registers the cron and the section catalog. |
| 8 |
* |
| 9 |
* Free sections are require_once'd here because the project autoloader |
| 10 |
* doesn't translate underscores in sub-namespaces to hyphenated |
| 11 |
* directories. Pro can register more sections via the |
| 12 |
* `thinkrank_email_report_register_sections` action. |
| 13 |
* |
| 14 |
* @package ThinkRank |
| 15 |
* @subpackage SEO |
| 16 |
* @since 1.9.0 |
| 17 |
*/ |
| 18 |
|
| 19 |
declare(strict_types=1); |
| 20 |
|
| 21 |
namespace ThinkRank\SEO; |
| 22 |
|
| 23 |
use ThinkRank\SEO\Email_Report_Sections\Email_Report_Section_Interface; |
| 24 |
use ThinkRank\SEO\Email_Report_Sections\Key_Metrics_Section; |
| 25 |
use ThinkRank\SEO\Email_Report_Sections\Position_Summary_Section; |
| 26 |
use ThinkRank\SEO\Email_Report_Sections\Top_Winning_Posts_Section; |
| 27 |
use ThinkRank\SEO\Email_Report_Sections\Top_Losing_Posts_Section; |
| 28 |
use ThinkRank\SEO\Email_Report_Sections\Top_Winning_Keywords_Section; |
| 29 |
use ThinkRank\SEO\Email_Report_Sections\Top_Losing_Keywords_Section; |
| 30 |
|
| 31 |
if (!defined('ABSPATH')) { |
| 32 |
exit; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Email_Report_Manager |
| 37 |
* |
| 38 |
* @since 1.9.0 |
| 39 |
*/ |
| 40 |
final class Email_Report_Manager { |
| 41 |
|
| 42 |
private ?Email_Report_Config $config = null; |
| 43 |
private ?Email_Report_Section_Registry $registry = null; |
| 44 |
private ?Email_Report_Renderer $renderer = null; |
| 45 |
private ?Email_Report_Mailer $mailer = null; |
| 46 |
private ?Email_Report_Generator $generator = null; |
| 47 |
private ?Email_Report_Scheduler $scheduler = null; |
| 48 |
private ?Email_Report_Data_Provider $data_provider = null; |
| 49 |
|
| 50 |
/** |
| 51 |
* Called by the plugin DI container at plugins_loaded. |
| 52 |
* |
| 53 |
* Two-phase: load files now (so endpoint classes can resolve types |
| 54 |
* during rest_api_init), then register cron/sections on init. |
| 55 |
*/ |
| 56 |
public function init(): void { |
| 57 |
$this->require_files(); |
| 58 |
$this->build_graph(); |
| 59 |
$this->register_default_sections(); |
| 60 |
$this->register_extension_sections(); |
| 61 |
$this->scheduler->register(); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Section files live under `seo/email-report-sections/` (hyphenated) |
| 66 |
* but the namespace uses underscores — autoloader can't bridge that |
| 67 |
* mismatch. Explicit require keeps boot order deterministic. |
| 68 |
*/ |
| 69 |
private function require_files(): void { |
| 70 |
$base = THINKRANK_PLUGIN_DIR . 'includes/seo/email-report-sections/'; |
| 71 |
require_once $base . 'interface-email-report-section.php'; |
| 72 |
require_once $base . 'class-top-posts-renderer.php'; |
| 73 |
require_once $base . 'class-key-metrics-section.php'; |
| 74 |
require_once $base . 'class-position-summary-section.php'; |
| 75 |
require_once $base . 'class-top-winning-posts-section.php'; |
| 76 |
require_once $base . 'class-top-losing-posts-section.php'; |
| 77 |
require_once $base . 'class-top-winning-keywords-section.php'; |
| 78 |
require_once $base . 'class-top-losing-keywords-section.php'; |
| 79 |
|
| 80 |
// Defaults config is procedural — load eagerly. |
| 81 |
require_once THINKRANK_PLUGIN_DIR . 'includes/config/email-report-settings-config.php'; |
| 82 |
} |
| 83 |
|
| 84 |
private function build_graph(): void { |
| 85 |
$this->config = new Email_Report_Config(); |
| 86 |
$this->registry = new Email_Report_Section_Registry(); |
| 87 |
$this->renderer = new Email_Report_Renderer($this->registry); |
| 88 |
$this->mailer = new Email_Report_Mailer(); |
| 89 |
$this->data_provider = new Email_Report_Data_Provider(); |
| 90 |
$this->generator = new Email_Report_Generator( |
| 91 |
$this->config, |
| 92 |
$this->renderer, |
| 93 |
$this->mailer, |
| 94 |
$this->data_provider |
| 95 |
); |
| 96 |
$this->scheduler = new Email_Report_Scheduler($this->config, $this->generator); |
| 97 |
} |
| 98 |
|
| 99 |
private function register_default_sections(): void { |
| 100 |
$this->registry->register(new Key_Metrics_Section()); |
| 101 |
$this->registry->register(new Position_Summary_Section()); |
| 102 |
$this->registry->register(new Top_Winning_Posts_Section()); |
| 103 |
$this->registry->register(new Top_Losing_Posts_Section()); |
| 104 |
$this->registry->register(new Top_Winning_Keywords_Section()); |
| 105 |
$this->registry->register(new Top_Losing_Keywords_Section()); |
| 106 |
} |
| 107 |
|
| 108 |
private function register_extension_sections(): void { |
| 109 |
/** |
| 110 |
* Pro plugin (or any other plugin) hooks here and calls |
| 111 |
* $registry->register(new MySection()) |
| 112 |
* to add or override a section. |
| 113 |
* |
| 114 |
* @since 1.9.0 |
| 115 |
* |
| 116 |
* @param Email_Report_Section_Registry $registry |
| 117 |
*/ |
| 118 |
do_action('thinkrank_email_report_register_sections', $this->registry); |
| 119 |
} |
| 120 |
|
| 121 |
// Accessors used by the REST endpoint. |
| 122 |
|
| 123 |
public function config(): Email_Report_Config { |
| 124 |
return $this->config; |
| 125 |
} |
| 126 |
|
| 127 |
public function registry(): Email_Report_Section_Registry { |
| 128 |
return $this->registry; |
| 129 |
} |
| 130 |
|
| 131 |
public function generator(): Email_Report_Generator { |
| 132 |
return $this->generator; |
| 133 |
} |
| 134 |
|
| 135 |
public function scheduler(): Email_Report_Scheduler { |
| 136 |
return $this->scheduler; |
| 137 |
} |
| 138 |
} |
| 139 |
|