PluginProbe
SureCookie – GDPR Cookie Consent Banner, Cookie Scanner & Script Blocking / trunk
SureCookie – GDPR Cookie Consent Banner, Cookie Scanner & Script Blocking vtrunk
1.5.0 1.4.0 1.3.0 1.3.1 trunk 0.0.0-alpha.1 0.0.0-alpha.2 0.0.0-alpha.3 0.0.1-beta.1 0.0.1-beta.2 0.0.1-beta.3 0.0.1-beta.4 1.0.0 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4
surecookie / inc / modules / services / init.php

init.php in SureCookie – GDPR Cookie Consent Banner, Cookie Scanner & Script Blocking trunk, at inc/modules/services/init.php

85 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Initialize the Services module.
4 *
5 * Owns the known-services catalog domain: fetch/cache/validate of the unified
6 * dataset/services.json (Services_Source), its projections (Known_Scripts blocking
7 * view, Service_Cookies_Source / Declared_Cookies declared cookies), the daily
8 * refresh Cron, and the REST controller. Other modules consume these views purely
9 * through `surecookie_*` hooks, so this module has no hard dependency on them and
10 * they have none on it.
11 *
12 * @package SureCookie\Inc\Modules\Services
13 * @since 1.3.0
14 */
15
16 namespace SureCookie\Inc\Modules\Services;
17
18 use SureCookie\Inc\Traits\GetInstance;
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit; // Exit if accessed directly.
22 }
23
24 /**
25 * Init
26 *
27 * @since 1.3.0
28 */
29 class Init {
30 use GetInstance;
31
32 /**
33 * Constructor.
34 *
35 * @since 1.3.0
36 */
37 private function __construct() {
38 // Schedules + runs the daily unified-catalog refresh and reconciles
39 // declared cookies. Schedules directly in its own constructor because
40 // modules boot on init:999 - too late for an init-hooked callback.
41 Cron::get_instance();
42
43 // Registry of admin-added services; its constructor wires the read-time
44 // Detected Resources overlay (surecookie_scanned_resources filter).
45 Installed_Services::get_instance();
46
47 // Provide the blocking view to consumers (the Blocker + Scan_Scripts merge)
48 // via the shared filter, so script-blocking stays a pure consumer with no
49 // dependency on this module's classes. Priority 5 seeds the catalog view
50 // before Scan_Scripts (p20) merges scan-detected resources on top.
51 add_filter( 'surecookie_known_scripts', [ $this, 'provide_blocking_view' ], 5 );
52
53 // Register this module's REST controller(s).
54 add_filter( 'surecookie_api_controllers', [ $this, 'register_api_controllers' ], 20 );
55 }
56
57 /**
58 * Seed the `surecookie_known_scripts` filter with the catalog blocking view.
59 *
60 * @param array<string, array<string, mixed>> $scripts Incoming (unseeded) view.
61 * @return array<string, array<string, mixed>> The category => slug => definition view.
62 * @since 1.3.0
63 */
64 public function provide_blocking_view( $scripts = [] ) {
65 $view = Services_Source::get_instance()->get_blocking_view();
66
67 // The catalog is the authoritative base; anything already present merges under it.
68 return is_array( $scripts ) && $scripts !== []
69 ? array_merge( $scripts, $view )
70 : $view;
71 }
72
73 /**
74 * Register this module's REST API controllers.
75 *
76 * @param array<string> $controllers Existing controllers.
77 * @return array<string> Updated controllers.
78 * @since 1.3.0
79 */
80 public function register_api_controllers( $controllers = [] ) {
81 $controllers[] = '\SureCookie\Inc\Modules\Services\Api';
82 return $controllers;
83 }
84 }
85