Download the PHP package myfarms/php-units-of-measure without Composer

On this page you can find all versions of the php package myfarms/php-units-of-measure. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-units-of-measure

PHP Units of Measure

master: Build Status

Introduction

This is a PHP library for representing and converting physical units of measure. The utility of this library is in encapsulating physical quantities in such a way that you don't have to keep track of which unit they're represented in. For instance:

Having this abstraction allows you to create interfaces that accept physical quantities without requiring them to be in a particular unit. For example, this function assumes the height is a float of a particular unit (presumably feet):

Whereas this version allows for height to be provided in whatever unit is convenient:

Installation

This library is best included in your projects via composer. See the Composer website for more details, and see the Packagist.org site for this library.

Use

Conversion

As in the examples above, the basic usage of this library is in representing physical quantities and converting between typical units of measure. For example:

It's also possible to implicity cast a quantity to a string, which will display its original value:

Arithmetic Operators

There's also support for addition and subtraction. The PhysicalQuantity objects are immutable, and as such these arithmetic methods return new quantity objects representing the results:

Adding new Units of Measure to Existing Quantities

Ocassionally, you will need to add a new unit of measure to a pre-existing quantity.

For example, let's say in a project you need a new measure of length, called "cubits". You have two options: you can permanently add the new unit of measure to a new child class of the \PhpUnitsOfMeasure\PhysicalQuantity\Length class (or add it directly to that class and submit a pull request to get it added upstream, if appropriate), or you can add the unit temporarily at run time, inside your calling code.

Adding a New Unit of Measure at Runtime

To add a new unit of measure to an existing quantity at run time, you'd do this:

Permanently Adding a New Unit of Measure to a Physical Quantity

The above method only applies to the specific Length object and is therefore temporary; it would be necessary to repeat this process every time you created a new measurement and wanted to use cubits.

A new unit of measure can be permanently added to a physical quantity class by essentially the same process, only it would be done inside the constructor of the quantity class. For example:

Now any new object of class Length that gets instantiated will come with the cubits unit already built in.

Adding New Physical Quantities

Physical quantities are categories of measurable values, like mass, length, force, etc.

For physical quantities that are not already present in this library, it will be necessary to write a class to support a new one. All physical quantities extend the \PhpUnitsOfMeasure\PhysicalQuantity class, and typically have only a constructor method which creates the quantity's units of measure. See above for examples on how to add new units to a quantity class.

Note that every physical quantity has a chosen "native unit" which is typically the SI standard. The main point for this unit is that all of the quantity's other units of measure will convert to and from this chosen native unit. It's important to be aware of a quantity's native unit when writing conversions for new units of measure.

Adding new Aliases to Existing Units

It may come up that the right unit of measure exists for the right physical quantity, but there's a missing alias for the unit. For example, if you thought 'footses' was an obviously lacking alias for the Length unit 'ft', you could temporarily add the alias like this:

And of course, if you need to add the alias permanently, you can do so in the constructor of the quantity's class.

API Documentation

API documentation (such as it is) is handled through GitApiDoc.

Testing and Contributing

Pull requests are welcome, especially regarding new units of measure or new physical quantities. However, please note that there are many sources for conversion factors, and not all are careful to respect known precision.

In the United States, the standards body for measurement is NIST, and they've published NIST Special Publication 1038 "The International System of Units (SI) - Conversion factors for General Use". This guide contains the approved conversion factors between various units and the base SI units.

Also note that any new physical quantities should have the appropriate SI unit chosen for their native unit of measure.

Setting Up for Testing

After cloning this repository, install Composer:

Since this is for development, install with the dev dependencies:

Continuous Integration

Continuous integration is handled through Travis-CI.

Unit Tests

All the tests associated with this project can be manually run with:

CodeSniffer

Codesniffer verifies that coding standards are being met. Once the project is built with development dependencies, you can run the checks with:


All versions of php-units-of-measure with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package myfarms/php-units-of-measure contains the following files

Loading the files please wait ....