-
-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathContainsData.php
More file actions
78 lines (57 loc) · 1.3 KB
/
ContainsData.php
File metadata and controls
78 lines (57 loc) · 1.3 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Statamic\Data;
trait ContainsData
{
use ContainsSupplementalData;
protected $data;
public function get($key, $fallback = null)
{
return $this->data[$key] ?? $fallback;
}
public function has($key)
{
return $this->data->has($key);
}
public function set($key, $value)
{
$this->data[$key] = $value;
return $this;
}
public function increment($key, $amount = 1)
{
$this->data[$key] = ($this->data[$key] ?? 0) + $amount;
return $this;
}
public function decrement($key, $amount = 1)
{
return $this->increment($key, -$amount);
}
public function remove($key)
{
unset($this->data[$key]);
return $this;
}
public function modify($key, $callback)
{
$value = $this->get($key);
$this->set($key, $callback($value));
return $this;
}
public function data($data = null)
{
if (func_num_args() === 0) {
return $this->data;
}
$this->data = collect($data);
return $this;
}
public function merge($data)
{
$this->data = $this->data->merge($data);
return $this;
}
public function __set($key, $value)
{
$this->set($key, $value);
}
}