MetaRefresh::setModuleConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\metarefresh\Controller;
6
7
use Exception;
8
use SimpleSAML\Configuration;
9
use SimpleSAML\Error;
10
use SimpleSAML\Logger;
11
use SimpleSAML\Utils;
12
use SimpleSAML\XHTML\Template;
13
14
/**
15
 * Controller class for the metarefresh module.
16
 *
17
 * This class serves the different views available in the module.
18
 *
19
 * @package SimpleSAML\Module\metarefresh
20
 */
21
22
class MetaRefresh
23
{
24
    /** @var \SimpleSAML\Configuration */
25
    protected Configuration $module_config;
26
27
    /**
28
     * @var \SimpleSAML\Utils\Auth
29
     */
30
    protected $authUtils;
31
32
33
    /**
34
     * Controller constructor.
35
     *
36
     * It initializes the global configuration and auth source configuration for the controllers implemented here.
37
     *
38
     * @param \SimpleSAML\Configuration              $config The configuration to use by the controllers.
39
     *
40
     * @throws \Exception
41
     */
42
    public function __construct(
43
        protected Configuration $config,
44
    ) {
45
        $this->module_config = Configuration::getConfig('module_metarefresh.php');
46
        $this->authUtils = new Utils\Auth();
47
    }
48
49
50
    /**
51
     * Inject the \SimpleSAML\Utils\Auth dependency.
52
     *
53
     * @param \SimpleSAML\Utils\Auth $authUtils
54
     */
55
    public function setAuthUtils(Utils\Auth $authUtils): void
56
    {
57
        $this->authUtils = $authUtils;
58
    }
59
60
    /**
61
     * Inject the \SimpleSAML\Configuration dependency.
62
     *
63
     * @param \SimpleSAML\Configuration $module_config
64
     */
65
    public function setModuleConfig(Configuration $module_config): void
66
    {
67
        $this->module_config = $module_config;
68
    }
69
70
    /**
71
     * @return \SimpleSAML\XHTML\Template
72
     */
73
    public function main(): Template
74
    {
75
        $this->authUtils->requireAdmin();
76
77
        Logger::setCaptureLog(true);
78
79
        $mf = new \SimpleSAML\Module\metarefresh\MetaRefresh($this->config, $this->module_config);
80
81
        try {
82
            $mf->runRefresh();
83
        } catch (Exception $e) {
84
            $e = Error\Exception::fromException($e);
85
            $e->logWarning();
86
        }
87
88
        $logentries = Logger::getCapturedLog();
89
90
        $t = new Template($this->config, 'metarefresh:fetch.twig');
91
        $t->data['logentries'] = $logentries;
92
        return $t;
93
    }
94
}
95