File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace DatabaseFactory \Collections {
44
5+ /**
6+ * Takes a collection of data and provides the ability to access
7+ * objects as arrays
8+ *
9+ * @package DatabaseFactory\Collections
10+ * @author Jason Napolitano
11+ *
12+ * @version 1.0.0
13+ * @since 1.0.0
14+ * @license MIT <https://mit-license.org>
15+ */
516 class ToArray implements \ArrayAccess
617 {
18+ /**
19+ * Constructor
20+ */
721 public function __construct (private array $ collection )
822 {
923 // ...
1024 }
1125
26+ /**
27+ * Returns the raw collection of data
28+ */
1229 public function collection (): array
1330 {
1431 return $ this ->collection ;
1532 }
1633
34+ /**
35+ * Assigns a value to the specified offset
36+ *
37+ * @link https://www.php.net/manual/en/arrayaccess.offsetset.php
38+ */
1739 public function offsetSet ($ offset , $ value ): void
1840 {
1941 !is_null ($ offset )
2042 ? $ this ->collection [$ offset ] = $ value
2143 : $ this ->collection [] = $ value ;
2244 }
2345
46+ /**
47+ * Checks to see if an offset exists
48+ *
49+ * @link https://www.php.net/manual/en/arrayaccess.offsetexists.php
50+ */
2451 public function offsetExists ($ offset ): bool
2552 {
2653 return isset ($ this ->collection [$ offset ]);
2754 }
2855
56+ /**
57+ * Unset an offset
58+ *
59+ * @link https://www.php.net/manual/en/arrayaccess.offsetunset.php
60+ */
2961 public function offsetUnset ($ offset ): void
3062 {
3163 unset($ this ->collection [$ offset ]);
3264 }
3365
66+ /**
67+ * Retrieves an offset
68+ *
69+ * @link https://www.php.net/manual/en/arrayaccess.offsetget.php
70+ */
3471 public function offsetGet ($ offset ): ?int
3572 {
3673 return $ this ->collection [$ offset ] ?? null ;
You can’t perform that action at this time.
0 commit comments