| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* Describes query criteria for searching invoices. |
| 11 |
*/ |
| 12 |
class InvoiceQuery implements \JsonSerializable |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var InvoiceFilter |
| 16 |
*/ |
| 17 |
private $filter; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var InvoiceSort|null |
| 21 |
*/ |
| 22 |
private $sort; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param InvoiceFilter $filter |
| 26 |
*/ |
| 27 |
public function __construct(InvoiceFilter $filter) |
| 28 |
{ |
| 29 |
$this->filter = $filter; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Returns Filter. |
| 34 |
* Describes query filters to apply. |
| 35 |
*/ |
| 36 |
public function getFilter(): InvoiceFilter |
| 37 |
{ |
| 38 |
return $this->filter; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Sets Filter. |
| 43 |
* Describes query filters to apply. |
| 44 |
* |
| 45 |
* @required |
| 46 |
* @maps filter |
| 47 |
*/ |
| 48 |
public function setFilter(InvoiceFilter $filter): void |
| 49 |
{ |
| 50 |
$this->filter = $filter; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Returns Sort. |
| 55 |
* Identifies the sort field and sort order. |
| 56 |
*/ |
| 57 |
public function getSort(): ?InvoiceSort |
| 58 |
{ |
| 59 |
return $this->sort; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Sets Sort. |
| 64 |
* Identifies the sort field and sort order. |
| 65 |
* |
| 66 |
* @maps sort |
| 67 |
*/ |
| 68 |
public function setSort(?InvoiceSort $sort): void |
| 69 |
{ |
| 70 |
$this->sort = $sort; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Encode this object to JSON |
| 75 |
* |
| 76 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 77 |
* are set. (default: false) |
| 78 |
* |
| 79 |
* @return array|stdClass |
| 80 |
*/ |
| 81 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 82 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 83 |
{ |
| 84 |
$json = []; |
| 85 |
$json['filter'] = $this->filter; |
| 86 |
if (isset($this->sort)) { |
| 87 |
$json['sort'] = $this->sort; |
| 88 |
} |
| 89 |
$json = array_filter($json, function ($val) { |
| 90 |
return $val !== null; |
| 91 |
}); |
| 92 |
|
| 93 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 94 |
} |
| 95 |
} |
| 96 |
|