-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXoopsController.php
163 lines (146 loc) · 5.05 KB
/
XoopsController.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?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;
/**
* XoopsController implements a controller with with specific
* characteristics optimized for the XOOPS environment, including:
* - XOOPS specific User and AuthorizationHandler
* - XOOPS module helper
* - XOOPS module appropriate configuration, defaults and autoloading
*
* @category Xmf\Xadr\XoopsController
* @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
*/
class XoopsController extends Controller
{
/**
* @var string XOOPS Module directory name
*/
protected $dirname;
/**
* @var object XOOPS Module helper
*/
protected $moduleHelper;
/**
* @var XoopsUser instance
*/
protected $user;
/**
* XOOPS specific controller constructor, sets user and
* authorization handler to XOOPS specific onjects.
*
* @param Request|null $request Request object, or null for default request
* @param Response|null $response Response object, or null for default response
*/
protected function __construct($request = null, $response = null)
{
parent::__construct($request, $response);
$xoops = \Xoops::getInstance();
if (is_object($request) && $request->attributes()->has('dirname')) {
$this->dirname = $request->attributes()->get('dirname');
} else {
$this->dirname = $xoops->isModule() ? $xoops->module->getVar('dirname') : 'system';
}
$this->moduleHelper = $xoops->getModuleHelper($this->dirname);
//$this->moduleHelper->setDebug(true);
$this->nameSpace = (string) $this->modGetInfo('xadr_namespace');
// this will quietly ignore a missing config file
$classname = $this->nameSpace . "\\Configuration";
if (class_exists($classname)) {
new $classname($this);
}
// set some reasonable defaults if config is empty
if (!$this->config->get('DEFAULT_UNIT', false)) {
//$pathname=$xoops->path('modules/'.$this->dirname.'/');
//$this->config->set('UNITS_DIR', $pathname.'class/xadr/');
$this->config->set('SCRIPT_PATH', $xoops->url('modules/'.$this->dirname.'/index.php'));
$this->config->set('UNIT_ACCESSOR', 'unit');
$this->config->set('ACTION_ACCESSOR', 'action');
$this->config->set('DEFAULT_UNIT', 'App');
$this->config->set('DEFAULT_ACTION', 'Index');
$this->config->set('ERROR_404_UNIT', 'App');
$this->config->set('ERROR_404_ACTION', 'PageNotFound');
$this->config->set('SECURE_UNIT', 'App');
$this->config->set('SECURE_ACTION', 'NoPermission');
}
$this->user = new XoopsUser($this);
$this->authorizationHandler = new XoopsAuthHandler($this);
$this->user->setXoopsPermissionMap($this->config->get('PermissionMap', array()));
}
// These methods provide quick access to some XOOPS objects.
// The controller already is module aware and has a module
// helper established. Share that.
/**
* getHandler - get XoopsObjectHandler
*
* @param string $name name of an object handler
*
* @return bool|XoopsObjectHandler|XoopsPersistableObjectHandler
*/
public function getHandler($name)
{
return $this->moduleHelper->getHandler($name);
}
/**
* moduleHelper - get module helper
*
* @return object Module Helper
*/
public function moduleHelper()
{
return $this->moduleHelper;
}
/**
* modGetVar - get varaible from XoopsModule
*
* @param string $name name of module variable
*
* @return mixed module getVar return
*/
public function modGetVar($name)
{
return $this->moduleHelper->getModule()->getVar($name);
}
/**
* modGetInfo - get modversion item
*
* @param string $name name of module info variable
*
* @return mixed module getInfo return
*/
public function modGetInfo($name)
{
return $this->moduleHelper->getModule()->getInfo($name);
}
/**
* modGetConfig - get a module configuration value
*
* @param string $name name of module configuration
*
* @return mixed module helper getConfig return
*/
public function modGetConfig($name)
{
return $this->moduleHelper->getConfig($name);
}
/**
* getDirname
*
* @return string
*/
public function getDirname()
{
return $this->dirname;
}
}