-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUserController.php
50 lines (42 loc) · 1.03 KB
/
UserController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/**
* @author Martin PAUCOT <contact@martin-paucot.fr>
*/
class UserController extends Controller
{
/**
* @var SerializerInterface
*/
private $serializer;
public function __construct(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}
/**
* Returns the current user.
*
* @Route(
* "user",
* methods={"GET"}
* )
*
* @Security("has_role('ROLE_USER')")
*
* @return Response
*/
public function getUserAction(): Response
{
return new Response(
$this->serializer->serialize(
$this->getUser(),
'json', array('groups' => array('default'))
)
);
}
}