Completed
Push — master ( 8ade87...495f03 )
by Jean-Christophe
01:54
created

WithAuthTrait   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 3
A loadView() 0 6 3
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() && !$this->_getAuthController()->_displayInfoAsString()){
20
			$this->_getAuthController()->info();
21
		}
22
	}
23
	
24
	/**
25
	 * {@inheritDoc}
26
	 * @see \Ubiquity\controllers\Controller::loadView()
27
	 */
28
	public function loadView($viewName, $pData = NULL, $asString = false) {
29
		if(!URequest::isAjax() && $this->_getAuthController()->_displayInfoAsString()){
30
			$this->view->setVar("_userInfo",$this->_getAuthController()->info());
0 ignored issues
show
Bug introduced by
The property view does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
		}
32
		return parent::loadView ($viewName,$pData,$asString);
33
	}
34
35
	/**
36
	 * {@inheritDoc}
37
	 * @see \Ubiquity\controllers\Controller::isValid()
38
	 */
39
	public function isValid() {
40
		return $this->_getAuthController()->_isValidUser();
41
	}
42
43
	/**
44
	 * {@inheritDoc}
45
	 * @see \Ubiquity\controllers\Controller::onInvalidControl()
46
	 */
47
	public function onInvalidControl() {
48
		$auth=$this->_getAuthController();
49
		$auth->initialize();
50
		$auth->noAccess(Startup::$urlParts);
51
		$auth->finalize();
52
		exit();
53
	}
54
	
55
	/**
56
	 * @return \Ubiquity\controllers\auth\AuthController
57
	 */
58
	protected function _getAuthController():AuthController{
59
		if(!isset($this->authController)){
60
			$this->authController=$this->getAuthController();
61
		}
62
		return $this->authController;
63
	}
64
	
65
	protected abstract function getAuthController():AuthController;
66
67
}
68