Download the PHP package leancaptain/money without Composer

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

LeanCaptain Money

A small, framework-agnostic PHP money value object for representing, comparing, and calculating monetary values safely using integer minor units.

The package is intentionally lightweight and has no runtime dependencies.

Requirements

Installation

Install via Composer:

Quick Start

Monetary amounts should be provided as integers or decimal strings rather than floats.

Minor Units

Money is stored internally using integer minor units.

You can also construct money directly from minor units:

Currencies determine their own minor-unit precision.

Built-in Currencies

The package ships with a set of commonly used currencies:

Applications are not required to use the built-in Currency enum.

Custom Currencies

Implement CurrencyContract to provide an application-specific currency:

Then use it normally:

Currency compatibility is determined by both the currency code and minor-unit precision.

Arithmetic

Addition

Subtraction

Multiplication

Division

Arithmetic operations return new Money instances. Existing instances are never mutated.

Rounding

The default rounding behavior is intentionally strict.

If a value cannot be represented exactly using the currency's minor-unit precision, a RoundingRequired exception is thrown.

Rounding can be requested explicitly:

Supported rounding modes:

The same rules apply to calculations that require rounding:

Comparisons

You can also inspect the state of an amount:

Ordering or arithmetic between incompatible currencies throws a CurrencyMismatch exception.

The package does not perform currency conversion.

Other Operations

Negate an amount:

Get the absolute value:

Money Factory

MoneyFactory can be used when an application has default currency and rounding requirements.

This avoids repeating application defaults while keeping Money itself free from global configuration.

You can also construct values from minor units:

String Representation

Money implements Stringable.

The string representation is intentionally predictable and locale-independent.

Locale-aware presentation formatting should be handled separately by the consuming application.

JSON Serialization

Money implements JsonSerializable.

Produces:

The decimal amount is serialized as a string to avoid introducing floating-point representation into the monetary value.

Exceptions

The package provides dedicated exceptions for common invalid operations:

InvalidMoneyAmount

Thrown when an amount has invalid syntax.

RoundingRequired

Thrown when an otherwise valid value cannot be represented exactly and the rounding mode is REJECT.

CurrencyMismatch

Thrown when arithmetic or ordering is attempted between incompatible currencies.

Division by zero throws PHP's native DivisionByZeroError.

Design Principles

LeanCaptain Money intentionally follows a few simple rules:

The goal is to provide a small, predictable money primitive rather than a complete financial or accounting framework.

Testing

Run the test suite with:

License

LeanCaptain Money is open-sourced software licensed under the MIT license.


All versions of money with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
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 leancaptain/money contains the following files

Loading the files please wait ...