PHP code example of zef-dev / zef-expression-language

1. Go to this page and download the library: Download zef-dev/zef-expression-language 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/ */

    

zef-dev / zef-expression-language example snippets



use Zef\Zel\Symfony\ExpressionLanguage;

$expressionLanguage =   new ExpressionLanguage();
$evaluated          =   $expressionLanguage->evaluate( 'true', []);

// will not throw an exception any more
$evaluated          =   $expressionLanguage->evaluate( 'myvar', []);
$evaluated          =   $expressionLanguage->evaluate( 'myvar[\'myfield\']', ['myvar'=>[]]);



use Zef\Zel\Symfony\ExpressionLanguage;
use Zef\Zel\ArrayResolver;

$expressionLanguage =   new ExpressionLanguage();
$resolver           =   new ArrayResolver([]);
$evaluated          =   $expressionLanguage->evaluate( 'true', $resolver->getValues());

// now you can access array fields in dot notation
$resolver           =   new ArrayResolver(['myvar'=>['myfield'=>true]]);
$evaluated          =   $expressionLanguage->evaluate( 'myvar.myfield', $resolver->getValues());

// now you can access getters in a shorter way
$obj    =   new Myclass();
$obj->getName();
$obj->isValid();
$obj->hasErrror();

$resolver           =   new ArrayResolver(['myvar'=>$obj]);
$evaluated          =   $expressionLanguage->evaluate( 'myvar.name', $resolver->getValues());
$evaluated          =   $expressionLanguage->evaluate( 'myvar.valid', $resolver->getValues());
$evaluated          =   $expressionLanguage->evaluate( 'myvar.error', $resolver->getValues());