stefandoorn/3dbinpacking-php-api

该软件包已被放弃,不再维护。没有建议的替代软件包。

3dbinpacking.com PHP API

0.5 2016-07-21 10:25 UTC

This package is auto-updated.

Last update: 2022-02-01 12:52:25 UTC


README

3dbinpacking.com PHP API 包装器

Build Status Scrutinizer Code Quality Test Coverage Code Climate StyleCI Latest Stable Version Total Downloads License

此库作为 3dbinpacking.com 上的 API 的 PHP 包装器。

警告:此软件包已被放弃,将不会获得支持。它将继续在 GH 上提供。

目录

  1. 要求
  2. 安装
  3. 示例
  4. 许可

要求

此库使用 PHP 5.5+。

要使用 3dbinpacking.com API 包装器,您必须从 3dbinpacking.com 请求访问密钥。对于每个请求,您都必须提供用户名和 API 密钥。

注意:此服务 不是 免费使用的。

安装

建议您通过 Composer 安装此库。为此,运行 Composer 命令安装 API 包装器的最新稳定版本

composer require stefandoorn/3dbinpacking-php-api

示例

// Build packing request
$request = new \BinPacking3d\Entity\Request();

$bin = new \BinPacking3d\Entity\Bin();
$bin->setWidth(100);
$bin->setHeight(120);
$bin->setDepth(130);
$bin->setMaxWeight(10);
$bin->setOuterWidth(110);
$bin->setOuterHeight(130);
$bin->setOuterDepth(140);
$bin->setWeight(0.1);
$bin->setIdentifier('Test');
$bin->setInternalIdentifier(1);
$request->addBin($bin);

// Item
$item = new \BinPacking3d\Entity\Item();
$item->setWidth(50);
$item->setHeight(60);
$item->setDepth(70);
$item->setWeight(5);
$item->setItemIdentifier('Test');
$item->setProduct(['product_id' => 1]);
$request->addItem($item);

// Set extra info
$request->setApiKey('API KEY');
$request->setUsername('USERNAME');

// Perform request and get results
$boxes = $packIntoMany->run();

// Process result, in here we get all the packed boxes including the items per box
foreach ($boxes->yieldBins() as $packedBox) {
    // Get weight of box
    $weight = $packedBox->getUsedWeight();

    // Get dimensions
    $height = $packedBox->getOuterHeight();
    $width = $packedBox->getOuterWidth();
    $depth = $packedBox->getOuterDepth();

    // Get identifier
    $identifier = $packedBin->getIdentifier();

    // Get items in this box
    foreach ($packedBox->yieldItems() as $item) {
    	// Get additional product data supplied (e.g. IDs, SKUs, etc)
    	$product = $item->getProduct();

    	// Add to database etc...
    }
}

您可以可选地添加一个兼容 PSR-3 的记录器到请求对象

$log = new \Monolog\Logger('binpacking');
$log->pushHandler(new \Monolog\Handler\StreamHandler('binpacking.log', \Monolog\Logger::DEBUG));

您可以可选地添加一个与 doctrine/cache 兼容的缓存驱动程序,例如。

$cacheDriver = new \Doctrine\Common\Cache\RedisCache();
$redis = new Redis;
$redis->connect($redisHost);
$cacheDriver->setRedis($redis);
$packIntoMany->setCache($cacheDriver);

许可

3dbinpacking.com API 包装器根据 MIT 许可证 (MIT) 许可。