Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Dashboard_Support
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 load
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Public entry point for hosts that render a widget dashboard without booting Stats v2.
4 *
5 * @package automattic/jetpack-premium-analytics
6 */
7
8namespace Automattic\Jetpack\PremiumAnalytics;
9
10/**
11 * Loads what a page needs to host a widget dashboard: the dashboard API and the shared
12 * script modules a widget bundle imports.
13 *
14 * It injects no section script data, and for now the page hooks add_widget_modules_to_boot_deps()
15 * to its own boot dependencies filter. The REST half is Dashboard_Support_Routes::register().
16 *
17 * @since 0.19.0
18 */
19class Dashboard_Support {
20
21    /**
22     * Path to the generated script module registration. Null uses the generated build.
23     *
24     * A test seam, as Analytics::$build_entry is: `build/` is gitignored and test-php runs no build step.
25     *
26     * @var string|null
27     */
28    private static $modules_entry = null;
29
30    /**
31     * Load the dashboard API and register the shared script modules and the SDK alias.
32     *
33     * Idempotent. Call it before `wp_default_scripts` fires, on the requests that render the
34     * host's page: that hook is where the modules register.
35     *
36     * @since 0.19.0
37     *
38     * @return void
39     */
40    public static function load() {
41        // Widget modules for the client's dynamic import() map.
42        require_once __DIR__ . '/widget-modules.php';
43
44        // Default layout primitives and the bundled defaults' seed.
45        require_once __DIR__ . '/dashboard-layout.php';
46
47        // Dashboard section API.
48        require_once __DIR__ . '/dashboard-sections.php';
49
50        $modules_entry = self::$modules_entry ?? __DIR__ . '/../build/modules.php';
51        if ( file_exists( $modules_entry ) ) {
52            require_once $modules_entry;
53            require_once __DIR__ . '/sdk-module.php';
54        }
55    }
56}