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;
class Person { public function __construct(public string $name) {} }
$expression = ExpressionParser::parse(
'joe:MyPersonType.name:string()',
new Types(['MyPersonType' => Person::class]),
);
$scope = new Scope(
// Passing values to the expression
['joe' => new Person('Joe')],
// Custom function definitions
['name' => static fn (Person $person): string => $person->name],
);
$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::object(Foo::class)]);