1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HexMakina\kadro\Controllers; |
4
|
|
|
|
5
|
|
|
use HexMakina\kadro\Auth\{Operator,Permission,ACL}; |
|
|
|
|
6
|
|
|
use HexMakina\kadro\Auth\{OperatorInterface,AccessRefusedException}; |
7
|
|
|
use HexMakina\LeMarchand\LeMarchand; |
8
|
|
|
|
9
|
|
|
class Reception extends Kadro |
10
|
|
|
{ |
11
|
|
|
public function requires_operator(): bool |
12
|
|
|
{ |
13
|
|
|
return false; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function welcome(OperatorInterface $operator) |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
if ($this->router()->name() === 'identify') { |
20
|
|
|
$this->identify($operator); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$target_controller = $this->router()->targetController(); |
24
|
|
|
$target_controller = $this->get('Controllers\\'.$target_controller); |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
if ($target_controller->requires_operator()) { |
28
|
|
|
if (is_null($operator = get_class($operator)::exists($this->get('StateAgent')->operatorId()))) { |
29
|
|
|
$this->router()->hop('checkin'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if (!$operator->is_active()) { |
33
|
|
|
$this->checkout(); |
34
|
|
|
throw new AccessRefusedException(); |
35
|
|
|
} |
36
|
|
|
LeMarchand::box()->put('OperatorInterface', $operator); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $operator; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function checkin() |
43
|
|
|
{ |
44
|
|
|
$this->display('checkin', 'standalone'); |
45
|
|
|
$this->logger()->cleanUserReport(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function checkout() |
49
|
|
|
{ |
50
|
|
|
$this->get('StateAgent')->destroy(); |
51
|
|
|
$this->router()->hop('checkin'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function identify($op) |
55
|
|
|
{ |
56
|
|
|
try { |
57
|
|
|
$username = $this->router()->submitted('username'); |
58
|
|
|
$password = $this->router()->submitted('password'); |
59
|
|
|
|
60
|
|
|
$operator = get_class($op)::exists(['username' => $username]); |
61
|
|
|
|
62
|
|
|
if (is_null($operator) || !$operator->is_active()) { |
63
|
|
|
throw new \Exception('ERR_DISABLED'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (!$operator->password_verify($password)) { |
67
|
|
|
throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->get('StateAgent')->operatorId($operator->get_id()); |
71
|
|
|
$this->logger()->nice($this->l('PAGE_CHECKIN_WELCOME', [$operator->name()])); |
72
|
|
|
$this->router()->hop(); |
73
|
|
|
} catch (\Exception $e) { |
74
|
|
|
$this->logger()->warning($this->l('KADRO_operator_' . $e->getMessage())); |
75
|
|
|
$this->router()->hop('checkin'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: