| 1 | <?php |
||
| 7 | * |
||
| 8 | * (c) Dev-Int Création <[email protected]>. |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Domain\Model\Article\VO; |
||
| 15 | |||
| 16 | final class Packaging |
||
| 17 | { |
||
| 18 | private array $parcel; |
||
|
|
|||
| 19 | private ?array $subPackage; |
||
| 20 | private ?array $consumerUnit; |
||
| 21 | |||
| 22 | public function __construct(array $parcel, ?array $subPackage = null, ?array $consumerUnit = null) |
||
| 23 | { |
||
| 24 | $this->parcel = $parcel; |
||
| 25 | $this->subPackage = $subPackage; |
||
| 26 | $this->consumerUnit = $consumerUnit; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function fromArray(array $packages): self |
||
| 30 | { |
||
| 31 | $parcel = Storage::fromArray($packages[0])->toArray(); |
||
| 32 | $subPackage = null; |
||
| 33 | $consumerUnit = null; |
||
| 34 | |||
| 35 | for ($i = 1; $i < 3; ++$i) { |
||
| 36 | if (null !== $packages[$i]) { |
||
| 37 | if (1 === $i) { |
||
| 38 | $subPackage = Storage::fromArray($packages[$i])->toArray(); |
||
| 39 | } |
||
| 40 | if (2 === $i) { |
||
| 41 | $consumerUnit = Storage::fromArray($packages[$i])->toArray(); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | return new self($parcel, $subPackage, $consumerUnit); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function parcel(): array |
||
| 50 | { |
||
| 51 | return $this->parcel; |
||
| 52 | } |
||
| 53 | |||
| 54 | public function subPackage(): ?array |
||
| 55 | { |
||
| 56 | return $this->subPackage; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function consumerUnit(): ?array |
||
| 60 | { |
||
| 61 | return $this->consumerUnit; |
||
| 62 | } |
||
| 63 | } |
||
| 64 |