fix logger service dependency injection

This commit is contained in:
Mathieu Jaumotte 2021-03-04 16:13:34 +01:00
parent cedf08b906
commit 2c35fb1e5b
2 changed files with 24 additions and 3 deletions

View File

@ -2,6 +2,7 @@
namespace Chill\MainBundle\Controller; namespace Chill\MainBundle\Controller;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -21,7 +22,22 @@ class UserController extends AbstractController
{ {
const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter'; const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter';
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* UserController constructor.
*
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/** /**
* Lists all User entities. * Lists all User entities.
* *
@ -363,7 +379,7 @@ class UserController extends AbstractController
$password = $editForm->get('new_password')->getData(); $password = $editForm->get('new_password')->getData();
// logging for prod // logging for prod
$this->get('logger')->info('update password for an user', [ $this->logger->info('update password for an user', [
'by' => $this->getUser()->getUsername(), 'by' => $this->getUser()->getUsername(),
'user' => $user->getUsername() 'user' => $user->getUsername()
]); ]);

View File

@ -20,8 +20,13 @@ services:
Chill\MainBundle\Controller\PermissionsGroupController: Chill\MainBundle\Controller\PermissionsGroupController:
arguments: arguments:
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
$roleProvider: '@chill.main.role_provider' $roleProvider: '@chill.main.role_provider'
$roleHierarchy: '@security.role_hierarchy' $roleHierarchy: '@security.role_hierarchy'
$translator: '@Symfony\Contracts\Translation\TranslatorInterface' $translator: '@Symfony\Contracts\Translation\TranslatorInterface'
tags: ['controller.service_arguments'] tags: ['controller.service_arguments']
Chill\MainBundle\Controller\UserController:
arguments:
$logger: '@Psr\Log\LoggerInterface'
tags: ['controller.service_arguments']