Completed
Push — master ( ff2012...83cef1 )
by Igor
02:43
created

BaseController::setView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
 * @license MIT
4
 * @author Igor Sorokin <[email protected]>
5
 */
6
namespace Dspbee\Core;
7
8
use Dspbee\Bundle\Template\Native;
9
10
/**
11
 * Base functions to process request.
12
 *
13
 * Class BaseController
14
 * @package Dspbee\Core
15
 */
16
class BaseController
17
{
18
    /**
19
     * @param string $packageRoot
20
     * @param Request $request
21
     */
22
    public function __construct($packageRoot, Request $request)
23
    {
24
        $this->packageRoot = $packageRoot;
25
        $this->request = $request;
26
        $this->response = null;
27
    }
28
29
    /**
30
     * @return Response|null
31
     */
32
    public function getResponse()
33
    {
34
        return $this->response;
35
    }
36
37
    /**
38
     * @param Response $response
39
     */
40
    public function setResponse(Response $response)
41
    {
42
        $this->response = $response;
43
    }
44
45
    /**
46
     * Create Response from template.
47
     *
48
     * @param string $name
49
     * @param array $data
50
     */
51
    public function setView($name = '', array $data = [])
52
    {
53
        $this->response = new Response;
54
        $this->response->setContent((new Native($this->packageRoot, $this->request))->getContent($name, $data));
55
    }
56
57
    /**
58
     * Create Response from content.
59
     *
60
     * @param string $content
61
     */
62
    public function setContent($content)
63
    {
64
        $this->response = new Response();
65
        $this->response->setContent($content);
66
    }
67
68
    /**
69
     * Redirect to URL with statusCode and terminate app.
70
     *
71
     * @param null $url
72
     * @param int $statusCode
73
     */
74
    public function setRedirect($url = null, $statusCode = 307)
75
    {
76
        $this->response = new Response();
77
        $this->response->redirect($url, $statusCode);
78
    }
79
80
    protected $packageRoot;
81
    protected $request;
82
    protected $response;
83
}