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

WithAuthTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 2
A isValid() 0 3 1
A onInvalidControl() 0 7 1
A _getAuthController() 0 6 2
getAuthController() 0 1 ?
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