File tree Expand file tree Collapse file tree 4 files changed +151
-0
lines changed Expand file tree Collapse file tree 4 files changed +151
-0
lines changed Original file line number Diff line number Diff line change
1
+ .DS_Store
2
+ thumbs.db
3
+ * .class
4
+ * .pyc
5
+ * .pyo
6
+ * .swp
7
+ .project
8
+ .settings
9
+ .idea
10
+ composer.lock
11
+ vendor /*
Original file line number Diff line number Diff line change
1
+ PHP Data Storage
2
+ ================
3
+
4
+ Example
5
+ -----
6
+ ``` php
7
+ <?php
8
+
9
+ $storage = new frostealth\Storage\Data(); // or $storage = new frostealth\Storage\Data($array);
10
+ $storage->set('login', 'example@example.com');
11
+ // ...
12
+
13
+ if ($storage->has('login')) {
14
+ $login = $storage->get('login');
15
+ $storage->remove('login');
16
+ }
17
+
18
+ $storage->clear();
19
+
20
+ ```
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " frostealth/php-data-storage" ,
3
+ "description" : " PHP Data Storage" ,
4
+ "version" : " 1.0.0" ,
5
+ "authors" : [
6
+ {
7
+ "name" : " Kudinov Ivan" ,
8
+ "email" : " frostealth@gmail.com"
9
+ }
10
+ ],
11
+ "autoload" : {
12
+ "psr-4" : {
13
+ "frostealth\\ Storage\\ " : " src/"
14
+ }
15
+ },
16
+ "require" : {
17
+ "php" : " >=5.4.0"
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace frostealth \Storage ;
4
+
5
+ /**
6
+ * Class Data
7
+ *
8
+ * @package frostealth\Storage
9
+ */
10
+ class Data
11
+ {
12
+ /** @var array */
13
+ protected $ data ;
14
+
15
+ /**
16
+ * @param array $data
17
+ */
18
+ public function __construct (array $ data = [])
19
+ {
20
+ $ this ->fill ($ data );
21
+ }
22
+
23
+ /**
24
+ * @param string $key
25
+ * @param mixed $value
26
+ */
27
+ public function set ($ key , $ value )
28
+ {
29
+ $ this ->data [$ key ] = $ value ;
30
+ }
31
+
32
+ /**
33
+ * @param string $key
34
+ * @param mixed $default
35
+ *
36
+ * @return mixed
37
+ */
38
+ public function get ($ key , $ default = null )
39
+ {
40
+ return $ this ->has ($ key ) ? $ this ->data [$ key ] : $ default ;
41
+ }
42
+
43
+ /**
44
+ * @param string $key
45
+ *
46
+ * @return bool
47
+ */
48
+ public function has ($ key )
49
+ {
50
+ return array_key_exists ($ key , $ this ->data );
51
+ }
52
+
53
+ /**
54
+ * @return array
55
+ */
56
+ public function keys ()
57
+ {
58
+ return array_keys ($ this ->data );
59
+ }
60
+
61
+ /**
62
+ * @param string $key
63
+ */
64
+ public function remove ($ key )
65
+ {
66
+ unset($ this ->data [$ key ]);
67
+ }
68
+
69
+ /**
70
+ * @param array $data
71
+ * @param bool $recursive
72
+ */
73
+ public function replace (array $ data , $ recursive = false )
74
+ {
75
+ $ function = $ recursive ? 'array_replace_recursive ' : 'array_replace ' ;
76
+ $ result = $ function ($ this ->data , $ data );
77
+ $ this ->fill ($ result );
78
+ }
79
+
80
+ /**
81
+ * @param array $data
82
+ */
83
+ public function fill (array $ data )
84
+ {
85
+ $ this ->data = $ data ;
86
+ }
87
+
88
+ /**
89
+ * @return array
90
+ */
91
+ public function all ()
92
+ {
93
+ return $ this ->data ;
94
+ }
95
+
96
+ public function clear ()
97
+ {
98
+ $ this ->fill ([]);
99
+ }
100
+ }
101
+
You can’t perform that action at this time.
0 commit comments