mirror of
https://github.com/felixfoertsch/wordpress-dev-env.git
synced 2026-04-18 15:28:44 +02:00
Initial commit
This commit is contained in:
74
wordpress_plugins/query-monitor/classes/Collectors.php
Normal file
74
wordpress_plugins/query-monitor/classes/Collectors.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Container for data collectors.
|
||||
*
|
||||
* @package query-monitor
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'QM_Collectors' ) ) {
|
||||
class QM_Collectors implements IteratorAggregate {
|
||||
|
||||
private $items = array();
|
||||
private $processed = false;
|
||||
|
||||
public function getIterator() {
|
||||
return new ArrayIterator( $this->items );
|
||||
}
|
||||
|
||||
public static function add( QM_Collector $collector ) {
|
||||
$collectors = self::init();
|
||||
|
||||
$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();
|
||||
if ( isset( $collectors->items[ $id ] ) ) {
|
||||
return $collectors->items[ $id ];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function init() {
|
||||
static $instance;
|
||||
|
||||
if ( ! $instance ) {
|
||||
$instance = new QM_Collectors();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user