Download the PHP package oceanmoon/quantities without Composer

On this page you can find all versions of the php package oceanmoon/quantities. 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 quantities

OceanMoon PHP Quantities

This package enables calculations and conversions with physical and non-physical quantities, including support for SI and other systems of units (including data and currencies), metric and binary prefixes, parsing, and formatting.

Examples


Description

This package provides strongly-typed classes for physical quantities (length, mass, time, temperature, etc.) and some non-physical quantities (data, money), with comprehensive unit conversion capabilities. The system automatically finds conversion factors between compatible units, supports metric and binary prefixes, handles offsets for temperature scales, and loads the latest currency exchange rates automatically.

Key capabilities include:


Development and Quality Assurance

Claude Chat and Claude Code were used in the development of this package. The core classes were designed, coded, and commented primarily by the author, with Claude providing assistance with code reviews, debugging, and generating tests and documentation. All code was thoroughly reviewed by the author, and validated using industry-standard tools including PHP_Codesniffer, PHPStan (to level 9), and PHPUnit to ensure full compliance with PSR-12 coding standards and comprehensive unit testing with 100% code coverage. This collaborative approach has produced a well-designed, production-ready package with thorough test coverage and documentation.

Code Coverage


Requirements


Installation


Quick start


Concepts

Background on the domain model and how the library represents physical measurements.

  1. Terminology — Key terms and definitions used throughout the library.
  2. Dimensions and Base Units — Dimension codes, base units, and how the library tracks physical dimensions.
  3. Quantity Types — Typed quantity classes like Length, Mass, and Force, and how they map to dimensions.
  4. Prefixes — Metric, engineering, and binary prefixes for scaling units.
  5. Units — Unit symbol conventions, notation rules, and supported non-ASCII and alternate symbols.
  6. Physical Constants — Built-in physical constants as Quantity objects.

Working with Quantities

Practical guides for using the library in your code.

  1. Creating Quantities — Creating new quantities with constructors and the factory method.
  2. Unit Conversion — Converting between units, expansion, simplification, and auto-prefixing.
  3. Arithmetic Operations — Add, subtract, multiply, and divide quantities.
  4. Calculation Examples — Real-world physics and engineering calculations.
  5. Currency Calculations — Example conversions and calculations involving currencies.
  6. Comparison Functions — Exact and approximate equality, ordering, and tolerances.
  7. String Functions — Parsing strings into quantities and formatting output (ASCII and Unicode).
  8. Part Decomposition — Working with quantities as parts (e.g. 45° 30′ 15″ or 1h 30min 45s).
  9. Customization — Adding custom units, conversions, and quantity type classes.

Reference

Main Public API

Other than the quantity type classes (below), these are the main classes you'll use.

Class Description
Quantity Base class for all measurement types. Provides unit conversion, arithmetic operations, comparison, formatting, and part decomposition.
PhysicalConstant Access to physical constants (speed of light, Planck constant, etc.) as Quantity objects.

Quantity Types

All quantity type classes extend Quantity and define their specific units and conversions. See the Quantity Type reference for the complete list of built-in units for each type.

Class Dimension SI or common base unit Description
Acceleration T-2L m/s² Rate of change of velocity.
AmountOfSubstance N mol SI base quantity for counting entities.
Angle A rad Angular measurements with trig functions.
Area L2 Two-dimensional extent.
Capacitance T4L-2M-1I2 F Ability to store electric charge.
CatalyticActivity T-1N kat Rate of catalysis.
Conductance T3L-2M-1I2 S Electrical conductance.
Data D B Digital storage with metric and binary prefixes.
Density L-3M kg/m³ Mass per unit volume.
Dimensionless empty empty Ratios, percentages, and pure numbers.
ElectricCharge TI C Quantity of electricity.
ElectricCurrent I A SI base quantity for electric current.
Energy T-2L2M J Capacity to do work.
Force T-2LM N Interaction causing acceleration.
Frequency T-1 Hz, Bq Cycles per unit time.
Illuminance L-2JA2 lx Luminous flux per area.
Inductance T-2L2MI-2 H Property opposing current change.
Length L m SI base quantity for distance.
LuminousFlux JA2 lm Perceived light power.
LuminousIntensity J cd SI base quantity for luminous intensity.
MagneticFlux T-2L2MI-1 Wb Total magnetic field through surface.
MagneticFluxDensity T-2MI-1 T Magnetic field strength.
Mass M kg SI base quantity for mass.
Money C XAU Currency conversions and calculations.
Power T-3L2M W Rate of energy transfer.
Pressure T-2L-1M Pa Force per unit area.
RadiationDose T-2L2 Gy, Sv Absorbed and equivalent radiation dose.
Resistance T-3L2MI-2 Ω Opposition to electric current.
SolidAngle A2 sr Three-dimensional angular extent.
Temperature H K SI base quantity with affine conversions.
Time T s SI base quantity for duration.
Velocity T-1L m/s Rate of change of position.
Voltage T-3L2MI-1 V Electric potential difference.
Volume L3 Three-dimensional extent.

Services

These classes are predominantly internal, except for adding custom units via UnitService::add(), or registering new quantity types via QuantityTypeService::add().

Class Description
ConversionService Manages unit conversions and converters.
DimensionService Utilities for working with physical dimension codes (validation, composition, transformation).
PrefixService Manages SI and binary prefixes (lookup, filtering by group).
QuantityTypeService Registry of quantity types keyed by dimension code.
UnitService Registry of units with lookup, filtering, and loading by system.

Internal Types

These types provide the core functionality of the library and will typically not be used directly by end-users.

Classes

Name Description
Unit Represents a single-symbol measurement unit with optional prefix support.
UnitTerm A unit with optional prefix and exponent (e.g., km², ms⁻¹).
CompoundUnit Compound unit expression combining unit terms via multiplication/division.
Prefix SI metric and binary prefixes (kilo, mega, kibi, etc.).
Conversion Represents a unit conversion with factor and error tracking.
Converter Graph-based algorithm for finding conversion paths between units.
FloatWithError Floating-point numbers with tracked error bounds for precision monitoring.
QuantityType Data class representing a quantity type with its dimension, SI unit, and PHP class.

Interfaces

Name Description
UnitInterface Interface implemented by Unit, UnitTerm, and CompoundUnit.

Enums

Name Description
UnitSystem Enum for systems of units (SI, Imperial, US Customary, etc.).

Exceptions

Custom exception types to provide additional context when needed. Both extend DomainException, as they relate to provided values being outside a valid domain.

Class Description
UnknownUnitException Thrown when a unit symbol cannot be resolved.
DimensionMismatchException Thrown when units have incompatible dimensions.

Currency Classes

Classes for currency data management and exchange rate integration.

Class Description
CurrencyService Manages currency unit data and exchange rate conversions.
ExchangeRateServiceInterface Contract for exchange rate providers.
CurrencyLayerService CurrencyLayer API (USD-based, 1,000 req/month free).
ExchangeRateApiService ExchangeRate-API (any base currency, 1,500 req/month free).
FixerService Fixer.io API (EUR-based, 10,000 req/month free).
FrankfurterService Frankfurter API (ECB data, completely free, no API key).
OpenExchangeRatesService Open Exchange Rates API (USD-based, free tier available).

Testing

The library includes comprehensive test coverage:


License

MIT License - see LICENSE for details


Support

For questions or suggestions, please open an issue.


Changelog

See CHANGELOG.md for version history and changes.


All versions of quantities with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-simplexml Version *
oceanmoon/core Version ^2.0
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 oceanmoon/quantities contains the following files

Loading the files please wait ...