This repository was archived by the owner on Apr 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.php
More file actions
64 lines (58 loc) · 1.33 KB
/
store.php
File metadata and controls
64 lines (58 loc) · 1.33 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
define ('DIR_DB', dirname(__DIR__).'/db');
define('FL_DATA', DIR_DB.'/data.json');
_init();
function _init()
{
if(!is_dir(DIR_DB)){
mkdir(DIR_DB);
}
if(!file_exists(FL_DATA)){
file_put_contents(FL_DATA, '');
}
}
function save($data)
{
if(!is_array($data)){
return false;
}
$items = [];
$items = json_decode(file_get_contents(FL_DATA),true);
array_push($items, $data);
$str = json_encode(array_values($items));
return file_put_contents(FL_DATA, $str);
}
function find($data)
{
$datas = json_decode(file_get_contents(FL_DATA), true);
foreach ( $datas as $data){
if($data['id'] === $data){
return $data;
}
}
}
function findAll()
{
$datas = json_decode(file_get_contents(FL_DATA), true);
return (is_array($datas) && count($datas) > 0) ? $datas : null;
}
function clear()
{
return file_put_contents(FL_DATA, json_encode([]));
}
function delet($data)
{
if(empty($data)){
return false;
}
$items = [];
if(file_exists(FL_DATA)){
$items = json_decode(file_get_contents(FL_DATA), true);
foreach ($items as $key => $i){
if($i['name'] == $data){
unset($items[$key]);
}
}
}
return file_put_contents(FL_DATA, json_encode(array_values($items)));
}