1 | <?php |
||
19 | class Packer implements LoggerAwareInterface |
||
20 | { |
||
21 | use LoggerAwareTrait; |
||
22 | |||
23 | const MAX_BOXES_TO_BALANCE_WEIGHT = 12; |
||
24 | |||
25 | /** |
||
26 | * List of items to be packed |
||
27 | * @var ItemList |
||
28 | */ |
||
29 | protected $items; |
||
30 | |||
31 | /** |
||
32 | * List of box sizes available to pack items into |
||
33 | * @var BoxList |
||
34 | */ |
||
35 | protected $boxes; |
||
36 | |||
37 | /** |
||
38 | * Constructor |
||
39 | */ |
||
40 | 26 | public function __construct() |
|
47 | |||
48 | /** |
||
49 | * Add item to be packed |
||
50 | * @param Item $item |
||
51 | * @param int $qty |
||
52 | */ |
||
53 | 26 | public function addItem(Item $item, $qty = 1) |
|
60 | |||
61 | /** |
||
62 | * Set a list of items all at once |
||
63 | * @param \Traversable|array $items |
||
64 | */ |
||
65 | 1 | public function setItems($items) |
|
66 | { |
||
67 | 1 | if ($items instanceof ItemList) { |
|
68 | $this->items = clone $items; |
||
69 | } else { |
||
70 | 1 | $this->items = new ItemList(); |
|
71 | 1 | foreach ($items as $item) { |
|
72 | 1 | $this->items->insert($item); |
|
73 | } |
||
74 | } |
||
75 | 1 | } |
|
76 | |||
77 | /** |
||
78 | * Add box size |
||
79 | * @param Box $box |
||
80 | */ |
||
81 | 25 | public function addBox(Box $box) |
|
86 | |||
87 | /** |
||
88 | * Add a pre-prepared set of boxes all at once |
||
89 | * @param BoxList $boxList |
||
90 | */ |
||
91 | 1 | public function setBoxes(BoxList $boxList) |
|
95 | |||
96 | /** |
||
97 | * Pack items into boxes |
||
98 | * |
||
99 | * @return PackedBoxList |
||
100 | */ |
||
101 | 26 | public function pack() |
|
115 | |||
116 | /** |
||
117 | * Pack items into boxes using the principle of largest volume item first |
||
118 | * |
||
119 | * @throws ItemTooLargeException |
||
120 | * @return PackedBoxList |
||
121 | */ |
||
122 | 26 | public function doVolumePacking() |
|
177 | } |
||
178 |