Sorry for the noobish question, but I just can't get the example to work.
<?php
require_once 'vendor/autoload.php';
use DVDoug\BoxPacker\ItemList;
use DVDoug\BoxPacker\Packer;
use DVDoug\BoxPacker\TestBox;
use DVDoug\BoxPacker\TestItem;
/*
* To figure out which boxes you need, and which items go into which box
*/
$packer = new Packer();
$packer->addBox(new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000));
$packer->addBox(new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000));
$packer->addItem(new TestItem('Item 1', 250, 250, 2, 200));
$packer->addItem(new TestItem('Item 2', 250, 250, 2, 200));
$packer->addItem(new TestItem('Item 3', 250, 250, 2, 200));
$packedBoxes = $packer->pack();
echo("These items fitted into " . count($packedBoxes) . " box(es)" . PHP_EOL);
foreach ($packedBoxes as $packedBox) {
$boxType = $packedBox->getBox(); // your own box object, in this case TestBox
echo("This box is a {$boxType->getReference()}, it is {$boxType->getOuterWidth()}mm wide, {$boxType->getOuterLength()}mm long and {$boxType->getOuterDepth()}mm high" . PHP_EOL);
echo("The combined weight of this box and the items inside it is {$packedBox->getWeight()}g" . PHP_EOL);
echo("The items in this box are:" . PHP_EOL);
$itemsInTheBox = $packedBox->getItems();
foreach ($itemsInTheBox as $item) { // your own item object, in this case TestItem
echo($item->getDescription() . PHP_EOL);
}
echo(PHP_EOL);
}
/*
* To just see if a selection of items will fit into one specific box
*/
$box = new TestBox('Le box', 300, 300, 10, 10, 296, 296, 8, 1000);
$items = new ItemList();
$items->insert(new TestItem('Item 1', 297, 296, 2, 200));
$items->insert(new TestItem('Item 2', 297, 296, 2, 500));
$items->insert(new TestItem('Item 3', 296, 296, 4, 290));
$packer = new Packer();
$packedBox = $packer->packIntoBox($box, $items);
/* $packedBox->getItems() contains the items that fit */