PHPackages                             gosuperscript/axiom-interval - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. gosuperscript/axiom-interval

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

gosuperscript/axiom-interval
============================

A PHP library that extends gosuperscript/axiom with support for Interval types, providing type-safe interval handling and operator overloading for schema validation

v0.6.0(1mo ago)035.1k↓37.9%[3 PRs](https://github.com/gosuperscript/axiom-interval/pulls)MITPHPPHP ^8.4CI passing

Since Nov 10Pushed 1w agoCompare

[ Source](https://github.com/gosuperscript/axiom-interval)[ Packagist](https://packagist.org/packages/gosuperscript/axiom-interval)[ RSS](/packages/gosuperscript-axiom-interval/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (6)Dependencies (21)Versions (14)Used By (0)

Axiom Interval
==============

[](#axiom-interval)

A PHP library that extends [gosuperscript/axiom](https://github.com/gosuperscript/axiom) with support for [Interval](https://github.com/superscript/interval) types: a `Type` that validates and coerces intervals, and an `Extension` that teaches the compiler to compare them.

Features
--------

[](#features)

- **Interval Type**: Validate and coerce interval values at a program's boundary
- **Operator rules**: Compare an interval against a number (`>`, `=`, `coerce('[1,2]')->unwrap()->unwrap();

// Assert an existing Interval object (strict membership)
$type->assert($interval)->isOk(); // true

// Format back to string notation
$type->format($interval); // "[1,2]"
```

#### Interval notation

[](#interval-notation)

- `[1,2]` — Closed interval (includes both endpoints)
- `(1,2)` — Open interval (excludes both endpoints)
- `[1,2)` — Half-open (includes left, excludes right)
- `(1,2]` — Half-open (excludes left, includes right)

### The extension

[](#the-extension)

`IntervalExtension` contributes the interval's operator rules and its literal registration. Compose it onto the core dialect and hand the dialect to an expression; the compiler resolves and type-checks every operator against it, and the compiled `Program` runs what it resolved — no runtime dispatch.

```
use Superscript\Axiom\Dialect;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Interval\IntervalExtension;
use Superscript\Axiom\Interval\Types\IntervalType;
use Superscript\Axiom\Sources\InfixExpression;
use Superscript\Axiom\Sources\StaticSource;
use Superscript\Axiom\Sources\SymbolSource;

$dialect = Dialect::core()->with(new IntervalExtension());

$expression = new Expression(
    new InfixExpression(new SymbolSource('range'), '>', new StaticSource(1)),
    dialect: $dialect,
    declarations: ['range' => new IntervalType()],
);

$program = $expression->compile()->unwrap();

$program(['range' => '[2,3]'])->unwrap()->unwrap(); // true — [2,3] lies above 1
```

#### Supported operations

[](#supported-operations)

- **Ordering against a number** — `interval > number`, `>=`, `
