-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContextAware.php
121 lines (108 loc) · 2.63 KB
/
ContextAware.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace Xmf\Xadr;
/**
* Extending ContextAware makes shared context, such as controller, config,
* request and domain objects readily available in a class
*
* @category Xmf\Xadr\ContextAware
* @package Xmf
* @author Richard Griffith <[email protected]>
* @copyright 2013-2015 XOOPS Project (http://xoops.org)
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
* @link http://xoops.org
*/
abstract class ContextAware
{
protected $context = null;
/**
* ContextAware __construct
*
* @param Controller $context - context object
*/
final public function __construct(Controller $context)
{
$this->context = $context;
$this->initContextAware();
}
/**
* init - called by __construct. Sub classes can put any contructor code
* here, rather than overriding __construct
*
* @return void
*/
protected function initContextAware()
{
return;
}
/**
* Instance of the Config object
*
* @return Config configuration object
*/
public function config()
{
return $this->context->getConfig();
}
/**
* Instance of the full context. At present this is the controller
*
* @return object shared context
*/
public function context()
{
return $this->context;
}
/**
* Get the controller context
*
* @return Controller instance
*/
public function controller()
{
return $this->context;
}
/**
* Get the request context
*
* @return Request instance
*/
public function request()
{
return $this->context->getRequest();
}
/**
* Get the response context
*
* @return Response instance
*/
public function response()
{
return $this->context->getResponse();
}
/**
* Get the user context
*
* @return User instance
*/
public function user()
{
return $this->context-> getUser();
}
/**
* Get the DomainManager instance
*
* @return DomainManager instance
*/
public function domain()
{
return $this->context->getDomainManager();
}
}