Passed
Push — master ( 96b645...37300b )
by Anthony
04:06
created

App::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
	namespace core;
3
4
	use core\database\Database;
5
6
	class App {
7
		private static $database;
8
		private static $nav;
9
		private static $erreur;
10
		
11
		private static $values = [];
12
    
13
    
14
		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
15
		public function __construct() {
16
            
17
		}
18
		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
19
    
20
    
21
    
22
		//-------------------------- GETTER ----------------------------------------------------------------------------//
23
		public static function getErreur() {
24
			return self::$erreur;
25
		}
26
		
27
		/**
28
		 * @return array
29
		 * get array of all values wich will be used in the page
30
		 */
31
		public static function getValues() {
32
			return self::$values;
33
		}
34
35
		/**
36
		 * @return Database
37
		 * renvoi une instance de la classe Database
38
		 */
39
		public static function getDb() {
40
			if (self::$database == null) {
41
				self::$database = new Database(DB_TYPE, DB_NAME, DB_USER, DB_PASS, DB_HOST);
42
			}
43
			return self::$database;
44
		}
45
46
		/**
47
		 * @param null $no_module
48
		 * @return Navigation
49
		 * renvoi une instancde de la class navigation
50
		 */
51
		public static function getNav($no_module = null) {
52
			if (self::$nav == null) {
53
				self::$nav = new Navigation($no_module);
54
			}
55
56
			return self::$nav;
57
		}
58
59
		/**
60
		 * @param string $url
61
		 * fonction qui permet de supprmer un dossier avec toute son abrorescence en fonction d'une URL
62
		 */
63
		public static function supprimerDossier($url) {
64
			if (is_dir($url)) {
65
				$objects = scandir($url);
66
				foreach ($objects as $object) {
67
					if ($object != "." && $object != "..") {
68
						if (filetype($url."/".$object) == "dir") App::supprimerDossier($url."/".$object); else unlink($url."/".$object);
69
					}
70
				}
71
				reset($objects);
72
				rmdir($url);
73
			}
74
		}
75
76
		/**
77
		 * @param $from
78
		 * @param $to
79
		 * @param $sujet
80
		 * @param $message
81
		 */
82
		public static function envoyerMail($from, $to, $sujet, $message) {
83
			$mail = new \Nette\Mail\Message();
84
			$mail->setFrom($from)
85
				->addTo($to)
86
				->setSubject($sujet)
87
				->setHtmlBody($message);
88
89
			if (SMTP_HOST != "") {
90
				$mailer = new \Nette\Mail\SmtpMailer([
91
					'host' => SMTP_HOST,
92
					'username' => SMTP_USER,
93
					'password' => SMTP_PASS,
94
					'secure' => SMTP_SECURE,
95
					'port' => SMTP_PORT
96
				]);
97
			}
98
			else {
99
				$mailer = new \Nette\Mail\SmtpMailer();
100
			}
101
102
			$mailer->send($mail);
103
		}
104
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
105
    
106
    
107
    
108
		//-------------------------- SETTER ----------------------------------------------------------------------------//
109
		/**
110
		 * @param $values
111
		 * can set values while keep older infos
112
		 */
113
		public static function setValues($values) {
114
			self::$values = array_merge(self::$values, $values);
115
		}
116
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
117
	}