{"id":37364237,"url":"https://github.com/subzeta/ruling","last_synced_at":"2026-01-16T04:49:33.644Z","repository":{"id":57061068,"uuid":"50247979","full_name":"subzeta/ruling","owner":"subzeta","description":"Stateless rule engine","archived":false,"fork":false,"pushed_at":"2017-12-07T14:20:47.000Z","size":28,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-08T23:36:49.563Z","etag":null,"topics":["assert","callback","interpreted-rules","rule-engine","rules-processor","stateless-rule-engine"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/subzeta.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":"2016-01-23T16:56:27.000Z","updated_at":"2024-07-01T12:37:40.000Z","dependencies_parsed_at":"2022-08-24T14:53:42.599Z","dependency_job_id":null,"html_url":"https://github.com/subzeta/ruling","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/subzeta/ruling","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subzeta%2Fruling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subzeta%2Fruling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subzeta%2Fruling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subzeta%2Fruling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/subzeta","download_url":"https://codeload.github.com/subzeta/ruling/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subzeta%2Fruling/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["assert","callback","interpreted-rules","rule-engine","rules-processor","stateless-rule-engine"],"created_at":"2026-01-16T04:49:32.978Z","updated_at":"2026-01-16T04:49:33.630Z","avatar_url":"https://github.com/subzeta.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rule engine\nStateless rule engine to assert statements given a context.\n\n# Install\n```bash\n$ composer require \"subzeta/ruling\" : \"^2.0\"\n```\n\n# Usage example\n```php\n\nrequire '/path/to/vendor/autoload.php';\n\nuse subzeta\\Ruling\\Ruling;\n\n$my = new \\stdClass();\n$my-\u003esensitivity = 80;\n$my-\u003ejoyfulness = 10;\n\n(new Ruling())\n    -\u003egiven([\n        'sensitivity' =\u003e $my-\u003esensitivity,\n        'joyfulness' =\u003e $my-\u003ejoyfulness\n    ])-\u003ewhen(\n        ':sensitivity is greater than 90 or :joyfulness is less than 20'\n    )-\u003ethen(function() {\n        echo 'Hell yeah, I should listen music right now!';\n    })-\u003eotherwise(function() {\n        echo 'I\\'m happy enough, thanks.';\n    })-\u003eexecute();\n\n// Outputs: Hell yeah, I should listen music right now!\n```\n\n# Calls\nThere are three main entrances:\n#### interpret\nReturns the interpreted rules.\nUsing the example above the output would be: ['80 \u003e 90 || 10 \u003c 20']\n#### assert\nReturns a boolean indicating the output.\nUsing the example above the output would be: true\n#### execute\nFires the success or fail callback if defined.\nUsing the example above the output would be: 'Hell yeah, I should listen it!'\n\n# Error handling\nDifferent types of exceptions are thrown when something goes wrong:\n#### InvalidContextException\nWhen the provided context isn't valid (accepts: ['string-key-1' =\u003e value-1, ..., 'string-key-x' =\u003e value-x]).\n#### InvalidRuleException\nWhen the provided rules aren't valid (accepts: 'string' or ['string-1', ..., 'string-x']) \n#### InvalidCallbackException\nWhen the provided success/fail callback isn't callable (accepts: function(){return 'Hey Ho! Let\\'s go!';})\n\n# Supported Operators\nType | Operator | Representation\n---- | -------- | -----------\nComparison | is greater than | \u003e\nComparison | is greater or equal to | \u003e=\nComparison | is less than | \u003c\nComparison | is less or equal to | \u003c=\nComparison | is equal to (alias: is) | ==\nComparison | is not equal to (aliases: is not, isn't) | !=\nComparison | same as | ===\nComparison | not same as | !==\nLogical | and | \u0026\u0026\nLogical | or | \\|\\|\nContainment | contained in (alias: in) | in \n\n# Notes\n* It's not necessary to provide callbacks for *execute* method, it will return a boolean instead as *assert* does.\n* Rules respect the operator precedence and evaluate the parenthesis from right to left.\n\n# Testing\n```bash\n$ phpunit\n```\n\n# Recursive to do list\n* Increase the number of unit tests to prevent bad contexts or bad formatted rules from being executed.\n\n# To do\n* Improve the interpreted method response. \n\n# Changelist\n* Allow aliases (\"is equal to\" can be written as \"is\" and \"is not equal to\" as \"is not\"/\"isn't\").\n* Context values may permit callable functions too.\n* Added the strict comparison operators (same as, not same as).\n* It can be interesting to implement a kind of *dump* method to show the interpreted rule.\n* Added the \"in\" operator.\n* Context accepts array values.\n\n# License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubzeta%2Fruling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubzeta%2Fruling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubzeta%2Fruling/lists"}