1 | <?php |
||
20 | class Packer implements LoggerAwareInterface |
||
21 | { |
||
22 | use LoggerAwareTrait; |
||
23 | |||
24 | /** |
||
25 | * Number of boxes at which balancing weight is deemed not worth it |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $maxBoxesToBalanceWeight = 12; |
||
29 | |||
30 | /** |
||
31 | * List of items to be packed |
||
32 | * @var ItemList |
||
33 | */ |
||
34 | protected $items; |
||
35 | |||
36 | /** |
||
37 | * List of box sizes available to pack items into |
||
38 | * @var BoxList |
||
39 | */ |
||
40 | protected $boxes; |
||
41 | |||
42 | /** |
||
43 | * Constructor |
||
44 | */ |
||
45 | 27 | public function __construct() |
|
52 | |||
53 | /** |
||
54 | * Add item to be packed |
||
55 | * @param Item $item |
||
56 | * @param int $qty |
||
57 | */ |
||
58 | 26 | public function addItem(Item $item, int $qty = 1): void |
|
65 | |||
66 | /** |
||
67 | * Set a list of items all at once |
||
68 | * @param \Traversable|array $items |
||
69 | */ |
||
70 | 2 | public function setItems($items): void |
|
81 | |||
82 | /** |
||
83 | * Add box size |
||
84 | * @param Box $box |
||
85 | */ |
||
86 | 25 | public function addBox(Box $box): void |
|
91 | |||
92 | /** |
||
93 | * Add a pre-prepared set of boxes all at once |
||
94 | * @param BoxList $boxList |
||
95 | */ |
||
96 | 2 | public function setBoxes(BoxList $boxList): void |
|
100 | |||
101 | /** |
||
102 | * Number of boxes at which balancing weight is deemed not worth the extra computation time |
||
103 | * @return int |
||
104 | */ |
||
105 | 1 | public function getMaxBoxesToBalanceWeight(): int |
|
109 | |||
110 | /** |
||
111 | * Number of boxes at which balancing weight is deemed not worth the extra computation time |
||
112 | * @param int $maxBoxesToBalanceWeight |
||
113 | */ |
||
114 | 2 | public function setMaxBoxesToBalanceWeight(int $maxBoxesToBalanceWeight) |
|
118 | |||
119 | /** |
||
120 | * Pack items into boxes |
||
121 | * |
||
122 | * @return PackedBoxList |
||
123 | */ |
||
124 | 26 | public function pack(): PackedBoxList |
|
138 | |||
139 | /** |
||
140 | * Pack items into boxes using the principle of largest volume item first |
||
141 | * |
||
142 | * @throws ItemTooLargeException |
||
143 | * @return PackedBoxList |
||
144 | */ |
||
145 | 26 | public function doVolumePacking(): PackedBoxList |
|
200 | } |
||
201 |