1. Go to this page and download the library: Download gosuperscript/axiom-lookup 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 / axiom-lookup example snippets
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Superscript\Axiom\Dialect;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Lookup\LookupExtension;
use Superscript\Axiom\Lookup\LookupSource;
use Superscript\Axiom\Lookup\Support\Filters\ValueFilter;
use Superscript\Axiom\Sources\StaticSource;
// Create a filesystem instance (local filesystem example)
$adapter = new LocalFilesystemAdapter('/path/to/data');
$filesystem = new Filesystem($adapter);
// Compose the lookup extension onto the dialect — this is where the filesystem lives
$dialect = Dialect::core()->with(new LookupExtension($filesystem));
// Define a lookup source — pure data, no filesystem
$lookup = new LookupSource(
path: 'products.csv',
filters: [new ValueFilter('category', new StaticSource('Electronics'))],
columns: ['price'],
);
// Compile once, then invoke the program like a function
$program = (new Expression($lookup, dialect: $dialect))->compile()->unwrap();
$result = $program(); // Result<Option<mixed>, Throwable>
$lookup = new LookupSource(path: 'products.csv', aggregate: 'sum');
$program = (new Expression($lookup, dialect: $dialect))->compile()->unwrap();
$program();
// Err(RuntimeException: aggregateColumn is 'sum', aggregateColumn: 'price');
// ✓
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Superscript\Axiom\Dialect;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Lookup\LookupExtension;
use Superscript\Axiom\Lookup\LookupSource;
use Superscript\Axiom\Lookup\Support\Filters\ValueFilter;
use Superscript\Axiom\Sources\StaticSource;
$adapter = new LocalFilesystemAdapter('/path/to/data');
$filesystem = new Filesystem($adapter);
$dialect = Dialect::core()->with(new LookupExtension($filesystem));
$lookup = new LookupSource(
path: 'users.csv',
filters: [new ValueFilter('status', new StaticSource('active'))],
columns: ['name', 'email'],
);
$result = (new Expression($lookup, dialect: $dialect))->compile()->unwrap()();
use Aws\S3\S3Client;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
use Superscript\Axiom\Dialect;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Lookup\LookupExtension;
use Superscript\Axiom\Lookup\LookupSource;
use Superscript\Axiom\Lookup\Support\Filters\ValueFilter;
use Superscript\Axiom\Sources\StaticSource;
$client = new S3Client([
'credentials' => ['key' => 'your-key', 'secret' => 'your-secret'],
'region' => 'us-east-1',
'version' => 'latest',
]);
$adapter = new AwsS3V3Adapter($client, 'your-bucket-name');
$filesystem = new Filesystem($adapter);
$dialect = Dialect::core()->with(new LookupExtension($filesystem));
$lookup = new LookupSource(
path: 'data/products.csv',
filters: [new ValueFilter('category', new StaticSource('Books'))],
columns: ['price'],
);
$result = (new Expression($lookup, dialect: $dialect))->compile()->unwrap()();
use Superscript\Axiom\Dialect;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Lookup\LookupExtension;
use Superscript\Axiom\Lookup\LookupSource;
use Superscript\Axiom\Lookup\Support\Filters\ValueFilter;
use Superscript\Axiom\Sources\SymbolSource;
use Superscript\Axiom\Types\StringType;
$dialect = Dialect::core()->with(new LookupExtension($filesystem));
// A lookup parameterised by a `category` symbol supplied at call time
$lookup = new LookupSource(
path: 'products.csv',
filters: [new ValueFilter('category', new SymbolSource('category'))],
columns: ['price'],
);
$program = (new Expression($lookup, dialect: $dialect, declarations: ['category' => new StringType()]))
->compile()
->unwrap();
// Invoke with bindings — equivalent forms
$electronics = $program(['category' => 'Electronics']);
$books = $program->call(['category' => 'Books']);
new LookupExtension($filesystem); // default: full CSV stream
new LookupExtension($filesystem, $reader); // host-provided indexed reader
use Superscript\Axiom\Lookup\Support\Filters\ValueFilter;
use Superscript\Axiom\Sources\StaticSource;
use Superscript\Axiom\Types\NumberType;
$lookup = new LookupSource(
path: 'users.csv',
filters: [new ValueFilter('age', new StaticSource(30), '>=')],
columns: ['name'],
schema: ['age' => new NumberType()],
);
use Superscript\Axiom\Lookup\Support\Filters\RangeFilter;
use Superscript\Axiom\Sources\SymbolSource;
use Superscript\Axiom\Types\NumberType;
$lookup = new LookupSource(
path: 'premium_bands.csv',
filters: [new RangeFilter('minimum', 'maximum', new SymbolSource('turnover'))],
columns: ['premium'],
schema: [
'minimum' => new NumberType(),
'maximum' => new NumberType(),
],
);
use Superscript\Axiom\Sources\Coerce;
use Superscript\Axiom\Types\ListType;
use Superscript\Axiom\Types\StringType;
$cities = new LookupSource(
path: 'allowed-cities.csv',
columns: ['city'],
aggregate: 'all',
);
$users = new LookupSource(
path: 'users.csv',
filters: [new ValueFilter(
'city',
new Coerce(new ListType(new StringType()), $cities),
'in',
)],
columns: ['name'],
aggregate: 'all',
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.