Passed
Push — bugfix ( 149862 )
by Simon
12:39
created

NotIdentifiedException::getDomainAccessManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Exceptions;
10
11
use Waca\DataObjects\Domain;
12
use Waca\DataObjects\User;
13
use Waca\Fragments\NavigationMenuAccessControl;
14
use Waca\PdoDatabase;
15
use Waca\Security\DomainAccessManager;
16
use Waca\Security\SecurityManager;
17
18
class NotIdentifiedException extends ReadableException
19
{
20
    use NavigationMenuAccessControl;
21
22
    /** @var SecurityManager */
23
    private $securityManager;
24
    /** @var DomainAccessManager */
25
    private $domainAccessManager;
26
27
    /**
28
     * NotIdentifiedException constructor.
29
     *
30
     * @param SecurityManager     $securityManager
31
     * @param DomainAccessManager $domainAccessManager
32
     */
33
    public function __construct(SecurityManager $securityManager, DomainAccessManager $domainAccessManager)
34
    {
35
        $this->securityManager = $securityManager;
36
        $this->domainAccessManager = $domainAccessManager;
37
    }
38
39
    /**
40
     * Returns a readable HTML error message that's displayable to the user using templates.
41
     * @return string
42
     */
43
    public function getReadableError()
44
    {
45
        if (!headers_sent()) {
46
            header("HTTP/1.1 403 Forbidden");
47
        }
48
49
        $this->setUpSmarty();
50
51
        // uck. We should still be able to access the database in this situation though.
52
        $database = PdoDatabase::getDatabaseConnection('acc');
53
        $currentUser = User::getCurrent($database);
54
        $this->assign('currentUser', $currentUser);
55
        $this->assign('currentDomain', Domain::getCurrent($database));
56
57
        if ($this->securityManager !== null) {
58
            $this->setupNavMenuAccess($currentUser);
59
        }
60
61
        return $this->fetchTemplate("exception/not-identified.tpl");
62
    }
63
64
    protected function getSecurityManager(): SecurityManager
65
    {
66
        return $this->securityManager;
67
    }
68
69
    public function getDomainAccessManager(): DomainAccessManager
70
    {
71
        return $this->domainAccessManager;
72
    }
73
}