{"id":24292341,"url":"https://github.com/loremipsum/action-logger-bundle","last_synced_at":"2025-03-06T04:26:35.785Z","repository":{"id":57015581,"uuid":"163268775","full_name":"loremipsum/action-logger-bundle","owner":"loremipsum","description":"Symfony bundle to log custom actions and events with doctrine.","archived":false,"fork":false,"pushed_at":"2020-01-10T13:42:51.000Z","size":47,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T15:29:37.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loremipsum.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-27T08:30:27.000Z","updated_at":"2020-01-10T13:42:53.000Z","dependencies_parsed_at":"2022-08-22T09:31:44.332Z","dependency_job_id":null,"html_url":"https://github.com/loremipsum/action-logger-bundle","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loremipsum%2Faction-logger-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loremipsum%2Faction-logger-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loremipsum%2Faction-logger-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loremipsum%2Faction-logger-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loremipsum","download_url":"https://codeload.github.com/loremipsum/action-logger-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242147137,"owners_count":20079496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-16T15:29:38.437Z","updated_at":"2025-03-06T04:26:35.765Z","avatar_url":"https://github.com/loremipsum.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActionLogger bundle\n\nSymfony bundle to log custom actions and events with doctrine.\n\n## Configuration\n\n```yaml\n# config/packages/lorem_ipsum_action_logger.yaml \n\nlorem_ipsum_action_logger:\n    # mapping is used to store actions in the database without using the class name\n    mapping:\n        user.add: { class: App\\Action\\User\\UserAddAction }\n        user.edit: { class: App\\Action\\User\\UserEditAction, alias: 'user_edit' }\n        settings.edit: { class: App\\Action\\SettingsEditAction, alias: ['settings_edit', 'settings_update'] }\n    # entity_mapping is used to store action relations to entities in the database using the class name\n    entity_mapping:\n        user: App\\Entity\\User\n        settings: App\\Entity\\Settings\n```\n\n## Action example\n\nUsage example:  \nA new user has been created. All you have to do is call `log` or `flashLog` \non our ActionLogger with the `UserAddAction` and the new `$user` entity.\n\n```php\n/** @var LoremIpsum\\ActionLoggerBundle\\ActionLogger $actionLogger **/\n$actionLogger-\u003elog(new UserAddAction($user));\n// Display action message as flash message\n$actionLogger-\u003eflashLog(new UserAddAction($user), 'success');\n```\n\nAnd here is our `UserAddAction`:\n\n```php\n\u003c?php\n\nnamespace App\\Action\\User;\n\nuse App\\Entity\\User;\nuse Doctrine\\Common\\Persistence\\ObjectManager;\nuse LoremIpsum\\ActionLoggerBundle\\Action\\EntityAction;\nuse LoremIpsum\\ActionLoggerBundle\\Entity\\LogAction;\nuse LoremIpsum\\RouteGeneratorBundle\\Model\\RouteGeneratorInterface;\n\nclass UserAddAction extends EntityAction\n{\n    /**\n     * @var User\n     */\n    protected $entity;\n\n    public function __construct(User $entity = null)\n    {\n        parent::__construct($entity);\n    }\n    \n    public function getIcon()\n    {\n        return 'fa fa-plus';\n    }\n\n    public function getLevel(): int\n    {\n        return LogAction::LEVEL_INFO;\n    }\n\n    protected function load(ObjectManager $em)\n    {\n        $this-\u003eentity = $em-\u003egetRepository(User::class)-\u003efind($this-\u003emeta['id']);\n    }\n\n    private function getLink(RouteGeneratorInterface $router = null): array\n    {\n        if (! $router || ! $this-\u003eentity instanceof User) {\n            return ['%entity%', ['%entity%' =\u003e $this-\u003emeta['name']]];\n        }\n        return [\"\u003ca href=\\\"{$router-\u003egenerate($this-\u003eentity)}\\\"\u003e%entity%\u003c/a\u003e\", ['%entity%' =\u003e $this-\u003eentity]];\n    }\n    \n    public function getMessage(RouteGeneratorInterface $router = null)\n    {\n        list($entity, $entities) = $this-\u003egetLink($router);\n        return [\"User $entity added.\", $entities];\n    }\n\n    public function getUserMessage(RouteGeneratorInterface $router = null)\n    {\n        list($user, $users) = $this-\u003egetUserLink($router);\n        list($entity, $entities) = $this-\u003egetLink($router);\n        return [\"$user added user $entity.\", $users, $entities];\n    }\n}\n```\n\n## Event subscriber example\n\nLog all action events with Psr\\Log\\LoggerInterface.\n\n```php\n\u003c?php\n\nnamespace App\\EventListener;\n\nuse LoremIpsum\\ActionLoggerBundle\\Event\\ActionEvent;\nuse Psr\\Log\\LoggerInterface;\nuse Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\n\nclass ActionLogListener implements EventSubscriberInterface\n{\n    private $logger;\n\n    public function __construct(LoggerInterface $logger)\n    {\n        $this-\u003elogger = $logger;\n    }\n\n    public function onLog(ActionEvent $event)\n    {\n        $action = $event-\u003egetAction();\n        $this-\u003elogger-\u003edebug('[ActionLogListener] ' . $event-\u003egetActionFactory()-\u003egetAction(get_class($action)), $action-\u003egetUserMessage());\n    }\n\n    public static function getSubscribedEvents()\n    {\n        return [\n            ActionEvent::class =\u003e 'onLog',\n        ];\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floremipsum%2Faction-logger-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floremipsum%2Faction-logger-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floremipsum%2Faction-logger-bundle/lists"}