1. Go to this page and download the library: Download gosuperscript/schema-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 / schema-lookup example snippets
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Lookup\{LookupResolver, LookupSource};
use Superscript\Axiom\Lookup\Support\Filters\ValueFilter;
use Superscript\Axiom\Resolvers\DelegatingResolver;
use Superscript\Axiom\Sources\StaticSource;
// Create a filesystem instance (local filesystem example)
$adapter = new LocalFilesystemAdapter('/path/to/data');
$filesystem = new Filesystem($adapter);
// Set up the resolver with the filesystem
$resolver = new DelegatingResolver([
LookupSource::class => LookupResolver::class,
]);
$resolver->instance(\League\Flysystem\FilesystemOperator::class, $filesystem);
// Define a lookup source
$lookup = new LookupSource(
path: 'products.csv',
filters: [new ValueFilter('category', new StaticSource('Electronics'))],
columns: 'price'
);
// Wrap the source in an Expression and invoke it like a function
$query = new Expression($lookup, $resolver);
$result = $query(); // Result<Option<mixed>>
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Lookup\{LookupResolver, LookupSource};
use Superscript\Axiom\Resolvers\DelegatingResolver;
$adapter = new LocalFilesystemAdapter('/path/to/data');
$filesystem = new Filesystem($adapter);
// Configure resolver with filesystem
$resolver = new DelegatingResolver([
LookupSource::class => LookupResolver::class,
]);
$resolver->instance(\League\Flysystem\FilesystemOperator::class, $filesystem);
$lookup = new LookupSource(
path: 'users.csv',
filters: [new ValueFilter('status', new StaticSource('active'))],
columns: ['name', 'email']
);
$result = (new Expression($lookup, $resolver))();
use League\Flysystem\Filesystem;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use Aws\S3\S3Client;
use Superscript\Axiom\Expression;
use Superscript\Axiom\Lookup\{LookupResolver, LookupSource};
use Superscript\Axiom\Resolvers\DelegatingResolver;
$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);
// Configure resolver with S3 filesystem
$resolver = new DelegatingResolver([
LookupSource::class => LookupResolver::class,
]);
$resolver->instance(\League\Flysystem\FilesystemOperator::class, $filesystem);
$lookup = new LookupSource(
path: 'data/products.csv',
filters: [new ValueFilter('category', new StaticSource('Books'))],
columns: 'price'
);
$result = (new Expression($lookup, $resolver))();
use Superscript\Axiom\Expression;
use Superscript\Axiom\Resolvers\SymbolResolver;
use Superscript\Axiom\Sources\SymbolSource;
// Register SymbolResolver so `SymbolSource` placeholders can be resolved
$resolver = new DelegatingResolver([
LookupSource::class => LookupResolver::class,
SymbolSource::class => SymbolResolver::class,
]);
$resolver->instance(\League\Flysystem\FilesystemOperator::class, $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'
);
$query = new Expression($lookup, $resolver);
// Inspect
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.