forked from symfony-cmf/blog-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseController.php
85 lines (74 loc) · 2.28 KB
/
BaseController.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Bundle\BlogBundle\Controller;
use Knp\Component\Pager\Paginator;
use Symfony\Cmf\Bundle\BlogBundle\Model\Post;
use Symfony\Cmf\Bundle\BlogBundle\Model\Blog;
use Symfony\Cmf\Bundle\BlogBundle\Repository\PostRepository;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use FOS\RestBundle\View\ViewHandlerInterface;
use FOS\RestBundle\View\View;
/**
* Base Controller
*
* @author Daniel Leech <[email protected]>
*/
abstract class BaseController
{
/**
* @var EngineInterface
*/
protected $templating;
/**
* @var SecurityContextInterface
*/
protected $securityContext;
/**
* @var ViewHandlerInterface
*/
protected $viewHandler;
/**
* Constructor
*
* @param EngineInterface $templating
* @param SecurityContextInterface $securityContext
* @param ViewHandlerInterface $viewHandler
*/
public function __construct(
EngineInterface $templating,
SecurityContextInterface $securityContext,
ViewHandlerInterface $viewHandler = null
) {
$this->templating = $templating;
$this->securityContext = $securityContext;
$this->viewHandler = $viewHandler;
}
protected function renderResponse($contentTemplate, $params)
{
if ($this->viewHandler) {
$view = new View($params);
$view->setTemplate($contentTemplate);
return $this->viewHandler->handle($view);
}
return $this->templating->renderResponse($contentTemplate, $params);
}
protected function getTemplateForResponse(Request $request, $contentTemplate)
{
return str_replace(
array('{_format}', '{_locale}'),
array($request->getRequestFormat(), $request->getLocale()),
$contentTemplate
);
}
}