forked from DATA-DOG/DataDogAuditBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
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 DATA-DOG#31 from chancegarcia/documentation
Resolves Example for labeler DATA-DOG#11
- Loading branch information
Showing
2 changed files
with
65 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,52 @@ | ||
#Setting a Labeler | ||
|
||
Create a Labeler class/method. | ||
|
||
\AppBundle\Labler\AuditLabler | ||
|
||
namespace AppBundle\Labler; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class AuditLabler | ||
{ | ||
public static function getLabel( $entity) { | ||
if ($entity instanceof UserInterface) { | ||
return $entity->getUsername(); | ||
} | ||
|
||
return 'Unlabeled'; | ||
} | ||
} | ||
|
||
Re-define the audit subscriber service to call the `setLabler` method of the AuditSubscriber with the [callable](http://php.net/manual/en/language.types.callable.php). | ||
|
||
app/config/config.yml | ||
|
||
services: | ||
... | ||
datadog.event_subscriber.audit: | ||
class: 'DataDog\AuditBundle\EventSubscriber\AuditSubscriber' | ||
arguments: ["@security.token_storage"] | ||
tags: | ||
- { name: doctrine.event_subscriber, connection: default } | ||
calls: | ||
- ['setLabeler', [['\AppBundle\Labler\AuditLabler', 'getLabel']]] | ||
... | ||
or define in your services file | ||
|
||
app/config/services.xml | ||
|
||
... | ||
<service id="datadog.event_subscriber.audit" class="DataDog\AuditBundle\EventSubscriber\AuditSubscriber"> | ||
<argument type="service" id="security.token_storage"/> | ||
<tag name="doctrine.event_subscriber"/> | ||
<call method="setLabeler"> | ||
<argument type="collection"> | ||
<argument>\AppBundle\Labler\AuditLabler</argument> | ||
<argument>getLabel</argument> | ||
</argument> | ||
</call> | ||
</service> | ||
... |
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