self::NULL, 'statsd' => self::STATSD, 'dogstatsd' => self::DOGSTATSD ]; /** * Convert friendly format name to integer. * * @param string $format * @return int */ public static function getFormatFromString( string $format ): int { if ( self::SUPPORTED_FORMATS[$format] ?? false ) { return self::SUPPORTED_FORMATS[$format]; } throw new UnsupportedFormatException( "Format '" . $format . "' not supported. Expected one of " . json_encode( array_keys( self::SUPPORTED_FORMATS ) ) ); } /** * Returns an instance of the requested formatter. * * @param int $format * @return FormatterInterface */ public static function getNewFormatter( int $format ): FormatterInterface { switch ( $format ) { case self::DOGSTATSD: return new DogStatsdFormatter(); case self::STATSD: return new StatsdFormatter(); case self::NULL: return new NullFormatter(); default: throw new UnsupportedFormatException( 'Unsupported metrics format. Got format: ' . $format ); } } /** * Returns an emitter instance appropriate the formatter instance. * * @param string $prefix * @param StatsCache $cache * @param FormatterInterface $formatter * @param string|null $target * @return EmitterInterface */ public static function getNewEmitter( string $prefix, StatsCache $cache, FormatterInterface $formatter, string $target = null ): EmitterInterface { switch ( get_class( $formatter ) ) { case StatsdFormatter::class: case DogStatsdFormatter::class: return new UDPEmitter( $prefix, $cache, $formatter, $target ); case NullFormatter::class: return new NullEmitter; default: throw new UnsupportedFormatException( 'Unsupported metrics format. Got format: ' . get_class( $formatter ) ); } } }