Skip to content

Commit

Permalink
Add Laravel5 support and default config
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkiii committed Aug 30, 2015
1 parent 8f425cf commit 7d592d5
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/statsd.php
@@ -0,0 +1,9 @@
<?php

return [
'host' => '127.0.0.1',

'port' => 8125,

'namespace' => ''
];
24 changes: 24 additions & 0 deletions src/Laravel5/Facade/StatsdFacade.php
@@ -0,0 +1,24 @@
<?php

namespace League\StatsD\Laravel5\Facade;

use Illuminate\Support\Facades\Facade;

/**
* Facade for Statsd Package
*
* @author Aran Wilkinson <aran@aranw.net>
* @package League\StatsD\Laravel5\Facade
*/
class StatsdFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'statsd';
}
}
67 changes: 67 additions & 0 deletions src/Laravel5/Provider/StatsdServiceProvider.php
@@ -0,0 +1,67 @@
<?php

namespace League\StatsD\Laravel5\Provider;

use Illuminate\Support\ServiceProvider;
use League\StatsD\Client as Statsd;

/**
* StatsD Service provider for Laravel
*
* @author Aran Wilkinson <aran@aranw.net>
*/
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;
}
);
}
}

0 comments on commit 7d592d5

Please sign in to comment.