1. Go to this page and download the library: Download eventjet/ausdruck 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/ */
eventjet / ausdruck example snippets
use Eventjet\Ausdruck\Parser\ExpressionParser;
use Eventjet\Ausdruck\Parser\Types;
use Eventjet\Ausdruck\Type;
$expression = ExpressionParser::parse(
'joe:MyPersonType.name:string()',
new Types(['MyPersonType' => Type::listOf(Type::string())]),
);
$scope = new Scope(
// Passing values to the expression
['joe' => ['joe']],
// Custom function definitions
['name' => static fn (array $person): string => $person[0]],
);
$name = $expression->evaluate($scope);
assert($name === 'Joe');
use Eventjet\Ausdruck\Parser\ExpressionParser;
use Eventjet\Ausdruck\Scope;
$x = ExpressionParser::parse('foo:int')
->evaluate(new Scope(['foo' => 123]));
assert($x === 123);
use Eventjet\Ausdruck\Parser\ExpressionParser;
use Eventjet\Ausdruck\Type;
ExpressionParser::parse('foo:MyType', ['MyType' => Type::alias(Type::listOf(Type::string()))]);
use Eventjet\Ausdruck\Parser\Declarations;
use Eventjet\Ausdruck\Type;
// zip: fn<T, U>(list<T>, list<U>) -> list<{ a: T, b: U }>
$zip = Type::func(
Type::listOf(Type::struct(['a' => Type::var('T'), 'b' => Type::var('U')])),
[Type::listOf(Type::var('T')), Type::listOf(Type::var('U'))],
);
$declarations = new Declarations(functions: ['zip' => $zip]);