Test Failed
Push — main ( 397c3b...9ee4d3 )
by Rafael
43:59
created

DolibarrGenericController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* Copyright (C) 2024      Rafael San José      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace DoliCore\Base;
20
21
use Alxarafe\Base\GenericController;
22
23
/**
24
 * Class DolibarrGenericController. The generic controller contains what is necessary for any controller
25
 *
26
 * This class is only needed for compatibility with Dolibarr.
27
 *
28
 * @package DoliCore\Base
29
 */
30
abstract class DolibarrGenericController extends GenericController
31
{
32
    /**
33
     * Contains the controller to execute.
34
     *
35
     * @var string
36
     */
37
    protected string $controller;
38
39
    /**
40
     * GenericController constructor.
41
     */
42
    public function __construct()
43
    {
44
        parent::__construct();
45
46
        $this->controller = filter_input(INPUT_GET, GET_FILENAME_VAR);
47
        $this->action = filter_input(INPUT_GET, 'action');
48
49
        if (empty($this->controller)) {
50
            $this->controller = 'index';
51
        }
52
53
        if (method_exists($this, $this->controller)) {
54
            return $this->{$this->controller}();
55
        }
56
57
        return $this->index();
58
    }
59
60
    /**
61
     * Returns the generic url of the controller;
62
     *
63
     * @param $full
64
     *
65
     * @return string
66
     */
67
    public static function url($full = false)
68
    {
69
        $url = '';
70
        if ($full) {
71
            $url .= BASE_URL . '/index.php';
72
        }
73
74
        $url .=
75
            '?' . GET_ROUTE_VAR . '=' . filter_input(INPUT_GET, GET_ROUTE_VAR) .
76
            '&' . GET_FILENAME_VAR . '=' . filter_input(INPUT_GET, GET_FILENAME_VAR);
77
78
        return $url;
79
    }
80
}
81