o2system /
database
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the O2System Framework package. |
||
| 4 | * |
||
| 5 | * For the full copyright and license information, please view the LICENSE |
||
| 6 | * file that was distributed with this source code. |
||
| 7 | * |
||
| 8 | * @author Steeve Andrian Salim |
||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
| 10 | */ |
||
| 11 | |||
| 12 | // ------------------------------------------------------------------------ |
||
| 13 | |||
| 14 | namespace O2System\Database\DataObjects\Result\Row\Columns; |
||
| 15 | |||
| 16 | // ------------------------------------------------------------------------ |
||
| 17 | |||
| 18 | use O2System\Spl\DataStructures\SplArrayObject; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Class DataJSON |
||
| 22 | * |
||
| 23 | * @package O2System\DB\DataStructures\Row\Columns |
||
| 24 | */ |
||
| 25 | class DataJSON extends SplArrayObject |
||
| 26 | {
|
||
| 27 | /** |
||
| 28 | * DataJSON::__construct |
||
| 29 | * |
||
| 30 | * SimpleJSONField constructor. |
||
| 31 | * |
||
| 32 | * @param array $data |
||
| 33 | */ |
||
| 34 | public function __construct($data = []) |
||
| 35 | {
|
||
| 36 | parent::__construct([]); |
||
| 37 | |||
| 38 | if ( ! empty($data)) {
|
||
| 39 | foreach ($data as $key => $value) {
|
||
| 40 | $this->__set($key, $value); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | // ------------------------------------------------------------------------ |
||
| 46 | |||
| 47 | /** |
||
| 48 | * DataJSON::__set |
||
| 49 | * |
||
| 50 | * Magic Method __set |
||
| 51 | * |
||
| 52 | * @param string $index |
||
| 53 | * |
||
| 54 | * @param int $value |
||
| 55 | */ |
||
| 56 | public function __set($index, $value) |
||
| 57 | {
|
||
| 58 | if (is_array($value)) {
|
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 59 | $value = new self($value); |
||
| 60 | } |
||
| 61 | |||
| 62 | $this->offsetSet($index, $value); |
||
| 63 | } |
||
| 64 | |||
| 65 | // ------------------------------------------------------------------------ |
||
| 66 | |||
| 67 | /** |
||
| 68 | * DataJSON__toArray |
||
| 69 | * |
||
| 70 | * Magic Method __toArray |
||
| 71 | * |
||
| 72 | * @return array |
||
| 73 | */ |
||
| 74 | public function __toArray() |
||
| 75 | {
|
||
| 76 | return $this->getArrayCopy(); |
||
| 77 | } |
||
| 78 | } |