1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Linio\Controller; |
6
|
|
|
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
9
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
10
|
|
|
|
11
|
|
|
trait TemplatingAware |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var EngineInterface |
15
|
|
|
*/ |
16
|
|
|
protected $templating; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @return EngineInterface |
20
|
|
|
*/ |
21
|
|
|
public function getTemplating() |
22
|
|
|
{ |
23
|
|
|
return $this->templating; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param EngineInterface $templating |
28
|
|
|
*/ |
29
|
|
|
public function setTemplating(EngineInterface $templating) |
30
|
|
|
{ |
31
|
|
|
$this->templating = $templating; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns a rendered view. |
36
|
|
|
* |
37
|
|
|
* @param string $view The view name |
38
|
|
|
* @param array $parameters An array of parameters to pass to the view |
39
|
|
|
* |
40
|
|
|
* @return string The rendered view |
41
|
|
|
*/ |
42
|
|
|
public function renderView($view, array $parameters = []) |
43
|
|
|
{ |
44
|
|
|
return $this->templating->render($view, $parameters); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Renders a view. |
49
|
|
|
* |
50
|
|
|
* @param string $view The view name |
51
|
|
|
* @param array $parameters An array of parameters to pass to the view |
52
|
|
|
* @param Response $response A response instance |
|
|
|
|
53
|
|
|
* |
54
|
|
|
* @return Response A Response instance |
55
|
|
|
*/ |
56
|
|
|
public function render($view, array $parameters = [], Response $response = null) |
57
|
|
|
{ |
58
|
|
|
return $this->templating->renderResponse($view, $parameters, $response); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Streams a view. |
63
|
|
|
* |
64
|
|
|
* @param string $view The view name |
65
|
|
|
* @param array $parameters An array of parameters to pass to the view |
66
|
|
|
* @param StreamedResponse $response A response instance |
|
|
|
|
67
|
|
|
* |
68
|
|
|
* @return StreamedResponse A StreamedResponse instance |
69
|
|
|
*/ |
70
|
|
|
public function stream($view, array $parameters = [], StreamedResponse $response = null) |
71
|
|
|
{ |
72
|
|
|
$templating = $this->templating; |
73
|
|
|
|
74
|
|
|
$callback = function () use ($templating, $view, $parameters) { |
75
|
|
|
$templating->stream($view, $parameters); |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
if (null === $response) { |
79
|
|
|
return new StreamedResponse($callback); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$response->setCallback($callback); |
83
|
|
|
|
84
|
|
|
return $response; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.