PHP code example of lokeland / shipping-value-objects

1. Go to this page and download the library: Download lokeland/shipping-value-objects 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/ */

    

lokeland / shipping-value-objects example snippets


use Lokeland\SVO\Weight;

$weight = Weight::fromGrams(100);
$weight = Weight::fromKilos(100);
$weight = Weight::ofZero();

$weight->toGrams();
$weight->toKilos();

$weight->add(Weight::fromGrams(50));
$weight->subtract(Weight::fromGrams(50));
$weight->multiply(2);

$weight->isZero();
$weight->equal(Weight::fromGrams(50));
$weight->equalOrGreaterThan(Weight::fromGrams(50));
$weight->equalOrLessThan(Weight::fromGrams(50));
$weight->greaterThan(Weight::fromGrams(50));
$weight->lessThan(Weight::fromGrams(50));
$weight->isBetween(
    Weight::fromGrams(10),
    Weight::fromGrams(70)
);

use Lokeland\SVO\Measurement;

$measurement = Measurement::fromMillimeters(100);
$measurement = Measurement::fromCentimeters(100);
$measurement = Measurement::fromDecimeter(100);
$measurement = Measurement::fromMeters(100);

$measurement->toMillimeters();
$measurement->toCentimeters();
$measurement->toDecimeter();
$measurement->toMeters();

$measurement->isZero();
$measurement->add(Measurement::fromCentimeters(50));
$measurement->subtract(Measurement::fromCentimeters(50));
$measurement->equal(Measurement::fromCentimeters(50));
$measurement->equalOrGreaterThan(Measurement::fromCentimeters(50));
$measurement->equalOrLessThan(Measurement::fromCentimeters(50));
$measurement->greaterThan(Measurement::fromCentimeters(50));
$measurement->lessThan(Measurement::fromCentimeters(50));
$measurement->multiply(2);
$measurement->isBetween(
    Measurement::fromCentimeters(10),
    Measurement::fromCentimeters(70)
);

use Lokeland\SVO\Dimensions;
use Lokeland\SVO\Measurement;

$dimensions = Dimensions::make(
    height: Measurement::fromMillimeters(100),
    width: Measurement::fromMillimeters(100),
    length: Measurement::fromMillimeters(100),
);
$dimensions = Dimensions::ofZero();

$dimensions->height;
$dimensions->width;
$dimensions->length;

$dimensions->isZero();

$dimensions->longest();
$dimensions->shortest();

$dimensions->toVolume();
$dimensions->toArray();

use Lokeland\SVO\ShippingAttributes;
use Lokeland\SVO\Weight;
use Lokeland\SVO\Dimensions;
use Lokeland\SVO\Measurement;

$shippingAttributes = ShippingAttributes::make(
    weight: Weight::fromKilos(),
    dimensions: Dimensions::make(
        height: Measurement::fromMillimeters(100),
        width: Measurement::fromMillimeters(100),
        length: Measurement::fromMillimeters(100),
    )
);

$shippingAttributes->weight;
$shippingAttributes->dimensions;

$shippingAttributes->toArray();

use Lokeland\SVO\Volume;

$volume = Volume::fromCubicMillimeters(10);
$volume = Volume::fromCubicCentimeters(10);
$volume = Volume::fromCubicDecimeters(10);
$volume = Volume::fromCubicMeters(10);

$volume->toCubicMillimeters();
$volume->toCubicCentimeters();
$volume->toCubicDecimeter();
$volume->toCubicMeters();

$volume->isZero();
$volume->add(Volume::fromCubicCentimeters(50));
$volume->subtract(Volume::fromCubicCentimeters(50));
$volume->equal(Volume::fromCubicCentimeters(50));
$volume->equalOrGreaterThan(Volume::fromCubicCentimeters(50));
$volume->equalOrLessThan(Volume::fromCubicCentimeters(50));
$volume->greaterThan(Volume::fromCubicCentimeters(50));
$volume->lessThan(Volume::fromCubicDecimeters(50));
$volume->multiply(2);
$volume->isBetween(
    Volume::fromCubicCentimeters(10),
    Volume::fromCubicCentimeters(70)
);

use Lokeland\SVO\Measurement;
use Lokeland\SVO\MeasurementCollection;

$collection = MeasurementCollection::make([
    Measurement::fromDecimeter(10),
    Measurement::fromDecimeter(20),
    Measurement::fromDecimeter(30),
]);

$collection->findLongest();
$collection->findShortest();
$collection->orderByLongToShort();
$collection->orderByShortToLong();
$collection->sumMeasurements();

use Lokeland\SVO\Weight;
use Lokeland\SVO\WeightCollection;

$collection = WeightCollection::make([
    Weight::fromKilos(1),
    Weight::fromKilos(2),
    Weight::fromKilos(3),
]);

$collection->findHeaviest();
$collection->findLightest();
$collection->orderByHeavyToLight();
$collection->orderByLightToHeavy();
$collection->sumWeight();

use Lokeland\SVO\Measurement;

$measurement = Measurement::fromMeters(1);
$measurement->add(
    measurement: Measurement::fromMeters(5),
    max: Measurement::fromMeters(2),
);
$measurement->toMeters(); // 2

$measurement = Measurement::fromMeters(5);
$measurement->subtract(
    measurement: Measurement::fromMeters(4),
    min: Measurement::fromMeters(3)
);
$measurement->toMeters(); // 3