PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.5
Independent Analytics – WordPress Analytics Plugin v2.15.5
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Eloquent / Concerns / GuardsAttributes.php
independent-analytics / vendor / illuminate / database / Eloquent / Concerns Last commit date
GuardsAttributes.php 1 month ago HasAttributes.php 1 month ago HasEvents.php 1 month ago HasGlobalScopes.php 1 month ago HasRelationships.php 1 month ago HasTimestamps.php 1 month ago HasUlids.php 1 month ago HasUuids.php 1 month ago HidesAttributes.php 1 month ago QueriesRelationships.php 1 month ago
GuardsAttributes.php
218 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Eloquent\Concerns;
4
5 /** @internal */
6 trait GuardsAttributes
7 {
8 /**
9 * The attributes that are mass assignable.
10 *
11 * @var array<string>
12 */
13 protected $fillable = [];
14 /**
15 * The attributes that aren't mass assignable.
16 *
17 * @var array<string>|bool
18 */
19 protected $guarded = ['*'];
20 /**
21 * Indicates if all mass assignment is enabled.
22 *
23 * @var bool
24 */
25 protected static $unguarded = \false;
26 /**
27 * The actual columns that exist on the database and can be guarded.
28 *
29 * @var array<string>
30 */
31 protected static $guardableColumns = [];
32 /**
33 * Get the fillable attributes for the model.
34 *
35 * @return array<string>
36 */
37 public function getFillable()
38 {
39 return $this->fillable;
40 }
41 /**
42 * Set the fillable attributes for the model.
43 *
44 * @param array<string> $fillable
45 * @return $this
46 */
47 public function fillable(array $fillable)
48 {
49 $this->fillable = $fillable;
50 return $this;
51 }
52 /**
53 * Merge new fillable attributes with existing fillable attributes on the model.
54 *
55 * @param array<string> $fillable
56 * @return $this
57 */
58 public function mergeFillable(array $fillable)
59 {
60 $this->fillable = \array_merge($this->fillable, $fillable);
61 return $this;
62 }
63 /**
64 * Get the guarded attributes for the model.
65 *
66 * @return array<string>
67 */
68 public function getGuarded()
69 {
70 return $this->guarded === \false ? [] : $this->guarded;
71 }
72 /**
73 * Set the guarded attributes for the model.
74 *
75 * @param array<string> $guarded
76 * @return $this
77 */
78 public function guard(array $guarded)
79 {
80 $this->guarded = $guarded;
81 return $this;
82 }
83 /**
84 * Merge new guarded attributes with existing guarded attributes on the model.
85 *
86 * @param array<string> $guarded
87 * @return $this
88 */
89 public function mergeGuarded(array $guarded)
90 {
91 $this->guarded = \array_merge($this->guarded, $guarded);
92 return $this;
93 }
94 /**
95 * Disable all mass assignable restrictions.
96 *
97 * @param bool $state
98 * @return void
99 */
100 public static function unguard($state = \true)
101 {
102 static::$unguarded = $state;
103 }
104 /**
105 * Enable the mass assignment restrictions.
106 *
107 * @return void
108 */
109 public static function reguard()
110 {
111 static::$unguarded = \false;
112 }
113 /**
114 * Determine if the current state is "unguarded".
115 *
116 * @return bool
117 */
118 public static function isUnguarded()
119 {
120 return static::$unguarded;
121 }
122 /**
123 * Run the given callable while being unguarded.
124 *
125 * @param callable $callback
126 * @return mixed
127 */
128 public static function unguarded(callable $callback)
129 {
130 if (static::$unguarded) {
131 return $callback();
132 }
133 static::unguard();
134 try {
135 return $callback();
136 } finally {
137 static::reguard();
138 }
139 }
140 /**
141 * Determine if the given attribute may be mass assigned.
142 *
143 * @param string $key
144 * @return bool
145 */
146 public function isFillable($key)
147 {
148 if (static::$unguarded) {
149 return \true;
150 }
151 // If the key is in the "fillable" array, we can of course assume that it's
152 // a fillable attribute. Otherwise, we will check the guarded array when
153 // we need to determine if the attribute is black-listed on the model.
154 if (\in_array($key, $this->getFillable())) {
155 return \true;
156 }
157 // If the attribute is explicitly listed in the "guarded" array then we can
158 // return false immediately. This means this attribute is definitely not
159 // fillable and there is no point in going any further in this method.
160 if ($this->isGuarded($key)) {
161 return \false;
162 }
163 return empty($this->getFillable()) && !\str_contains($key, '.') && !\str_starts_with($key, '_');
164 }
165 /**
166 * Determine if the given key is guarded.
167 *
168 * @param string $key
169 * @return bool
170 */
171 public function isGuarded($key)
172 {
173 if (empty($this->getGuarded())) {
174 return \false;
175 }
176 return $this->getGuarded() == ['*'] || !empty(\preg_grep('/^' . \preg_quote($key, '/') . '$/i', $this->getGuarded())) || !$this->isGuardableColumn($key);
177 }
178 /**
179 * Determine if the given column is a valid, guardable column.
180 *
181 * @param string $key
182 * @return bool
183 */
184 protected function isGuardableColumn($key)
185 {
186 if (!isset(static::$guardableColumns[\get_class($this)])) {
187 $columns = $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
188 if (empty($columns)) {
189 return \true;
190 }
191 static::$guardableColumns[\get_class($this)] = $columns;
192 }
193 return \in_array($key, static::$guardableColumns[\get_class($this)]);
194 }
195 /**
196 * Determine if the model is totally guarded.
197 *
198 * @return bool
199 */
200 public function totallyGuarded()
201 {
202 return \count($this->getFillable()) === 0 && $this->getGuarded() == ['*'];
203 }
204 /**
205 * Get the fillable attributes of a given array.
206 *
207 * @param array $attributes
208 * @return array
209 */
210 protected function fillableFromArray(array $attributes)
211 {
212 if (\count($this->getFillable()) > 0 && !static::$unguarded) {
213 return \array_intersect_key($attributes, \array_flip($this->getFillable()));
214 }
215 return $attributes;
216 }
217 }
218