Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2edae2c

Browse files
authored
Merge pull request#264 from Seb33300/fluent
feat: Update Fluent class from Laravel 12
2 parents056e75b +258e1b7 commit2edae2c

File tree

1 file changed

+83
-5
lines changed

1 file changed

+83
-5
lines changed

‎src/Html/Fluent.php‎

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
namespaceYajra\DataTables\Html;
44

55
useArrayAccess;
6+
useArrayIterator;
67
useIlluminate\Contracts\Support\Arrayable;
78
useIlluminate\Contracts\Support\Jsonable;
9+
useIlluminate\Support\Traits\Conditionable;
10+
useIlluminate\Support\Traits\Macroable;
11+
useIteratorAggregate;
812
useJsonSerializable;
13+
useTraversable;
914

1015
/**
1116
* @template TKey of array-key
@@ -14,8 +19,12 @@
1419
* @implements \Illuminate\Contracts\Support\Arrayable<TKey, TValue>
1520
* @implements \ArrayAccess<TKey, TValue>
1621
*/
17-
class Fluentimplements Arrayable, ArrayAccess, Jsonable, JsonSerializable
22+
class Fluentimplements Arrayable, ArrayAccess,IteratorAggregate,Jsonable, JsonSerializable
1823
{
24+
use Conditionable, Macroable {
25+
__callas macroCall;
26+
}
27+
1928
/**
2029
* All of the attributes set on the fluent instance.
2130
*
@@ -31,9 +40,7 @@ class Fluent implements Arrayable, ArrayAccess, Jsonable, JsonSerializable
3140
*/
3241
publicfunction__construct($attributes = [])
3342
{
34-
foreach ($attributesas$key =>$value) {
35-
$this->attributes[$key] =$value;
36-
}
43+
$this->fill($attributes);
3744
}
3845

3946
/**
@@ -50,6 +57,35 @@ public function get($key, $default = null)
5057
returndata_get($this->attributes,$key,$default);
5158
}
5259

60+
/**
61+
* Set an attribute on the fluent instance using "dot" notation.
62+
*
63+
* @param TKey $key
64+
* @param TValue $value
65+
* @return $this
66+
*/
67+
publicfunctionset($key,$value)
68+
{
69+
data_set($this->attributes,$key,$value);
70+
71+
return$this;
72+
}
73+
74+
/**
75+
* Fill the fluent instance with an array of attributes.
76+
*
77+
* @param iterable<TKey, TValue> $attributes
78+
* @return $this
79+
*/
80+
publicfunctionfill($attributes)
81+
{
82+
foreach ($attributesas$key =>$value) {
83+
$this->attributes[$key] =$value;
84+
}
85+
86+
return$this;
87+
}
88+
5389
/**
5490
* Get an attribute from the fluent instance.
5591
*
@@ -132,6 +168,34 @@ public function toJson($options = 0)
132168
returnjson_encode($this->jsonSerialize(),$options);
133169
}
134170

171+
/**
172+
* Convert the fluent instance to pretty print formatted JSON.
173+
*
174+
* @params int $options
175+
*
176+
* @return string
177+
*/
178+
publicfunctiontoPrettyJson(int$options =0)
179+
{
180+
return$this->toJson(JSON_PRETTY_PRINT |$options);
181+
}
182+
183+
/**
184+
* Determine if the fluent instance is empty.
185+
*/
186+
publicfunctionisEmpty():bool
187+
{
188+
returnempty($this->attributes);
189+
}
190+
191+
/**
192+
* Determine if the fluent instance is not empty.
193+
*/
194+
publicfunctionisNotEmpty():bool
195+
{
196+
return !$this->isEmpty();
197+
}
198+
135199
/**
136200
* Determine if the given offset exists.
137201
*
@@ -174,6 +238,16 @@ public function offsetUnset($offset): void
174238
unset($this->attributes[$offset]);
175239
}
176240

241+
/**
242+
* Get an iterator for the attributes.
243+
*
244+
* @return ArrayIterator<TKey, TValue>
245+
*/
246+
publicfunctiongetIterator():Traversable
247+
{
248+
returnnewArrayIterator($this->attributes);
249+
}
250+
177251
/**
178252
* Handle dynamic calls to the fluent instance to set attributes.
179253
*
@@ -183,7 +257,11 @@ public function offsetUnset($offset): void
183257
*/
184258
publicfunction__call($method,$parameters)
185259
{
186-
$this->attributes[$method] =count($parameters) >0 ?reset($parameters) :true;
260+
if (static::hasMacro($method)) {
261+
return$this->macroCall($method,$parameters);
262+
}
263+
264+
$this->attributes[$method] =count($parameters) >0 ?array_first($parameters) :true;
187265

188266
return$this;
189267
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp