*
* @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();
*
* @param string $key
* @since 1.26
+ * @return string
*/
private static function normalizeMetricKey( $key ) {
$key = preg_replace( '/[:.]+/', '.', $key );
$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 );
}
/**
+ * @deprecated Use getData()
* @return StatsdData[]
*/
public function getBuffer() {
return $this->buffer;
}
+
+ /**
+ * Check whether this data factory has any data.
+ * @return boolean
+ */
+ 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;
+ }
}