Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Laravel5 support and default config
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
return [ | ||
'host' => '127.0.0.1', | ||
|
||
'port' => 8125, | ||
|
||
'namespace' => '' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
); | ||
} | ||
} |