{"id":19265379,"url":"https://github.com/matrunchyk/expression-parser","last_synced_at":"2025-07-11T18:37:48.692Z","repository":{"id":56967665,"uuid":"128808122","full_name":"matrunchyk/expression-parser","owner":"matrunchyk","description":"This package allows evaluating (parse with mapping) large amounts of data in a flexible manner, providing various processing functions","archived":false,"fork":false,"pushed_at":"2019-10-05T08:01:45.000Z","size":61,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-10T15:03:19.936Z","etag":null,"topics":["compiler","expression","expression-evaluator","expression-parser","laravel","library","parser"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matrunchyk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-09T17:17:44.000Z","updated_at":"2024-05-10T15:03:19.936Z","dependencies_parsed_at":"2022-08-21T06:10:28.243Z","dependency_job_id":null,"html_url":"https://github.com/matrunchyk/expression-parser","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrunchyk%2Fexpression-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrunchyk%2Fexpression-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrunchyk%2Fexpression-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matrunchyk%2Fexpression-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matrunchyk","download_url":"https://codeload.github.com/matrunchyk/expression-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223876302,"owners_count":17218382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","expression","expression-evaluator","expression-parser","laravel","library","parser"],"created_at":"2024-11-09T19:45:50.627Z","updated_at":"2024-11-09T19:45:51.239Z","avatar_url":"https://github.com/matrunchyk.png","language":"PHP","readme":"# ⛓ Expression Parser v0.2.3\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://travis-ci.org/matrunchyk/expression-parser\"\u003e\u003cimg src=\"https://api.travis-ci.org/matrunchyk/expression-parser.svg?branch=master\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/github/package-json/v/badges/shields.svg\" alt=\"Last version\"\u003e\n\u003cimg src=\"https://poser.pugx.org/pugx/badge-poser/license?format=flat\" alt=\"License\"\u003e\n\u003c/p\u003e\n\nThis package allows to evaluate (parse with mapping) large amounts of data in flexible manner, providing various processing functions:\n\n## 🔩 Install\n\n`composer install di/expression-parser`\n\n## ⚒ Usage\n\n\n```\n// Signature\n$expression = new Expression(string $expression[, array $mappings = []]);\n```\n\n## 👀 Example\n\n```\nuse DI\\ExpressionParser\\Expression;\n\n$expression = 'or_x(equal([attr1], 1), in_array(explode([keywords]), \"hello\"))';\n\n$mappings = [\n    'attr1' =\u003e 1,\n    'keywords' =\u003e 'hello,world',\n];\n\n$ex = new Expression($expression, $mappings);\n\necho $ex-\u003evalue(); // true\n```\n\n\n\n\n## Standard function handlers\n\n#### 🔗 Parameter substitution\n\n📥 Input:\n\n```\nnew Expression(\n    '[attr1]',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `1`\n\n\n\n#### 🔗 Parameter substitution with `has()` function\n\n📥 Input:\n\n```\nnew Expression(\n    'has([attr1])',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n\n#### 🔗 Substitution with `in_array()` function and scalar value\n\n📥 Input:\n\n```\nnew Expression(\n    'in_array([keywords], \"hello\")',\n    [\n        'keywords' =\u003e [\n            'hello',\n            'world',\n        ],\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n#### 🔗 Nested `in_array()` and `explode()` function and scalar value\n\n📥 Input:\n\n```\nnew Expression(\n    'in_array(explode([keywords]), \"hello\")',\n    [\n        'keywords' =\u003e 'hello,world',\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n\n#### 🔗 Substitution with `matches_in_array()` function\n\n📥 Input:\n\n```\nnew Expression(\n    'matches_in_array([keywords], \"pool\")',\n    [\n        'keywords' =\u003e [\n            'swimming pool',\n        ],\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n\n#### 🔗 Nested `explode()` `is_empty()` and functions\n\n📥 Input:\n\n```\nnew Expression(\n    'is_empty(explode([keywords]))',\n    [\n        'keywords' =\u003e '',\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n\n#### 🔗 `implode()` with inline parameter substitution\n\n📥 Input:\n\n```\nnew Expression(\n    'implode(([attr1],[attr2]))',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `hello world`\n\n\n\n#### 🔗 `implode()` with inline parameter substitution and a separator flag\n\n📥 Input:\n\n```\nnew Expression(\n    'implode(([attr1],[attr2]), \",\")',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `hello,world`\n\n\n\n#### 🔗 `explode()` with array substitution\n\n📥 Input:\n\n```\nnew Expression(\n    'explode([Rooms])',\n    [\n        'Rooms' =\u003e 'Pantry,Study',\n    ]\n)\n```\n\n📤 Output: `['Pantry', 'Study']`\n\n\n\n## Standard handlers with one or multiple flags\n\n\n#### 🔗 `explode()` with array substitution and a separator flag\n\n📥 Input:\n\n```\nnew Expression(\n    'explode([Rooms], \";\")',\n    [\n        'Rooms' =\u003e 'Pantry;Study',\n    ]\n)\n```\n\n📤 Output: `['Pantry', 'Study']`\n\n\n\n#### 🔗 `get()` function with `count` and `nullable` flags\n\n📥 Input:\n\n```\nnew Expression(\n    'get([attr1], {\"count\":true, \"nullable\":false})',\n    [\n        'attr1' =\u003e [\n            'a',\n            'b',\n            'c',\n        ],\n    ]\n)\n```\n\n📤 Output: `3`\n\n\n\n#### 🔗 Nested mapping with `map` flag in `get()` function\n\n📥 Input:\n\n```\nnew Expression(\n    'get([attr1], {\"map\":{\"a\":1, \"b\": 2, \"c\": 3}})',\n    [\n        'attr1' =\u003e 'b',\n    ]\n)\n```\n\n📤 Output: `2`\n\n\n#### 🔗 Case sensitive matching in array with `sensitive` flag\n\n📥 Input:\n\n```\nnew Expression(\n    'matches_in_array([keywords], \"pool\", {\"sensitive\":true})',\n    [\n        'keywords' =\u003e [\n            'Swimming Pool',\n        ],\n    ]\n)\n```\n\n📤 Output: `false`\n\n\n\n## Logical handlers\n\n\n#### 🔗 `equal()` function\n\n📥 Input:\n\n```\nnew Expression(\n    'equal([attr1], 1)',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n\n#### 🔗 `great_than()` function\n\n📥 Input:\n\n```\nnew Expression(\n    'great_than([attr1], 0)',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n\n#### 🔗 Nested `not()` and `equal()` functions\n\n📥 Input:\n\n```\nnew Expression(\n    'not(equal([attr1], 2))',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n\n\n#### 🔗 Nested `not()` and `equal()` functions\n\n📥 Input:\n\n```\nnew Expression(\n    'not(equal([attr1], 2))',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 2,\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n## Complex functions with unlimited nesting level\n\n\n#### 🔗 Multiple function parameter substitution with nesting with `and_x()`\n\n📥 Input:\n\n```\nnew Expression(\n    'and_x(equal([attr1], 1), in_array(explode([attr2]), \"hello\"))',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 'hello,world',\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n#### 🔗 Multiple function parameter substitution with nesting with `or_x()`\n\n📥 Input:\n\n```\nnew Expression(\n    'or_x(equal([attr1], 1), in_array(explode([attr2]), \"hello\"))',\n    [\n        'attr1' =\u003e 1,\n        'attr2' =\u003e 'hello,world',\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n#### 🔗 Multiple function parameter substitution with nesting with `or_x()` and `not()`\n\n📥 Input:\n\n```\nnew Expression(\n    'not(or_x(equal([attr1], 1), in_array(explode([attr2]), \"word\")))',\n    [\n        'attr1' =\u003e 2,\n        'attr2' =\u003e 'hello,world',\n    ]\n)\n```\n\n📤 Output: `true`\n\n\n#### 😳 Multiple nesting with a Closure\n\n📥 Input:\n\n```\nnew Expression(\n    'first(take(sort(filter([attr1], [filter_func]), [dir]), [offset]))',\n    [\n        'attr1' =\u003e [\n            10,\n            30,\n            20,\n        ],\n        'filter_func' =\u003e function (ExpressionParser $context, $value) {\n            return array_filter($value, function ($item) use ($context) {\n                return $item \u003c $context-\u003egetMappings('filter_attr');\n            });\n        },\n        'filter_attr' =\u003e 30,\n        'dir' =\u003e 'desc',\n        'offset' =\u003e 1,\n    ]\n)\n```\n\n📤 Output: `20`\n\n\n## `Laravel Collection` helpers\n\nThe package already has a built-in support of Laravel Collection helpers.\nFor more informations about the available functions it supports please refer to the original Laravel Collection [documentation page](https://laravel.com/docs/5.6/collections#available-methods).\n\n\n#### 🔗 Example usage of Laravel Collection functions\n\n📥 Input:\n\n```\nnew Expression(\n    'first(collect([attr1], [attr2]))',\n    [\n        'attr1' =\u003e 'value 1',\n        'attr2' =\u003e 'value 2',\n    ]\n)\n```\n\n📤 Output: `'value 1'`\n\n## Extending with custom handlers\n\nIn order to extend or override current functionality, you will need to add your own handler class name to `config/handlers.php` file:\n\n```\nuse DI\\ExpressionParser\\Handlers\\Logical;\nuse DI\\ExpressionParser\\Handlers\\Standard;\nuse DI\\ExpressionParser\\Handlers\\LaravelCollectionAdapter;\n\nreturn [\n    Standard::class,\n    Logical::class,\n    LaravelCollectionAdapter::class,\n\n    // Add custom expression handlers here:\n    // \\Acme\\Handlers\\CustomHandler::class,\n    // 'Acme\\Handlers\\CustomHandler',\n];\n```\n\n## 😍 Contribution\n\nPlease feel free to fork and help developing.\n\n\n## 📃 License\n\n[MIT](http://opensource.org/licenses/MIT)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrunchyk%2Fexpression-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatrunchyk%2Fexpression-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrunchyk%2Fexpression-parser/lists"}