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
// 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();