diff --git a/config/statsd.php b/config/statsd.php new file mode 100644 index 0000000..d5aa80f --- /dev/null +++ b/config/statsd.php @@ -0,0 +1,9 @@ + '127.0.0.1', + + 'port' => 8125, + + 'namespace' => '' +]; \ No newline at end of file diff --git a/src/Laravel5/Facade/StatsdFacade.php b/src/Laravel5/Facade/StatsdFacade.php new file mode 100644 index 0000000..bf3203f --- /dev/null +++ b/src/Laravel5/Facade/StatsdFacade.php @@ -0,0 +1,24 @@ + + * @package League\StatsD\Laravel5\Facade + */ +class StatsdFacade extends Facade +{ + /** + * Get the registered name of the component. + * + * @return string + */ + protected static function getFacadeAccessor() + { + return 'statsd'; + } +} diff --git a/src/Laravel5/Provider/StatsdServiceProvider.php b/src/Laravel5/Provider/StatsdServiceProvider.php new file mode 100644 index 0000000..f4a292c --- /dev/null +++ b/src/Laravel5/Provider/StatsdServiceProvider.php @@ -0,0 +1,67 @@ + + */ +class StatsdServiceProvider extends ServiceProvider +{ + + /** + * Boot the service provider. + * + * @return void + */ + public function boot() + { + // Publish config files + $this->publishes([ + __DIR__.'/../../../../config/config.php' => config_path('entrust.php'), + ]); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerStatsD(); + } + + /** + * Register Statsd + * + * @return void + */ + protected function registerStatsD() + { + $this->app['statsd'] = $this->app->share( + function ($app) { + // Set Default host and port + $options = array(); + if (isset($app['config']['statsd.host'])) { + $options['host'] = $app['config']['statsd.host']; + } + if (isset($app['config']['statsd.port'])) { + $options['port'] = $app['config']['statsd.port']; + } + if (isset($app['config']['statsd.namespace'])) { + $options['namespace'] = $app['config']['statsd.namespace']; + } + + // Create + $statsd = new Statsd(); + $statsd->configure($options); + return $statsd; + } + ); + } +}