Skip to content

Commit ef3bf7d

Browse files
committed
Add JSON serialization for Product class
1 parent 576f4cb commit ef3bf7d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/libraries/Product.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
2-
32
namespace BNETDocs\Libraries;
43

4+
use \BNETDocs\Libraries\Exceptions\ProductNotFoundException;
5+
use \BNETDocs\Libraries\Exceptions\QueryException;
56
use \CarlBennett\MVC\Libraries\Common;
67
use \CarlBennett\MVC\Libraries\Database;
78
use \CarlBennett\MVC\Libraries\DatabaseDriver;
8-
use \BNETDocs\Libraries\Exceptions\ProductNotFoundException;
9-
use \BNETDocs\Libraries\Exceptions\QueryException;
109
use \InvalidArgumentException;
10+
use \JsonSerializable;
1111
use \PDO;
1212
use \PDOException;
1313
use \StdClass;
1414

15-
class Product {
15+
class Product implements JsonSerializable {
1616

1717
protected $bnet_product_id;
1818
protected $bnet_product_raw;
@@ -108,6 +108,18 @@ public function getVersionByte() {
108108
return $this->version_byte;
109109
}
110110

111+
public function jsonSerialize()
112+
{
113+
return [
114+
'bnet_product_id' => $this->getBnetProductId(),
115+
'bnet_product_raw' => $this->getBnetProductRaw(),
116+
'bnls_product_id' => $this->getBnlsProductId(),
117+
'label' => $this->getLabel(),
118+
'sort' => $this->getSort(),
119+
'version_byte' => $this->getVersionByte(),
120+
];
121+
}
122+
111123
protected static function normalize(StdClass &$data) {
112124
$data->bnet_product_id = (int) $data->bnet_product_id;
113125
$data->bnet_product_raw = (string) $data->bnet_product_raw;

0 commit comments

Comments
 (0)