1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\EventListener; |
26
|
|
|
|
27
|
|
|
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; |
28
|
|
|
|
29
|
|
|
class SecurityEventListener |
30
|
|
|
{ |
31
|
|
|
public $entityManager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param \Doctrine\ORM\EntityManager $entityManager |
35
|
|
|
*/ |
36
|
626 |
|
public function __construct(\Doctrine\ORM\EntityManager $entityManager) |
|
|
|
|
37
|
|
|
{ |
38
|
626 |
|
$this->entityManager = $entityManager; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param InteractiveLoginEvent $event |
43
|
|
|
*/ |
44
|
|
|
public function onInteractiveLogin(InteractiveLoginEvent $event) |
45
|
|
|
{ |
46
|
|
|
$token = $event->getAuthenticationToken(); |
47
|
|
|
|
48
|
|
|
$user = $token->getUser(); |
49
|
|
|
if ($user instanceof \Eccube\Entity\Member) { |
50
|
|
|
$user->setLoginDate(new \DateTime()); |
51
|
|
|
$this->entityManager->persist($user); |
52
|
|
|
$this->entityManager->flush(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
The
EntityManager
might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManager
is closed. Any other code which depends on the same instance of theEntityManager
during this request will fail.On the other hand, if you instead inject the
ManagerRegistry
, thegetManager()
method guarantees that you will always get a usable manager instance.