PHPackages                             tourze/symfony-ecol-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/symfony-ecol-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/symfony-ecol-bundle
==========================

Expression and Condition Operations Language Bundle for Symfony

1.0.1(5mo ago)03.4k5MITPHPCI passing

Since Mar 31Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/symfony-ecol-bundle)[ Packagist](https://packagist.org/packages/tourze/symfony-ecol-bundle)[ RSS](/packages/tourze-symfony-ecol-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (25)Versions (8)Used By (5)

symfony-ecol-bundle
===================

[](#symfony-ecol-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/45ec335fc5dfc74d20a50ad4758f07595a60573a6583dd6117e1d6795e06efda/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f73796d666f6e792d65636f6c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-ecol-bundle)[![PHP Version](https://camo.githubusercontent.com/7f81849e5785b23f0f926d09ba39e1d7e12c20f6bb968645bcef6953ad65e5fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f73796d666f6e792d65636f6c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-ecol-bundle)[![License](https://camo.githubusercontent.com/83a70b1aa5ccdc1af82efad3942fea7d7a0a613249bb80832f99140c05eab07f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f73796d666f6e792d65636f6c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-ecol-bundle)

[![Build Status](https://camo.githubusercontent.com/23a9771d143d0d8a3c737165bea2a1efa8f170d6409e5a2cf7883c6552da48be/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746f75727a652f73796d666f6e792d65636f6c2d62756e646c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/tourze/symfony-ecol-bundle)[![Quality Score](https://camo.githubusercontent.com/7feccd44d8dba76e6dc30688f295105bb889cd3e05052155311ace2c198be5ed/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f73796d666f6e792d65636f6c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/symfony-ecol-bundle)[![Coverage Status](https://camo.githubusercontent.com/4fbc26170e2fe74c4943ed6c763d3f09b548afa23948364ea672a8f105287269/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f75727a652f73796d666f6e792d65636f6c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/symfony-ecol-bundle/code-structure)[![Total Downloads](https://camo.githubusercontent.com/43149fa30ba3820228776af023d7e17b0fc05b32637222f16ac18916dbc93b4e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f73796d666f6e792d65636f6c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-ecol-bundle)

This bundle provides an enhanced Expression Language experience for Symfony applications with additional functions, values, and Chinese syntax support.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Requirements](#requirements)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [Available Function Providers](#available-function-providers)
- [Available Value Providers](#available-value-providers)
- [Chinese Syntax Support](#chinese-syntax-support)
- [Advanced Usage](#advanced-usage)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#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

Installation
------------

[](#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],
    // ...
];
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Symfony 7.3 or higher
- Doctrine ORM

Configuration
-------------

[](#configuration)

The bundle works out of the box without additional configuration. However, you can customize it by creating custom function providers and value providers.

### Custom Function Providers

[](#custom-function-providers)

Create a service that implements function provider interface and tag it:

```
# config/services.yaml
services:
    App\Expression\MyFunctionProvider:
        tags: ['ecol.function.provider']
```

### Custom Value Providers

[](#custom-value-providers)

Create a service that implements value provider interface and tag it:

```
# config/services.yaml
services:
    App\Expression\MyValueProvider:
        tags: ['ecol.value.provider']
```

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#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

[](#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
----------------------------

[](#available-function-providers)

- `DateFunctionProvider`: Date manipulation functions
- `MathFunctionProvider`: Mathematical operations
- `ExceptionFunctionProvider`: Exception handling in expressions
- `ServiceFunctionProvider`: Service access in expressions

Available Value Providers
-------------------------

[](#available-value-providers)

- `Today`: Provides today's date (variable name: `当天日期`)
- `TodayRange`: Provides today's start and end timestamps (variable name: `当天日期范围`)
- `CurrentTimestamp`: Provides current timestamp (variable name: `当前时间戳`)
- `CurrentYear`: Provides current year
- `CurrentMonth`: Provides current month
- `CurrentWeekday0` - `CurrentWeekday6`: Provides weekday dates (variable name: `本周周日日期` etc.)

Chinese Syntax Support
----------------------

[](#chinese-syntax-support)

The engine automatically converts Chinese operators to their programming equivalents:

ChineseProgramming并且, 并, 与, 和&amp;&amp;或者, 或||不是, 不等于!=等于, 相等于, 是==全等于===大于, 多于&gt;小于, 少于&lt;大于等于, 大于或等于&gt;=小于等于, 小于或等于&lt;=加上+减去-乘以\*除以/Advanced Usage
--------------

[](#advanced-usage)

### Working with Complex Expressions

[](#working-with-complex-expressions)

For complex business logic, you can combine multiple operators and functions:

```
$expression = '(age >= 18 并且 country == "CN") 或者 (vip_level > 3 且 balance >= 1000)';
$result = $engine->evaluate($expression, [
    'age' => 25,
    'country' => 'CN',
    'vip_level' => 2,
    'balance' => 500
]);
```

### Custom Expression Functions

[](#custom-expression-functions)

Implement the ExpressionFunctionProviderInterface to add custom functions:

```
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;

class CustomFunctionProvider implements ExpressionFunctionProviderInterface
{
    public function getFunctions(): array
    {
        return [
            new ExpressionFunction('custom_function',
                function ($arg) { return sprintf('custom_function(%s)', $arg); },
                function ($arguments, $arg) { return $arg * 2; }
            ),
        ];
    }
}
```

### Entity Validation with Complex Rules

[](#entity-validation-with-complex-rules)

Use expressions for complex entity validation rules:

```
#[Expression]
private string $businessRule = 'status == "active" && (priority > 5 || urgent == true)';
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance72

Regular maintenance activity

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~50 days

Total

7

Last Release

179d ago

Major Versions

0.1.0 → 1.0.02025-11-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-symfony-ecol-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-symfony-ecol-bundle/health.svg)](https://phpackages.com/packages/tourze-symfony-ecol-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
