1 | <?php |
||
2 | |||
3 | namespace HexMakina\kadro\Controllers; |
||
4 | |||
5 | use HexMakina\kadro\Auth\{Operator,Permission,ACL}; |
||
0 ignored issues
–
show
|
|||
6 | use HexMakina\kadro\Auth\AccessRefusedException; |
||
7 | use HexMakina\BlackBox\Auth\OperatorInterface; |
||
8 | |||
9 | // use HexMakina\LeMarchand\LeMarchand; |
||
10 | |||
11 | class Reception extends Kadro |
||
12 | { |
||
13 | public function requiresOperator(): bool |
||
14 | { |
||
15 | return false; |
||
16 | } |
||
17 | |||
18 | public function welcome(OperatorInterface $operator) |
||
19 | { |
||
20 | $router = $this->get('HexMakina\BlackBox\RouterInterface'); |
||
21 | $router->match(); // throws RouterException if no match |
||
22 | |||
23 | if ($router->name() === 'identify') { |
||
24 | $this->identify($operator); |
||
25 | } |
||
26 | |||
27 | // MVC Cascade |
||
28 | $target_controller = $this->get('Controllers\\' . $router->targetController()); |
||
29 | |||
30 | if ($target_controller->requiresOperator()) { |
||
31 | if (is_null($operator_id = $this->get('HexMakina\BlackBox\StateAgentInterface')->operatorId())) { |
||
32 | $this->checkin(); |
||
33 | } |
||
34 | |||
35 | if (is_null($operator = get_class($operator)::exists($operator_id)) || !$operator->isActive()) { |
||
36 | $this->checkout(); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | return $operator; |
||
41 | } |
||
42 | |||
43 | public function checkin() |
||
44 | { |
||
45 | $this->display('checkin', 'standalone'); |
||
46 | $this->get('HexMakina\BlackBox\StateAgentInterface')->resetMessages(); |
||
47 | } |
||
48 | |||
49 | public function checkout() |
||
50 | { |
||
51 | $this->get('HexMakina\BlackBox\StateAgentInterface')->destroy(); |
||
52 | $this->router()->hop('checkin'); |
||
53 | } |
||
54 | |||
55 | public function identify($op) |
||
56 | { |
||
57 | try { |
||
58 | $username = $this->router()->submitted('username'); |
||
59 | $password = $this->router()->submitted('password'); |
||
60 | |||
61 | $operator = get_class($op)::exists(['username' => $username]); |
||
62 | |||
63 | if (is_null($operator) || !$operator->isActive()) { |
||
64 | throw new \Exception('ERR_DISABLED'); |
||
65 | } |
||
66 | |||
67 | if (!$operator->passwordVerify($password)) { |
||
68 | throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
||
69 | } |
||
70 | |||
71 | $this->get('HexMakina\BlackBox\StateAgentInterface')->operatorId($operator->getId()); |
||
72 | $this->logger()->notice('PAGE_CHECKIN_WELCOME', [$operator->name()]); |
||
73 | $this->router()->hop(); |
||
74 | } catch (\Exception $e) { |
||
75 | $this->logger()->warning('KADRO_operator_' . $e->getMessage()); |
||
76 | $this->router()->hop('checkin'); |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 |
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: