Completed
Pull Request — master (#8)
by Vermeulen
05:22 queued 03:14
created

Controller::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Classes géant les pages
5
 * @author Vermeulen Maxime <[email protected]>
6
 * @version 1.0
7
 */
8
9
namespace BFWCtr;
10
11
/**
12
 * Permet de gérer la vue et de savoir vers quel page envoyer
13
 * @package bfw-controller
14
 */
15
class Controller implements \BFWCtrInterface\IController
16
{
17
    /**
18
     * @var $kernel L'instance du Kernel
19
     */
20
    protected $kernel;
21
    protected $options;
22
    protected $routingSys;
23
    protected $routingSysName;
24
25
    /**
26
     * @var $nameCtr Le nom du controler appelé
27
     */
28
    protected $nameCtr = '';
29
30
    /**
31
     * @var $nameMethode Le nom de la méthode à appeler
32
     */
33
    protected $nameMethode = '';
34
35
    /**
36
     * @var $link_file L'arborescence interne dans les fichiers
37
     */
38
    protected $fileArbo = '';
39
40
    /**
41
     * @var $defaultPage La page par défault (celle qui sert de page index au site)
42
     */
43
    protected $defaultPage;
44
45
    /**
46
     * Constructeur
47
     * 
48
     * @param \stdClass $options : Les options du modules
49
     */
50
    public function __construct($options)
51
    {
52
        $this->kernel  = getKernel();
53
        $this->options = $options;
54
55
        $routingSysName = $options->routingModule;
56
        if($routingSysName === '')
57
        {
58
            $routingSysName = '\BFWCtr\Routing';
59
        }
60
61
        $this->routingSysName = $routingSysName;
62
63
        //Si la page par défaut a été indiqué, on la définie.
64
        if($options->defaultMethode !== null)
65
        {
66
            $this->setDefaultPage($options->defaultMethode);
67
        }
68
69
        $this->runRouting();
70
    }
71
72
    protected function runRouting()
73
    {
74
        $this->routingSys = new $this->routingSysName($this);
75
76
        $pageInfos = $this->routingSys->detectUri();
77
        $this->routingSys->detectGet();
78
79
        $this->fileArbo    = $pageInfos->fileArbo;
80
        $this->nameCtr     = $pageInfos->nameCtr;
81
        $this->nameMethode = $pageInfos->nameMethode;
82
    }
83
84
    /**
85
     * Retourne l'arborescence vers le fichier controler (inclus)
86
     * 
87
     * @return string
88
     */
89
    public function getFileArbo()
90
    {
91
        return $this->fileArbo;
92
    }
93
94
    /**
95
     * Modifie la page par défault
96
     * 
97
     * @param string $name Le nom de la page index du site
98
     */
99
    public function setDefaultPage($name)
100
    {
101
        $this->defaultPage = $name;
102
        $this->runRouting();
103
    }
104
105
    /**
106
     * Retourne le nom du controler utilisé
107
     * 
108
     * @return string
109
     */
110
    public function getNameCtr()
111
    {
112
        //return str_replace('/', '\\', $this->nameCtr);
113
        return $this->nameCtr;
114
    }
115
116
    /**
117
     * Retourne la méthode à appeler
118
     * 
119
     * @return string
120
     */
121
    public function getMethode()
122
    {
123
        return $this->nameMethode;
124
    }
125
126
    public function getOptions()
127
    {
128
        return $this->options;
129
    }
130
}
131