tourze / symfony-ecol-bundle
ECOL
Installs: 247
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^2.20 || ^3.0
- nesbot/carbon: ^2.72 || ^3
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/expression-language: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/property-access: ^6.4
- symfony/security-bundle: ^6.4
- symfony/security-core: ^6.4
- symfony/twig-bundle: ^6.4
- symfony/yaml: ^6.4 || ^7.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-04-28 15:46:41 UTC
README
This bundle provides an enhanced Expression Language experience for Symfony applications with additional functions, values, and Chinese syntax support.
Features
- Enhanced Symfony Expression Language engine with Chinese syntax support
- Date and math function providers for expressions
- Automatic expression validation via Doctrine event subscribers
- Value providers for common date operations (today, current timestamp, etc.)
- Support for custom expression functions and value providers
- Attribute for expression validation on entity properties
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM
Installation
To install the bundle, require it using Composer:
composer require tourze/symfony-ecol-bundle
Register the bundle in your config/bundles.php
:
return [ // ... Tourze\EcolBundle\EcolBundle::class => ['all' => true], // ... ];
Quick Start
Basic Usage
Use the engine service directly in your code:
use Symfony\Component\ExpressionLanguage\Expression; use Tourze\EcolBundle\Service\Engine; class YourService { public function __construct( private readonly Engine $engine ) { } public function evaluateExpression(): mixed { // Basic expression $result = $this->engine->evaluate('1 + 1'); // Expression with variables $result = $this->engine->evaluate('a + b', ['a' => 5, 'b' => 10]); // Expression with Chinese syntax $result = $this->engine->evaluate('a 大于 b 并且 c 等于 d', [ 'a' => 10, 'b' => 5, 'c' => 'test', 'd' => 'test' ]); return $result; } }
Validate Entity Properties
Use the Expression
attribute to validate expressions in entity properties:
use Tourze\EcolBundle\Attribute\Expression; class YourEntity { #[Expression] private string $conditionExpression = 'a > b && c == 1'; // ... }
Available Function Providers
DateFunctionProvider
: Date manipulation functionsMathFunctionProvider
: Mathematical operationsExceptionFunctionProvider
: Exception handling in expressionsServiceFunctionProvider
: Service access in expressions
Available Value Providers
Today
: Provides today's dateTodayRange
: Provides today's start and end timestampsCurrentTimestamp
: Provides current timestampCurrentYear
: Provides current yearCurrentMonth
: Provides current monthCurrentWeekday0
-CurrentWeekday6
: Provides weekday flags
Chinese Syntax Support
The engine automatically converts Chinese operators to their programming equivalents:
Chinese | Programming |
---|---|
并且, 并, 与, 和 | && |
或者, 或 | || |
不是, 不等于 | != |
等于, 相等于, 是 | == |
全等于 | === |
大于, 多于 | > |
小于, 少于 | < |
大于等于, 大于或等于 | >= |
小于等于, 小于或等于 | <= |
加上 | + |
减去 | - |
乘以 | * |
除以 | / |
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.