1. Go to this page and download the library: Download packvium/native-bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
packvium / native-bridge example snippets
use Packvium\Native\NativePacker;
$request = [
'units' => ['length' => 'mm'],
'configuration' => [
// Counted work bounds the search, so both backends stop at a reproducible point;
// the time limit is only a safety fuse.
'effort_budget' => ['max_search_nodes' => 20000],
'time_limit_ms' => 60000,
],
'items' => [
['id' => 'mug', 'quantity' => 6, 'weight' => '400 g',
'dimensions' => ['length' => '120', 'width' => '120', 'height' => '100']],
],
'containers' => [
['id' => 'box', 'max_payload' => '20 kg',
'inner_dimensions' => ['length' => '400', 'width' => '300', 'height' => '250']],
],
];
$packer = new NativePacker('/opt/packvium/libpackvium_ffi.so');
$result = $packer->pack($request);
echo $packer->backend(), PHP_EOL; // "rust" or "php"
echo $result['status'], PHP_EOL; // "feasible"
$packer = new NativePacker(); // no library path: pure PHP, deterministic either way
echo $packer->backend(), PHP_EOL; // "php"
use Packvium\Serialization\InvalidRequestException;
try {
$result = $packer->pack($request);
} catch (InvalidRequestException $e) {
$result = ['status' => 'error', 'error' => $e->getMessage()];
}
if ($result['status'] === 'error') {
// show $result['error'] to a person; it names the field and the rule it broke
}