Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CodexServices
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 loadServiceWiring
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getInstance
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare( strict_types = 1 );
3
4/**
5 * CodexServices.php
6 *
7 * This class is part of the Codex design system and manages the retrieval and instantiation
8 * of various renderers and services. It follows dependency injection principles, ensuring services are
9 * injected and reused throughout the system. Services include renderers for
10 * various UI components and utilities like Mustache and Localization.
11 *
12 * @category Infrastructure
13 * @package  Codex\Infrastructure
14 * @since    0.1.0
15 * @author   Doğu Abaris <abaris@null.net>
16 * @license  https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later
17 * @link     https://doc.wikimedia.org/codex/main/ Codex Documentation
18 */
19
20namespace Wikimedia\Codex\Infrastructure;
21
22use Wikimedia\Services\ServiceContainer;
23
24/**
25 * CodexServices
26 *
27 * Service locator for Codex services.
28 *
29 * Refer to src/Infrastructure/ServiceWiring.php for the default implementations.
30 *
31 * @category Infrastructure
32 * @package  Codex\Infrastructure
33 * @since    0.1.0
34 * @author   Doğu Abaris <abaris@null.net>
35 * @license  https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later
36 * @link     https://doc.wikimedia.org/codex/main/ Codex Documentation
37 */
38class CodexServices extends ServiceContainer {
39
40    /**
41     * Instance of CodexServices (singleton)
42     */
43    private static ?self $instance = null;
44
45    /**
46     * Private constructor to initialize the DI container, and load service wiring.
47     */
48    private function __construct() {
49        parent::__construct();
50        $this->loadServiceWiring();
51    }
52
53    /**
54     * Load service wiring from the ServiceWiring.php file.
55     *
56     * @since 0.1.0
57     * @return void
58     */
59    private function loadServiceWiring(): void {
60        $wiring = require __DIR__ . '/ServiceWiring.php';
61        $this->applyWiring( $wiring );
62    }
63
64    /**
65     * Retrieves the global default instance of the Codex service locator.
66     *
67     * @since 0.1.0
68     * @return self The default instance of the CodexServices.
69     */
70    public static function getInstance(): self {
71        if ( self::$instance === null ) {
72            self::$instance = new self();
73        }
74
75        return self::$instance;
76    }
77}