/var/www/html_nl/wp-content/plugins/query-monitor/classes/Collectors.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php declare(strict_types 1);
/**
 * Container for data collectors.
 *
 * @package query-monitor
 */

if ( ! class_exists'QM_Collectors' ) ) {
/**
 * @implements \IteratorAggregate<string, QM_Collector>
 */
class QM_Collectors implements IteratorAggregate {

    
/**
     * @var array<string, QM_Collector>
     */
    
private $items = array();

    
/**
     * @var boolean
     */
    
private $processed false;

    
/**
     * @return ArrayIterator<string, QM_Collector>
     */
    
#[\ReturnTypeWillChange]
    public function 
getIterator() {
        return new 
ArrayIterator$this->items );
    }

    
/**
     * @param QM_Collector $collector
     * @return void
     */
    
public static function addQM_Collector $collector ) {
        
$collectors self::init();

        
$collector->set_up();

        
$collectors->items$collector->id ] = $collector;
    }

    
/**
     * Fetches a collector instance.
     *
     * @param string $id The collector ID.
     * @return QM_Collector|null The collector object.
     */
    
public static function get$id ) {
        
$collectors self::init();

        return 
$collectors->items$id ] ?? null;
    }

    
/**
     * @return self
     */
    
public static function init() {
        static 
$instance;

        if ( ! 
$instance ) {
            
$instance = new QM_Collectors();
        }

        return 
$instance;

    }

    
/**
     * @return void
     */
    
public function process() {
        if ( 
$this->processed ) {
            return;
        }

        foreach ( 
$this as $collector ) {
            
$collector->tear_down();

            
$timer = new QM_Timer();
            
$timer->start();

            
$collector->process();
            
$collector->process_concerns();

            
$collector->set_timer$timer->stop() );
        }

        foreach ( 
$this as $collector ) {
            
$collector->post_process();
        }

        
$this->processed true;
    }

    
/**
     * @return void
     */
    
public static function cease() {
        
$collectors self::init();

        
$collectors->processed true;

        
/** @var QM_Collector $collector */
        
foreach ( $collectors as $collector ) {
            
$collector->tear_down();
            
$collector->discard_data();
        }
    }
}
}