PHP code example of brewerwall / unitz

1. Go to this page and download the library: Download brewerwall/unitz 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/ */

    

brewerwall / unitz example snippets


// Create a new Gravity Object
$gravity = new Gravity(plato: 12);

// Gets the Plato of our Gravity
$plato = $gravity->getPlato();

// Gets the Specific Gravity of our Gravity
$specificGravity = $gravity->getSpecificGravity();

// Gets the Brix of our Gravity
$brix = $gravity->getBrix();

// Gets our Preferred Unit of measure based on our preferences
$plato = $gravity->getValue();

// Instantiate a new UnitzService in a Service Provider Pattern
$unitService = new UnitzService(preferences: ['Temperature' => 'Celsius']);

// Dependency injection of UnitzService within the application
$temperature = $unitService->makeTemperature(fahrenheit: 72);

// Output of getValue() based on the user's preferences
$temperature->getValue(); // 22.222222222222

// Output of getValue() based on the user's preferences with rounding
$temperature->getValue(1); // 22.2

// Create a new Gravity Object
$gravity = new Gravity(userValue: 12, preferences: ['Gravity' => 'Brix']);

// Gets the Brix of our Gravity
$brix = $gravity->getBrix();  // 12

// Gets our Preferred Unit of measure based on our preferences
$plato = $gravity->getValue(); // 12

// Instantiate a new UnitzService in a Service Provider Pattern
$unitService = new UnitzService(preferences: ['Temperature' => 'Fahrenheit']);

// Dependency injection of UnitzService within the application and a user submitted form value
$temperature = $unitService->makeTemperature(userValue: 72);

// Output of getValue() based on the user's preferences
$temperature->getValue(); // 72

// Output of getFahrenheit() will return the same as getValue() since it's the user's preference
$temperature->getFahrenheit(); // 72

// Updating the user's temperature value will have the same effect.
$temperature->setValue(76);

// Values update as needed
$temperature->getValue(); // 76
$temperature->getFahrenheit(); // 76

[
    'Gravity' => 'Plato',
    'Temperature' => 'Fahrenheit',
    'Volume' => 'Gallon',
    'Pressure' => 'Psi',
    'Weight' => 'Pound',
    'Color' => 'Srm',
    'Time' => 'Minute',
    'Distillate' => 'Proof',
    'Length' => 'Foot',
];

// Create a new Weight Object
$weight = new Weight(kilogram: 7.5, preferences: ['Weight' => 'Kilogram']);

// Returns Kilogram since that is the overridden preference
$kilogram = $weight->getValue();

$weight = new Weight(kilogram: 7.5629145);

$kilogram = $weight->getKilogram(3);  // $kilogram = 7.563

$flow = new Flow(new Volume(gallon: 5), new Time(hour: 1));

$flow->getGallonPerHour(); // 5

$flow->getGallonPerMinute(); // 0.083333333333333

$boil = new Boil(new Volume(gallon: 5), new Time(hour: 1));

$boil->getGallonPerHour(); // 5

$boil->getGallonPerMinute(); // 0.083333333333333

$speed = new Speed(new Length(foot: 5), new Time(minute: 1));

$speed->getFeetPerMinute(); // 5

$boil->getFeetPerHour(); // 300
  
Area::rectangle(Length $length, Length $width): Length

Area::square(Length $side): Length

Area::circle(Length $radius): Length

Area::ellipse(Length $majorAxisRadius, Length $minorAxisRadius): Length

Area::triangle(Length $base, Length $height): Length

Area::equilateralTriangle(Length $side): Length

Area::trapezoid(Length $base1, Length $base2, Length $height): Length

Area::regularPentagon(Length $side): Length

Area::regularHexagon(Length $side): Length

Area::regularHeptagon(Length $side): Length

Area::regularOctagon(Length $side): Length

Area::regularNonagon(Length $side): Length

Area::regularDecagon(Length $side): Length

Beer::alcoholByVolume(Gravity $originalGravity, Gravity $finalGravity, string $formulaVersion = Beer::ABV_ALTERNATE_FORMULA): float

Beer::alcoholByWeight(Gravity $originalGravity, Gravity $finalGravity): float

Beer::standardReferenceMethod(Weight $weight, Color $color, Volume $volume): Color

Beer::maltColorUnit(Weight $weight, Color $color, Volume $volume): float

Beer::internationalBitternessUnits(float $alphaAcid, Weight $weight, Time $time, Gravity $gravity, Volume $volume)

Beer::alphaAcidUnit(float $alphaAcid, Weight $weight): float

Beer::hopUtilization(Time $time, Gravity $gravity)

Beer::calories(Gravity $originalGravity, Gravity $finalGravity, Volume $volume)

Beer::realExtract(Gravity $originalGravity, Gravity $finalGravity)

Beer::apparentDegreeOfFermentation(Gravity $originalGravity, Gravity $finalGravity)

Beer::gravityCorrection(Gravity $gravity, Temperature $temperature, Temperature $calibrationTemperature)

Spirit::diluteDownToDesiredProof(Proof $currentProof, Proof $desiredProof, Volume $currentVolume): Volume

Spirit::distilledAlcoholVolume(Volume $volume, Distillate $wash, float $stillEfficiencyPercent): Volume

Spirit::distilledRemainingWaterVolume(Volume $volume, Distillate $wash, float $stillEfficiencyPercent): Volume

Water::partsPerMillion(Weight $substance, Volume $volume): float

Water::boilOffVolume(Boil $boilRate, Time $time): Volume

Water::boilOffVolume(Volume postBoilVolume, Boil $boilRate, Time $time): Volume