-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtalhos.php
49 lines (47 loc) · 1.41 KB
/
Atalhos.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class Atalhos {
private $atalhos = [];
public function create ($nome, $href, $classIcon = '', $classColor = '') {
if (empty($classIcon)) {
$classIcon = 'fa fa-circle';
}
if (empty($classColor)) {
$classColor = 'blue';
}
$atalho = [
"icon" => $classIcon,
"label" => $nome,
"href" => $href,
"color" => $classColor
];
$atalhos = $this->readAtalho();
$atalhos[] = $atalho;
$this->saveAtalho($atalhos);
}
public function clear () {
$this->saveProjeto([]);
}
static public function getAtalhos () {
try {
$atalhos = json_decode(file_get_contents('atalhos.json'), true);
if (json_last_error() != JSON_ERROR_NONE) {
throw new \Exception("Erro ao abrir atalhos");
}
} catch (\Exception $e) {
$atalhos = [];
}
return $atalhos;
}
public function readAtalho () {
$this->atalhos = $this->getAtalhos();
return $this->atalhos;
}
public function saveProjeto ($atalhos = null) {
if (is_null($atalhos) && is_array($atalhos)) {
$atalhos = $this->atalhos;
} else {
$this->atalhos = $atalhos;
}
return file_put_contents('atalhos.json', json_encode($atalhos, JSON_PRETTY_PRINT));
}
}