PHP code example of gosuperscript / schema-interval

1. Go to this page and download the library: Download gosuperscript/schema-interval library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gosuperscript / schema-interval example snippets


use Superscript\Axiom\Interval\Types\IntervalType;

$type = new IntervalType();

// Coerce from a string or an Interval object
$interval = $type->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]"

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