{"id":15287331,"url":"https://github.com/ibrahimgunduz34/maria-bundle","last_synced_at":"2025-04-13T05:08:59.387Z","repository":{"id":56270074,"uuid":"221961750","full_name":"ibrahimgunduz34/maria-bundle","owner":"ibrahimgunduz34","description":"Maria Bundle is a rule engine implementation for Symfony applications that you can integrate to your projects and define your business rules easily.","archived":false,"fork":false,"pushed_at":"2020-11-17T14:39:37.000Z","size":51,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T05:08:45.055Z","etag":null,"topics":["bundle","library","php","rules-engine","symfony"],"latest_commit_sha":null,"homepage":null,"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/ibrahimgunduz34.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":"2019-11-15T16:23:50.000Z","updated_at":"2023-05-09T13:14:00.000Z","dependencies_parsed_at":"2022-08-15T15:50:14.170Z","dependency_job_id":null,"html_url":"https://github.com/ibrahimgunduz34/maria-bundle","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimgunduz34%2Fmaria-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimgunduz34%2Fmaria-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimgunduz34%2Fmaria-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimgunduz34%2Fmaria-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibrahimgunduz34","download_url":"https://codeload.github.com/ibrahimgunduz34/maria-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665747,"owners_count":21142123,"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":["bundle","library","php","rules-engine","symfony"],"created_at":"2024-09-30T15:27:46.903Z","updated_at":"2025-04-13T05:08:59.361Z","avatar_url":"https://github.com/ibrahimgunduz34.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MariaBundle \n[![Build Status](https://travis-ci.com/ibrahimgunduz34/maria-bundle.svg?token=vyj9YGL7pBUY54PzdkJC\u0026branch=master)](https://travis-ci.com/ibrahimgunduz34/maria-bundle)\n[![GitHub release](https://img.shields.io/github/release/ibrahimgunduz34/maria-bundle.svg)](https://gitHub.com/ibrahimgunduz34/maria-bundle/releases/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ibrahimgunduz34/maria-bundle/blob/master/LICENSE)\n\n## What is MariaBundle\n\nMaria is a simple and flexible business rule engine that you can integrate easily into \nyour Symfony applications through Bundle mechanism. It allows taking \nan action based on the rules when the input data matched. You can \ntrigger Maria by a trigger event you defined. It checks the input \nargument which comes through the trigger event by the rules and \ninvokes the action handler when matching occurred. Action handlers \nmight be a class or a reference that points to a service definition \nin the dependency injection system. So you can communicate with other Symfony \ncomponents easily through action handlers on Maria scenarios.\n\n## Installation\n\nYou can install Maria through composer\n\n```bash\n$ composer require ibrahimgunduz34/maria-bundle\n```\n\nAdd the bundle class to the bundle list by your Symfony version:\n\n### For Symfony 3.x users:\n\n**AppKernel.php**\n \n```php\n\u003c?php\n///...\npublic function registerBundles()\n{\n    $bundles = array(\n        //...\n        new SweetCode\\MariaBundle\\MariaBundle(),\n        //...\n    );\n}\n//...\n``` \n \n### For Symfony \u003e= 4 users:\n\n**config/bundles.php**\n\n```php\n\u003c?php\nreturn [\n  //...\n   SweetCode\\MariaBundle\\MariaBundle::class =\u003e ['all' =\u003e true],\n  //...  \n];\n```\n\n## Configuration Reference\n```yaml\n# config/packages/maria.yaml\nmaria:\n    scenarios_name:\n      trigger: \u003cThe event name you will trigger\u003e\n      handler: \u003cClass name or service reference\u003e\n#      handler:\n#        reference: \u003cClass or service reference from DI\u003e\n#        method: \u003chandler method name, default: onAction\u003e\n#        serialize: \u003ctrue | false, default: false\u003e\n      rules:\n        # You can define matchers as any, all, none, first or last matcher \n        # in the first line. If you won't an iterable object, you can simply\n        # use default or ignore the first line. \n        default: # [any | all | none | first | last | default ]\n          # You can define rules by numeric or associative arrays.\n          \n          # Associative arrays indicate that you will apply AND logic between the \n          # elements in the array\n          \n          # Numeric arrays indicate that you will apply OR logic between the \n          # elements in the array.\n          \n          # amount \u003e 100 AND category_id IN [1, 2, 3]\n          amount: {gt: 100}\n          category_id: { in: [1,2,3] }   \n          \n          # (amount \u003e AND category_id=1) OR (amount \u003c 500 AND category_id IN [5,6])\n          - amount: {gt: 100}\n            category_id: { eql: 1 }\n          - amount: [lt: 500]\n            category_id: { in: [5,6] }\n            \n          # (category_id IN [1,2] AND amount BETWEEN 100-200) OR (category_id = 3 AND amount \u003e= 200\n          - amount: { btw: [100, 200] }\n            category_id: { in: [1, 2] }\n          - amount: [lte: 200]\n            category_id: { eql: 3 }\n          \n          # Matching by RegExp\n          - { category_id: { in: [1,5] }, description: { regex: /awesome/i } }                 \n```\n\n## See Also\n* [Iterable Matchers](/Resources/docs/matchers.md)\n* [Arithmetic And Logic Operators](/Resources/docs/operators.md)\n \n## Example Usage\n\nDefine the following configuration into `config/packages/maria.yaml`\n\n```yaml\nmaria:\n    free_shipment:\n        trigger: cart.updated\n        handler: App\\Handler\\FreeShipmentHandler\n        rules:\n          amount: {gt: 100}\n          category_id: {eql: 1}\n```\n\nCreate a handler class in order to take an action to give free shipment\n\n```php\n\u003c?php\nnamespace App\\Handler;\n\nuse SweetCode\\MariaBundle\\MariaEventArg;\n\nclass FreeShipmentHandler\n{\n    public function onAction(MariaEventArg $eventArg){\n        //TODO: Write your magic code to give free shipment.\n        // You can reach your original input data by:\n        // $eventArg-\u003egetData();\n    }\n}\n```\n\nTrigger Maria where you updated cart in the project.\n```php\n\u003c?php\n//...\n/** @var \\Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface $eventDispatcher */\n$eventDispatcher = $container-\u003eget('event_dispatcher');\n// You can simply send an object or associative array to Maria through event context.\n$context = [\n    'amount'        =\u003e $order-\u003egetAmount(),\n    'category_id'   =\u003e $order-\u003egetCategoryId(),\n]\n$eventDispatcher-\u003edispatch(new \\SweetCode\\MariaBundle\\MariaEventArg($context), 'cart.updated');\n//...\n```\n\n## Working In Asynchronous Way\nMaria does not provide a way to invoke action handlers as asynchronous. However, you can make \naction handlers asynchronous easily by using other third-parties like `RabbitMqBundle` or \nbuilt-in Symfony components like `Messenger` You can make your action handler asynchronous by \nfollowing the steps below:\n\n**Important Notice:** We strongly recommend to follow the installation steps from `rabbitmq-bundle` repository:\n[https://github.com/php-amqplib/RabbitMqBundle](https://github.com/php-amqplib/RabbitMqBundle)\n\nInstall RabbitMqBundle\n```bash\n$ composer require php-amqplib/rabbitmq-bundle\n```\n\nAdd the bundle class to bundle the bundle list in the project:\n\n### For Symfony 3.x users:\n\n**AppKernel.php**\n \n```php\n\u003c?php\n///...\npublic function registerBundles()\n{\n    $bundles = array(\n        //...\n        new OldSound\\RabbitMqBundle\\OldSoundRabbitMqBundle(),\n        //...\n    );\n}\n//...\n``` \n \n### For Symfony \u003e= 4 users:\n\n**config/bundles.php**\n\n```php\n\u003c?php\nreturn [\n  //...\n   OldSound\\RabbitMqBundle\\OldSoundRabbitMqBundle::class =\u003e ['all' =\u003e true],\n  //...  \n];\n```\n\nConfigure the RabbitMq bundle.\n```yaml\n# config/packages/rabbitmq.yaml\n\nold_sound_rabbit_mq:\n    connections: \n        host: my.rabbitmq.host\n        user: rabbitmq\n        password: rabbitmq\n        vhost: '/'\n        lazy: false\n        connection_timeout: 3\n        read_write_timeout: 3\n        keepalive: false\n        heartbeat: 0\n        use_socket: true\n    producers:\n        email_producer:\n            connection: default\n            exchange_options: {name: 'emails', type: direct}\n            service_alias: email_producer # otherwise it gives very long service name\n    consumers:\n      email_consumer:\n        exchange_options: {name: 'emails', type: direct}\n        queue_options: {name: 'emails'} \n        # That's the service you need to implement as a consumer.\n        # Check the documentation from the repository to see how to implement a consumer:\n        # https://github.com/php-amqplib/RabbitMqBundle#consumers\n        callback: email_sender_service \n```\n\n\nAnd.. say maria, use `email_producer` as an action handler.\n\n```yaml\nmaria:\n    gift-email:\n        trigger: some.event\n        handler: \n          reference: '@email_producer'\n          method: 'publish'\n          erialize: true\n        rules:\n          ##...\n\n```\n\nEnjoy!\n\n## TODO:\n* Moving the scenario rules into different type of storage providers such as `in_memory` or `doctrine`\n* Validation improvement for configuration.\n\n## License:\nYou can access the license documentation [here](/LICENSE).\n\n## Credits:\nBundles structure, extension tests and the documentation partially inspired `RabbitMqBundle`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibrahimgunduz34%2Fmaria-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibrahimgunduz34%2Fmaria-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibrahimgunduz34%2Fmaria-bundle/lists"}