{"id":14983758,"url":"https://github.com/nicoswd/rule-engine-bundle","last_synced_at":"2025-04-10T19:40:56.376Z","repository":{"id":57026964,"uuid":"106741736","full_name":"nicoSWD/rule-engine-bundle","owner":"nicoSWD","description":"Symfony Rule Engine Bundle - Parses \u0026 Evaluates Rules Written in a JavaScript-like Syntax","archived":false,"fork":false,"pushed_at":"2018-04-27T10:52:42.000Z","size":45,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T17:15:13.685Z","etag":null,"topics":["business-rules","domain-specific-language","dsl","evaluator","rule","rule-engine","rules-engine","symfony","symfony-bundle","symfony3"],"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/nicoSWD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-12T20:26:34.000Z","updated_at":"2018-04-27T10:52:23.000Z","dependencies_parsed_at":"2022-08-23T16:30:15.476Z","dependency_job_id":null,"html_url":"https://github.com/nicoSWD/rule-engine-bundle","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicoSWD%2Frule-engine-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicoSWD%2Frule-engine-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicoSWD%2Frule-engine-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicoSWD%2Frule-engine-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicoSWD","download_url":"https://codeload.github.com/nicoSWD/rule-engine-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281414,"owners_count":21077423,"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":["business-rules","domain-specific-language","dsl","evaluator","rule","rule-engine","rules-engine","symfony","symfony-bundle","symfony3"],"created_at":"2024-09-24T14:07:52.972Z","updated_at":"2025-04-10T19:40:56.348Z","avatar_url":"https://github.com/nicoSWD.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Symfony Rule Engine Bundle\n==========================\n\n![build](https://travis-ci.org/nicoSWD/rule-engine-bundle.svg?branch=master)\n![coverage](https://scrutinizer-ci.com/g/nicoSWD/rule-engine-bundle/badges/coverage.png?b=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nicoSWD/rule-engine-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nicoSWD/rule-engine-bundle/?branch=master)\n[![Latest Stable Version](https://img.shields.io/packagist/v/nicoswd/symfony-rule-engine-bundle.svg)](https://packagist.org/packages/nicoswd/symfony-rule-engine-bundle)\n\n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/4a70db5d-43a9-4763-8168-60f0ac761f33/big.png)](https://insight.sensiolabs.com/projects/4a70db5d-43a9-4763-8168-60f0ac761f33)\n\nThis package bundles [nicoSWD/php-rule-parser](https://github.com/nicoSWD/php-rule-parser)\n\nRequires PHP \u003e= 7.0\n\nCompatible with Symfony 3 and 4!\n\nInstall\n=======\n\n```shell\n$ composer require nicoswd/symfony-rule-engine-bundle\n```\n\n```php\n\u003c?php\n\n// in AppKernel::registerBundles()\n$bundles = [\n    // ...\n    new nicoSWD\\RuleBundle\\RuleBundle(),\n    // ...\n];\n```\n\nUsage Example\n=====\n```php\n\u003c?php\n\n$rule = '[1, 4, 3].join(glue) === \"1-4-3\"';\n$variables = ['glue' =\u003e '-'];\n\n$result = $this-\u003eget('rule_parser')-\u003eisTrue($rule, $variables);\nvar_dump($result); // bool(true)\n```\n\nCustom Functions\n================\n\nCustom functions are automatically discovered. They just need to be configured\nas service with the tag `nico_swd.rule.function`.\n\nIf you have multiple functions inside the same directory, the easiest way to make\nthem visible to the bundle is this:\n\n_services.yml_\n\n```yaml\nAppBundle\\Functions\\:\n    resource: '../../src/AppBundle/Functions'\n    tags: ['nico_swd.rule.function']\n```\n\nFurthermore, custom functions must implement `nicoSWD\\Rules\\Core\\CallableUserFunction`\nlike in the example below\n\n```php\n\u003c?php\n\nnamespace AppBundle\\Functions;\n\nuse nicoSWD\\Rules\\Core\\CallableUserFunction;\nuse nicoSWD\\Rules\\Tokens\\BaseToken;\nuse nicoSWD\\Rules\\Tokens\\TokenArray;\n\nclass ArrayFilter implements CallableUserFunction\n{\n    /**\n     * @param BaseToken $param\n     * @param BaseToken $param ...\n     * @return BaseToken\n     */\n    public function call($param = null)\n    {\n        // Make sure this functions only works on arrays\n        if (!$param instanceof TokenArray) {\n            throw new \\InvalidArgumentException();\n        }\n\n        return new TokenArray(\n            array_values(\n                array_filter(\n                    $param-\u003etoArray()\n                )\n            )\n        );\n    }\n\n    public function getName(): string\n    {\n        return 'array_filter';\n    }\n}\n```\n\nThe functions optionally retrieve instances of `nicoSWD\\Rules\\Tokens\\BaseToken` as arguments,\nand always must return one as well.\n\n```php\n\u003c?php\n\n$rule = 'array_filter([0, false, 1]) === [1]';\n\n$result = $this-\u003eget('rule_parser')-\u003eisTrue($rule);\nvar_dump($result); // bool(true)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicoswd%2Frule-engine-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicoswd%2Frule-engine-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicoswd%2Frule-engine-bundle/lists"}