forked from sonata-project/SonataPageBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFOSRestController.php
56 lines (47 loc) · 1.34 KB
/
FOSRestController.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
51
52
53
54
55
56
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\PageBundle\Controller\Api;
use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View;
/**
* @author Duchkina Anastasiya <duchkina.nast@gmail.com>
*/
abstract class FOSRestController
{
/**
* NEXT_MAJOR: Remove this method, as it should be configured using annotations only.
*
* @return ParamFetcherInterface
*/
final protected function setMapForOrderByParam(ParamFetcherInterface $paramFetcher)
{
$orderByQueryParam = new QueryParam();
$orderByQueryParam->map = true;
$paramFetcher->addParam($orderByQueryParam);
return $paramFetcher;
}
/**
* @param $entity
*
* @return View
*/
final protected function serializeContext($entity, array $groups)
{
$context = new Context();
$context->setGroups($groups);
$context->enableMaxDepth();
$view = View::create($entity);
$view->setContext($context);
return $view;
}
}