PHP code example of kachnitel / entity-expression-language

1. Go to this page and download the library: Download kachnitel/entity-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/ */

    

kachnitel / entity-expression-language example snippets


use Kachnitel\EntityExpressionLanguage\EntityExpressionLanguage;

$lang = new EntityExpressionLanguage();

// Simple property comparison — calls getStatus() automatically
$lang->evaluate('entity.status == "pending"', $order);                  // bool

// Boolean property — calls isActive()
$lang->evaluate('entity.active', $product);

// Numeric comparison
$lang->evaluate('entity.stock > 0', $product);

// Combined conditions
$lang->evaluate('entity.status == "pending" && entity.stock > 0', $product);

// "item" is an alias for "entity"
$lang->evaluate('item.status == "draft"', $article);

// Explicit method call syntax
$lang->evaluate('entity.getStatus() == "pending"', $order);

use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

$lang->evaluate(
    'entity.status != "locked" && is_granted("ROLE_EDITOR")',
    $entity,
    $authorizationChecker,
);

// Pass entity as subject to a voter
$lang->evaluate('is_granted("ADMIN_EDIT", entity)', $entity, $authorizationChecker);