Completed
Push — master ( aa6241...8ade87 )
by Jean-Christophe
02:11
created

WithAuthTrait::_getAuthController()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
namespace Ubiquity\controllers\auth;
3
4
use Ubiquity\utils\http\URequest;
5
use Ubiquity\controllers\Startup;
6
7
/**
8
 * ControllerBase
9
 **/
10
trait WithAuthTrait{
11
	
12
	/**
13
	 * @var AuthController
14
	 */
15
	protected $authController;
16
	
17
	public function initialize(){
18
		parent::initialize();
19
		if(!URequest::isAjax()){
20
			$this->_getAuthController()->info();
21
		}
22
	}
23
24
	/**
25
	 * {@inheritDoc}
26
	 * @see \Ubiquity\controllers\Controller::isValid()
27
	 */
28
	public function isValid() {
29
		return $this->_getAuthController()->_isValidUser();
30
	}
31
32
	/**
33
	 * {@inheritDoc}
34
	 * @see \Ubiquity\controllers\Controller::onInvalidControl()
35
	 */
36
	public function onInvalidControl() {
37
		$auth=$this->_getAuthController();
38
		$auth->initialize();
39
		$auth->noAccess(Startup::$urlParts);
40
		$auth->finalize();
41
		exit();
42
	}
43
	
44
	/**
45
	 * @return \Ubiquity\controllers\auth\AuthController
46
	 */
47
	protected function _getAuthController():AuthController{
48
		if(!isset($this->authController)){
49
			$this->authController=$this->getAuthController();
50
		}
51
		return $this->authController;
52
	}
53
	
54
	protected abstract function getAuthController():AuthController;
55
56
}
57