X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Fstats%2FBufferingStatsdDataFactory.php;h=d75d9c0b1ec7b6e9ee71ea3a4b27a98d4bf1e859;hb=b5875a1fbca83f32cb5a160685ab6474d5a552a7;hp=9c18b10f10a9fd53bafe5809d70ba0b620a1225d;hpb=bdfe02223205923d923923dd420ba0dd863cd0fe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/stats/BufferingStatsdDataFactory.php b/includes/libs/stats/BufferingStatsdDataFactory.php index 9c18b10f10..d75d9c0b1e 100644 --- a/includes/libs/stats/BufferingStatsdDataFactory.php +++ b/includes/libs/stats/BufferingStatsdDataFactory.php @@ -32,8 +32,17 @@ use Liuggio\StatsdClient\Factory\StatsdDataFactory; * * @since 1.25 */ -class BufferingStatsdDataFactory extends StatsdDataFactory { +class BufferingStatsdDataFactory extends StatsdDataFactory implements IBufferingStatsdDataFactory { protected $buffer = []; + /** + * Collection enabled? + * @var bool + */ + protected $enabled = true; + /** + * @var string + */ + private $prefix; public function __construct( $prefix ) { parent::__construct(); @@ -49,6 +58,7 @@ class BufferingStatsdDataFactory extends StatsdDataFactory { * * @param string $key * @since 1.26 + * @return string */ private static function normalizeMetricKey( $key ) { $key = preg_replace( '/[:.]+/', '.', $key ); @@ -61,6 +71,9 @@ class BufferingStatsdDataFactory extends StatsdDataFactory { $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT ) { $entity = $this->produceStatsdDataEntity(); + if ( !$this->enabled ) { + return $entity; + } if ( $key !== null ) { $key = self::normalizeMetricKey( "{$this->prefix}.{$key}" ); $entity->setKey( $key ); @@ -79,9 +92,35 @@ class BufferingStatsdDataFactory extends StatsdDataFactory { } /** + * @deprecated Use getData() * @return StatsdData[] */ public function getBuffer() { return $this->buffer; } + + /** + * Check whether this data factory has any data. + * @return bool + */ + public function hasData() { + return !empty( $this->buffer ); + } + + /** + * Return data from the factory. + * @return StatsdData[] + */ + public function getData() { + return $this->buffer; + } + + /** + * Set collection enable status. + * @param bool $enabled Will collection be enabled? + * @return void + */ + public function setEnabled( $enabled ) { + $this->enabled = $enabled; + } }