forked from domnikl/statsd-php
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Slickdeals/add-aware-trait
Add aware interface to easily auto-inject client
- Loading branch information
Showing
10 changed files
with
107 additions
and
38 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 @@ | ||
{"commitizen": {"name": "cz_conventional_commits", "version": "3.0.2", "tag_format": "$version"}} |
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
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 |
---|---|---|
|
@@ -13,3 +13,6 @@ stats.log | |
/vendor | ||
/composer.lock | ||
/composer.phar | ||
|
||
# php-cs-fixer | ||
.php-cs-fixer.cache |
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,13 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__) | ||
; | ||
|
||
$config = new PhpCsFixer\Config(); | ||
return $config->setRules([ | ||
'@PSR12' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
]) | ||
->setFinder($finder) | ||
; |
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 |
---|---|---|
|
@@ -102,6 +102,33 @@ To disable sending any metrics to the statsd server, you can use the `Domnikl\St | |
class instead of the default socket abstraction. This may be incredibly useful for feature flags. Another options is | ||
to use `Domnikl\Statsd\Connection\InMemory` connection class, that will collect your messages but won't actually send them. | ||
|
||
## StatsdAwareInterface | ||
|
||
You can use the `StatsdAwareInterface` and `StatsdAwareTrait` in order to have dependency injection containers (such as | ||
Symfony's DI component) automatically detect the StatsdAwareInterface and inject the client into your service. | ||
|
||
### Symfony | ||
|
||
```yaml | ||
# config/services.yaml | ||
services: | ||
_instanceof: | ||
Domnikl\Statsd\StatsdAwareInterface: | ||
calls: | ||
- [setStatsdClient, ['@Domnikl\Statsd\Client']] | ||
|
||
Domnikl\Statsd\Client: | ||
arguments: | ||
$connection: '@app.statsd_connection' | ||
$namespace: '<namespace>' | ||
|
||
app.statsd_connection: | ||
class: Domnikl\Statsd\Connection\UdpSocket | ||
arguments: | ||
$host: '%env(STATSD_HOST)%' | ||
$port: '%env(STATSD_PORT)%' | ||
``` | ||
## Authors | ||
Original author: Dominik Liebler <[email protected]> | ||
|
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
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
<?php | ||
|
||
namespace Domnikl\Statsd; | ||
|
||
/** | ||
* Describes a StatsD-aware instance. | ||
*/ | ||
interface StatsdAwareInterface | ||
{ | ||
/** | ||
* Sets a StatsD client instance on the object. | ||
*/ | ||
public function setStatsdClient(Client $client): void; | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Domnikl\Statsd; | ||
|
||
/** | ||
* Basic implementation of StatsdAwareInterface. | ||
*/ | ||
trait StatsdAwareTrait | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
protected $statsd; | ||
|
||
/** | ||
* Sets the StatsD client. | ||
*/ | ||
public function setStatsdClient(Client $client) | ||
{ | ||
$this->statsd = $client; | ||
} | ||
} |
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