| @@ 9-49 (lines=41) @@ | ||
| 6 | ||
| 7 | use FAPI\Fortnox\Model\CreatableFromArray; |
|
| 8 | ||
| 9 | final class CustomerCollection implements CreatableFromArray |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var Customer[] |
|
| 13 | */ |
|
| 14 | private $customers = []; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @var array |
|
| 18 | */ |
|
| 19 | private $meta = []; |
|
| 20 | ||
| 21 | private function __construct() |
|
| 22 | { |
|
| 23 | } |
|
| 24 | ||
| 25 | public static function createFromArray(array $data) |
|
| 26 | { |
|
| 27 | $collection = new self(); |
|
| 28 | $collection->meta = $data['MetaInformation']; |
|
| 29 | ||
| 30 | foreach ($data['Customers'] as $customerData) { |
|
| 31 | $collection->customers[] = Customer::createFromArray($customerData); |
|
| 32 | } |
|
| 33 | ||
| 34 | return $collection; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return Customer[] |
|
| 39 | */ |
|
| 40 | public function getCustomers(): array |
|
| 41 | { |
|
| 42 | return $this->customers; |
|
| 43 | } |
|
| 44 | ||
| 45 | public function getMeta(): array |
|
| 46 | { |
|
| 47 | return $this->meta; |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||
| @@ 9-49 (lines=41) @@ | ||
| 6 | ||
| 7 | use FAPI\Fortnox\Model\CreatableFromArray; |
|
| 8 | ||
| 9 | class InvoiceCollection implements CreatableFromArray |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var Invoice[] |
|
| 13 | */ |
|
| 14 | private $invoices = []; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @var array |
|
| 18 | */ |
|
| 19 | private $meta = []; |
|
| 20 | ||
| 21 | private function __construct() |
|
| 22 | { |
|
| 23 | } |
|
| 24 | ||
| 25 | public static function createFromArray(array $data) |
|
| 26 | { |
|
| 27 | $collection = new self(); |
|
| 28 | $collection->meta = $data['MetaInformation']; |
|
| 29 | ||
| 30 | foreach ($data['Invoices'] as $childData) { |
|
| 31 | $collection->invoices[] = Invoice::createFromArray($childData); |
|
| 32 | } |
|
| 33 | ||
| 34 | return $collection; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return Invoice[] |
|
| 39 | */ |
|
| 40 | public function getInvoices(): array |
|
| 41 | { |
|
| 42 | return $this->invoices; |
|
| 43 | } |
|
| 44 | ||
| 45 | public function getMeta(): array |
|
| 46 | { |
|
| 47 | return $this->meta; |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||