-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.php
95 lines (79 loc) · 1.65 KB
/
Controller.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
86
87
88
89
90
91
92
93
94
95
<?php
namespace Steel;
use Steel\Injectors\View as ViewInjector;
use Steel\Injectors\Request as RequestInjector;
use Steel\Injectors\Response as ResponseInjector;
use Steel\Injectors\Config as ConfigInjector;
use Steel\Injectors\Event as EventInjector;
use Steel\Controller\Events\Flushed;
/**
* Controller
*/
abstract class Controller
{
use ViewInjector;
use RequestInjector;
use ResponseInjector;
use ConfigInjector;
use EventInjector;
/**
*/
const EVENT_CONTROLLER_FLUSHED = 'ControllerFlushed';
/**
* @var Interfaces\Request
*/
protected $request;
/**
* @var Response
*/
protected $response;
/**
* @var mixed
*/
protected $view;
/**
* @var string
*/
protected $templateName = 'Default';
/**
* Constructor
*/
public function __construct()
{
$this->request = $this->getRequest();
$this->response = $this->getResponse();
$this->view = $this->getView($this->templateName);
}
protected function setTemplate( $name )
{
$this->view->setTemplate( $name );
}
/**
* @param $view
* @return void
*/
public function setView($view)
{
$this->view = $view;
}
/**
* @param $name
* @param $value
* @return mixed
*/
protected function attach($name, $value)
{
return $this->view->attach($name, $value);
}
/**
* Performs the output
*
* @return void
*/
protected function output()
{
$this->view->output();
$this->response->flush();
$this->sendEvent(new Flushed());
}
}