Download the PHP package batrox/distance without Composer
On this page you can find all versions of the php package batrox/distance. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package distance
Distance Helper 
About
This Distance Helper package contains a tested PHP Value Object which makes working with, comparing, converting and formatting distances (meters, kilometers and steps) easy and fluent.
The inspriation for the package came from PHP helpers like Carbon, and an effort to refactor the code behind the virtual workplace walking challenge system Big Team Challenge.
Installation
You can pull in this package through composer
The package (particularly configuration) is designed to work with Laravel 5. Include our custom service provider within config/app.php
:
Usage
To create a new distance you, simply new-up an instance of the Distance class.
The default distance is meters, so ommitting the second (optional) constructor argument will default to meters
API
Converting
You can convert a distance object to a new unit using the to
methods.
The following methods are built-in:
toMeters()
toKilometers()
toMiles()
toFootsteps()
toSteps()
(alias)
If you just want to get the conversion, without changing the object, you can use the asUnit
method.
Rounding
Each unit has it's own decimal precision, and you can get the rounded format by using the round
method.
Comparison
Empty / zero
Value Comparison
Percentage Of
By default, the percentage is capped at 100, but passing false
as the second parameter will always return the real percentage.
Modifying
You can add or subtract distances
Formatting
Using PHP's magic __toString()
method, echo-ing or casting the object itself will round and use the number_format
function to return a string-representation of the value.
You can change the default formatting options to include/omit the comma and the unit suffix. Publish the config file using
You can also use the toStringWithSuffix
method to force the suffix on the end, for example:
Contributing
Please submit improvements and fixes :)
Changelog
Look at the CHANGELOG.md for this package.