bytic /
controllers
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Nip\Controllers\Response\ResponseFactory; |
||||||
| 4 | |||||||
| 5 | use Nip\Http\Response\Response; |
||||||
| 6 | use Nip\View\View; |
||||||
| 7 | |||||||
| 8 | /** |
||||||
| 9 | * Trait HasViewResponseTrait |
||||||
| 10 | * @package Nip\Controllers\Response\ResponseFactory |
||||||
| 11 | */ |
||||||
| 12 | trait HasViewResponseTrait |
||||||
| 13 | { |
||||||
| 14 | /** |
||||||
| 15 | * @var null|View |
||||||
| 16 | */ |
||||||
| 17 | protected $view = null; |
||||||
| 18 | |||||||
| 19 | /** |
||||||
| 20 | * Create a new response for a given view. |
||||||
| 21 | * |
||||||
| 22 | * @param string|array $view |
||||||
| 23 | * @param array $data |
||||||
| 24 | * @param int $status |
||||||
| 25 | * @param array $headers |
||||||
| 26 | * @return Response |
||||||
| 27 | */ |
||||||
| 28 | public function view($view, $data = [], $status = 200, array $headers = []) |
||||||
| 29 | { |
||||||
| 30 | return $this->make($this->renderView($view, $data), $status, $headers); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
It seems like
make() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 31 | } |
||||||
| 32 | |||||||
| 33 | /** |
||||||
| 34 | * @param string $view |
||||||
| 35 | * @param array $data |
||||||
| 36 | * @return bool|string|null |
||||||
| 37 | */ |
||||||
| 38 | protected function renderView($view, $data = []) |
||||||
| 39 | { |
||||||
| 40 | foreach ($data as $key => $value) { |
||||||
| 41 | $this->view->set($key, $value); |
||||||
|
0 ignored issues
–
show
The method
set() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 42 | } |
||||||
| 43 | return $this->view->load($view, [], true); |
||||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | /** |
||||||
| 47 | * @param View|null $view |
||||||
| 48 | */ |
||||||
| 49 | public function setView(?View $view): void |
||||||
| 50 | { |
||||||
| 51 | $this->view = $view; |
||||||
| 52 | } |
||||||
| 53 | } |
||||||
| 54 |