承接 systopia/expression-language-ext 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

systopia/expression-language-ext

最新稳定版本:v0.1.1

Composer 安装命令:

composer require systopia/expression-language-ext

包简介

Extension for the Symfony ExpressionLanguage Component

README 文档

README

This is an extension for Symfony's ExpressionLanguage component. It provides the functions date_create and map as well as different PHP functions. For simplified use all those functions are available in the class SystopiaExpressionLanguage.

date_create Function

The date_create function creates an object of type \DateTimeImmutable by using the default constructor.

Example:

$expressionLanguage = new SystopiaExpressionLanguage();
$dateTime = $expressionLanguage->evaluate('date_create("2000-01-02 03:04:05")');

map Function

The function map allows to apply an expression to the values of an array (actually any iterable). Each pair of key and value are provided as variables named key and value to the expression.

Example:

$array = [
    'x' => (object) ['a' => 1, 'b' => 2],
    'y' => (object) ['a' => 3, 'b' => 4],
];

$expressionLanguage = new SystopiaExpressionLanguage();
$mapped = $expressionLanguage->evaluate(
    'map(array, "key ~ \": \" ~ (value.a + value.b)")',
     ['array' => $array]
);

var_dump($mapped);

Output:

array(2) {
  [0]=>
  string(4) "x: 3"
  [1]=>
  string(4) "y: 7"
}

统计信息

  • 总下载量: 17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-13