File tree Expand file tree Collapse file tree 2 files changed +55
-1
lines changed Expand file tree Collapse file tree 2 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Support ;
4
4
5
+ use ArrayAccess ;
5
6
use Closure ;
6
7
use Illuminate \Support \Facades \Date ;
7
8
use Illuminate \Support \Traits \Conditionable ;
10
11
use JsonSerializable ;
11
12
use Symfony \Component \VarDumper \VarDumper ;
12
13
13
- class Stringable implements JsonSerializable
14
+ class Stringable implements JsonSerializable, ArrayAccess
14
15
{
15
16
use Conditionable, Macroable, Tappable;
16
17
@@ -1216,6 +1217,50 @@ public function jsonSerialize(): string
1216
1217
return $ this ->__toString ();
1217
1218
}
1218
1219
1220
+ /**
1221
+ * Determine if the given offset exists.
1222
+ *
1223
+ * @param mixed $offset
1224
+ * @return bool
1225
+ */
1226
+ public function offsetExists (mixed $ offset ): bool
1227
+ {
1228
+ return isset ($ this ->value [$ offset ]);
1229
+ }
1230
+
1231
+ /**
1232
+ * Get the value at the given offset.
1233
+ *
1234
+ * @param mixed $offset
1235
+ * @return string
1236
+ */
1237
+ public function offsetGet (mixed $ offset ): string
1238
+ {
1239
+ return $ this ->value [$ offset ];
1240
+ }
1241
+
1242
+ /**
1243
+ * Set the value at the given offset.
1244
+ *
1245
+ * @param mixed $offset
1246
+ * @return void
1247
+ */
1248
+ public function offsetSet (mixed $ offset , mixed $ value ): void
1249
+ {
1250
+ $ this ->value [$ offset ] = $ value ;
1251
+ }
1252
+
1253
+ /**
1254
+ * Unset the value at the given offset.
1255
+ *
1256
+ * @param mixed $offset
1257
+ * @return void
1258
+ */
1259
+ public function offsetUnset (mixed $ offset ): void
1260
+ {
1261
+ unset($ this ->value [$ offset ]);
1262
+ }
1263
+
1219
1264
/**
1220
1265
* Proxy dynamic properties onto methods.
1221
1266
*
Original file line number Diff line number Diff line change @@ -1179,4 +1179,13 @@ public function testToDateThrowsException()
1179
1179
1180
1180
$ this ->stringable ('not a date ' )->toDate ();
1181
1181
}
1182
+
1183
+ public function testArrayAccess ()
1184
+ {
1185
+ $ str = $ this ->stringable ('my string ' );
1186
+ $ this ->assertSame ('m ' , $ str [0 ]);
1187
+ $ this ->assertSame ('t ' , $ str [4 ]);
1188
+ $ this ->assertTrue (isset ($ str [2 ]));
1189
+ $ this ->assertFalse (isset ($ str [10 ]));
1190
+ }
1182
1191
}
You can’t perform that action at this time.
0 commit comments