XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
XCube_Controller.class.php
1<?php
26
27if ( ! defined( 'XCUBE_CORE_PATH' ) ) {
28 define( 'XCUBE_CORE_PATH', __DIR__ );
29}
30
31require_once XCUBE_CORE_PATH . '/XCube_Root.class.php';
32
33require_once XCUBE_CORE_PATH . '/XCube_ActionFilter.class.php';
34require_once XCUBE_CORE_PATH . '/XCube_RenderSystem.class.php';
35require_once XCUBE_CORE_PATH . '/XCube_Delegate.class.php';
36
37require_once XCUBE_CORE_PATH . '/XCube_Object.class.php';
38require_once XCUBE_CORE_PATH . '/XCube_Service.class.php';
39
40require_once XCUBE_CORE_PATH . '/XCube_Identity.class.php';
41require_once XCUBE_CORE_PATH . '/XCube_RoleManager.class.php';
42require_once XCUBE_CORE_PATH . '/XCube_Permission.class.php';
43
44require_once XCUBE_CORE_PATH . '/XCube_LanguageManager.class.php';
45
46require_once XCUBE_CORE_PATH . '/XCube_ActionForm.class.php';
47require_once XCUBE_CORE_PATH . '/XCube_TextFilter.class.php';
48require_once XCUBE_CORE_PATH . '/XCube_Session.class.php';
49
50
57 public $mRoot;
58
64 public $_mBlockChain = [];
65
66
75 public $_mFilterChain = [];
76
83
89 public $mDB;
90
97 public $mLocale;
98
105 public $mLanguage;
106
113 public $mSetupUser = null;
114
121 public $mExecute = null;
122
129 public $mSetupTextFilter = null;
130
131 public function __construct() {
132 // ----- removed by PHP74 refactoring
133 $this->_mBlockChain = [];
134 $this->_mFilterChain = [];
135 $this->_mLoadedFilterNames = [];
136 // ----- reverse for further testing in XCL 2.5.0
137
138 $this->mSetupUser = new XCube_Delegate();
139 $this->mExecute = new XCube_Delegate();
140 $this->mSetupTextFilter = new XCube_Delegate();
141 $this->mSetupTextFilter->add( 'XCube_TextFilter::getInstance', XCUBE_DELEGATE_PRIORITY_FINAL );
142 }
143
150 public function prepare( &$root ) {
151 $this->mRoot =& $root;
152
153 $this->mRoot->setDelegateManager( $this->_createDelegateManager() );
154 $this->mRoot->setServiceManager( $this->_createServiceManager() );
155 $this->mRoot->setPermissionManager( $this->_createPermissionManager() );
156 $this->mRoot->setRoleManager( $this->_createRoleManager() );
157 $this->mRoot->setContext( $this->_createContext() );
158 }
159
166 public function executeCommon() {
167 //
168 // Setup Filter chain and execute the process of these filters.
169 //
170 $this->_setupFilterChain();
171
172 $this->_processFilter();
173
174 $this->_setupEnvironment();
175
176 $this->_setupDB();
177
178 $this->_setupLanguage();
179
180 $this->_setupTextFilter();
181
182 $this->_setupConfig();
183
184 //
185 // Block section
186 //
187 $this->_processPreBlockFilter(); // action filters which have been loaded to the list of the controller.
188
189 $this->_setupSession();
190
191 $this->_setupUser();
192 }
193
200 public function executeHeader() {
201 $this->_setupBlock();
202 $this->_processBlock();
203 }
204
210 public function execute() {
211 $this->mExecute->call( new XCube_Ref( $this ) );
212 }
213
219 public function executeView() {
220 }
221
229 public function executeForward(string $url, int $time = 0, string $message = null ) {
230 // check header output
231 header( 'location: ' . $url );
232 exit();
233 }
234
242 public function executeRedirect(string $url, int $time = 1, string $message = null ) {
243 $this->executeForward( $url, $time, $message );
244 }
245
251 public function addActionFilter( &$filter ) {
252 $this->_mFilterChain[] =& $filter;
253 }
254
259 public function _setupFilterChain() {
260 }
261
266 public function _setupEnvironment() {
267 }
268
274 public function _setupDB() {
275 }
276
282 public function &getDB() {
283 return $this->mDB;
284 }
285
291 public function _setupLanguage() {
292 $this->mRoot->mLanguageManager = new XCube_LanguageManager();
293 }
294
295
301 public function _setupTextFilter() {
302 $textFilter = null;
303 $this->mSetupTextFilter->call( new XCube_Ref( $textFilter ) );
304 $this->mRoot->setTextFilter( $textFilter );
305 }
306
307
312 public function _setupConfig() {
313 }
314
322 public function _setupSession() {
323 $session = new XCube_Session();
324 $this->mRoot->setSession( $session );
325
326 }
327
332 public function _setupUser() {
333 $this->mSetupUser->call( new XCube_Ref( $this->mRoot->mContext->mUser ), new XCube_Ref( $this ), new XCube_Ref( $this->mRoot->mContext ) );
334 }
335
341 public function _processFilter() {
342 foreach ( array_keys( $this->_mFilterChain ) as $key ) {
343 $this->_mFilterChain[ $key ]->preFilter();
344 }
345 }
346
350 public function _setupBlock() {
351 }
352
356 public function _processBlock() {
357 /* foreach(array_keys($this->mBlockChain) as $key) {
358 if ($this->mBlockChain[$key]->hasPermission($this, $this->getUser())) {
359 $renderTarget =new XCube_RenderTarget();
360 $renderTarget->setType(XCUBE_RENDER_TARGET_TYPE_MAIN);
361
362 $this->mBlockChain[$key]->execute($this, $this->getUser(), $renderTarget);
363
364 $this->mBlockChain[$key]->mRenderTarget =& $renderTarget;
365
366 unset($renderTarget);
367 }
368 }*/
369 }
370
376 public function _processPreBlockFilter() {
377 foreach ( array_keys( $this->_mFilterChain ) as $key ) {
378 $this->_mFilterChain[ $key ]->preBlockFilter();
379 }
380 }
381
387 public function _processPostFilter() {
388 foreach ( array_reverse( array_keys( $this->_mFilterChain ) ) as $key ) {
389 $this->_mFilterChain[ $key ]->postFilter();
390 }
391 }
392
401 public function _processPreload( $path ) {
402 $path = $path . '/';
403
404 if ( is_dir( $path ) && ( $files = glob( $path . '/*.class.php' ) ) ) {
405 foreach ( $files as $file ) {
406 require_once $file;
407 $className = basename( $file, '.class.php' );
408 if ( XC_CLASS_EXISTS( $className ) && ! isset( $this->_mLoadedFilterNames[ $className ] ) ) {
409 $this->_mLoadedFilterNames[ $className ] = true;
410 $instance = new $className( $this );
411 $this->addActionFilter( $instance );
412 unset( $instance );
413 }
414 }
415 }
416 }
417
423 public function &_createDelegateManager() {
424 $delegateManager = new XCube_DelegateManager();
425
426 return $delegateManager;
427 }
428
434 public function &_createServiceManager() {
435 require_once XCUBE_CORE_PATH . '/XCube_ServiceManager.class.php';
436 $serviceManager = new XCube_ServiceManager();
437
438 return $serviceManager;
439 }
440
446 public function &_createPermissionManager() {
447 $chunkName = $this->mRoot->getSiteConfig( 'Cube', 'PermissionManager' );
448
449 //
450 // FIXME: Access private method.
451 //
452 $manager =& $this->mRoot->_createInstance( $this->mRoot->getSiteConfig( $chunkName, 'class' ), $this->mRoot->getSiteConfig( $chunkName, 'path' ) );
453
454 return $manager;
455 }
456
462 public function &_createRoleManager() {
463 $chunkName = $this->mRoot->getSiteConfig( 'Cube', 'RoleManager' );
464
465 //
466 // !FIXME: Access private method.
467 //
468 $manager =& $this->mRoot->_createInstance( $this->mRoot->getSiteConfig( $chunkName, 'class' ), $this->mRoot->getSiteConfig( $chunkName, 'path' ) );
469
470 return $manager;
471 }
472
478 public function &_createContext() {
479 $context = new XCube_HttpContext();
480 $request = new XCube_HttpRequest();
481 $context->setRequest( $request );
482
483 return $context;
484 }
485}
executeRedirect(string $url, int $time=1, string $message=null)
executeForward(string $url, int $time=0, string $message=null)
[Final] Used for the simple mechanism for common delegation in XCube.
Manager for delegates.