Download the PHP package php-architecture-kit/lazy-operators without Composer

On this page you can find all versions of the php package php-architecture-kit/lazy-operators. 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 lazy-operators

Lazy Operators

Coverage

Lazy, composable expression operators for PHP: arithmetic, comparison, logical, and conditional building blocks that you assemble into a tree and evaluate only when you call it.

What it is

Every value in this library is an Expression. An Expression holds its operands. It does not compute anything until you call it. Arithmetic::of(2)->multiply(3)->add(4)->build() builds a three-node tree and returns immediately. The addition, the multiplication, and the two literals stay untouched until you invoke the result with $expr().

This buys you one thing in particular: you can build a piece of logic once and reuse it from several starting points without re-running it (see the forking example below).

Requirements

Installation

Quick start

Reuse a partial chain from more than one point without mutating it:

Core concepts

The root contract is Foundation\Expression\Expression, from the Expression subdomain of Foundation:

Foundation\Expression\Type narrows this contract for each kind of value an operator can produce: NumberValue (int|float), IntegerValue and FloatValue (each a narrower NumberValue), StringValue, BooleanValue, ArrayValue, and ObjectValue. An operator that needs a number type-hints NumberValue on its operand. This lets one operator's output plug directly into the next operator's constructor.

You rarely construct these node classes directly. Every operator accepts either a raw scalar (2, 'x', true) or an Expression, and wraps a raw scalar into the matching literal node for you. This is why Arithmetic::of(2)->add(3) and Arithmetic::of(2)->add(SomeExpression) both work.

Each facade also accepts an optional ExpressionTreeConfig with a decorator. When set, every node the facade builds gets wrapped in your decorator. This is a plain way to add logging, caching, or tracing around every operation, without changing any operator code.

You supply a factory, called once per node with the node it wraps:

Because you construct the decorator yourself, it can take whatever else it needs — a logger, a cache pool, a channel name — alongside the node.

A factory is the only way to configure decoration. Passing a Decorator instance (new ExpressionTreeConfig($decorator)) was deprecated in 1.5.1 and removed in 1.6.0, along with the ExpressionTreeConfig::$decorator property; $decoratorFactory holds the factory, and null there means no decoration.

Available operators

The core namespaces have no dependency on any PHP extension.

Facade Namespace Operations
Arithmetic Foundation\Expression\Arithmetic add, subtract, multiply, divide, modulo, power
Logical Foundation\Expression\Logical and, or, xor, not
Comparison Foundation\Expression\Comparison equal, notEqual, identical, notIdentical, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual
Comparator Foundation\Expression\Comparator spaceship (PHP's <=>)
Conditional Foundation\Expression\Conditional if(...)->then(...)->else(...), switch(...)->case(...)->default(...)
Custom Foundation\Expression\Custom callback(Closure $fn, ...$args), for logic none of the above cover

Each facade builds with a fluent chain and returns the tree with ->build():

Extensions

Foundation\Expression\Extension holds anything beyond the core language: a full wrapper around a native PHP function group, code that depends on an optional extension, or a ready-made domain recipe built from core operators.

Extension Namespace Covers
Math Extension\Math Rounding, trigonometry, exponential/logarithmic functions, base conversion, random numbers, and value classification — one method per native PHP math function
List Extension\List Reducing an unbounded list of values to a single scalar: sum, product — computed via bcmath when available, native arithmetic otherwise
Array Extension\Array Genuinely array-shaped operations: get (dot-path lookup)
BcMath Extension\BcMath Arbitrary-precision arithmetic (add, sub, mul, div, comp), requires ext-bcmath
Allocation Extension\Allocation Proportional split of an amount across shares, remainder folded into one share

BcMath avoids the classic floating-point trap and computes exact decimal results:

Allocation picks its own strategy at run time: it uses bcmath when it's loaded, and falls back to native floats otherwise. The node it builds is AllocationFunction, with a public useBcMathIfAvailable property (default true) that you can set to false to force the native-float path even when bcmath is available:

Writing your own extension

The library has a consistent pattern for adding a new operator, whether it lives in Foundation\Expression\Extension or your own code. Every concrete node class:

  1. Declares its own KEY (a short string label), UID (a UUIDv4 string), and VERSION constant. KEY and UID must be unique across the whole set of registered nodes.
  2. Implements exactly one typed contract from Foundation\Expression\Type — NumberValue, StringValue, BooleanValue, ArrayValue, ObjectValue, or a package-specific one such as Extension\BcMath\PrecisionNumberValue.
  3. Exposes a static formula(): string method that documents the computation in plain text, for example AdditionOperator::formula() returns 'f(left, right) = left + right'.
  4. If it wraps a native PHP function, it adds use GuardsNativeFunction;. Its constructor calls self::guardAvailable('function_name'). This throws a clear exception when the underlying function is not loaded, instead of a generic PHP error later.

Extension\Allocation and Extension\BcMath follow this pattern end to end and are good references to copy from.

Testing and quality tooling

Tests live under tests/Unit (one file per class under src/Foundation, mirroring its Expression/ Registry subdomains), tests/Functional (cross-cutting scenarios, such as BcMath feeding Allocation), and tests/Support (test doubles for Expression).

Contributing

Run composer test, composer code:analyse, and composer code:fix:dry before opening a pull request. All three run in CI on every push.

License

MIT. See LICENSE.


All versions of lazy-operators 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 php-architecture-kit/lazy-operators contains the following files

Loading the files please wait ...