Created
February 5, 2015 20:40
-
-
Save fago/1b6026a5fd6c203f8e19 to your computer and use it in GitHub Desktop.
RulesDX for adding actions and conditions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Existing PR: https://github.com/fago/rules/pull/134/files | |
| $rule->addCondition('rules_test_string_condition', [ | |
| 'context_mapping' => ['text:select' => 'node:uid:0:entity:name:0:value'], | |
| ])); | |
| ]); | |
| // With value object: | |
| $rule->addCondition('rules_test_string_condition', ContextConfig() | |
| ->map('text', 'node:uid:0:entity:name:0:value') | |
| )); | |
| // More options: | |
| $rule->addCondition('example', ContextConfig() | |
| ->map('user', 'node:author') | |
| ->map('user2', 'node2:author') | |
| ->setContextValue('text', 'some-text') | |
| ->process('text', 'uppercase_data_processor_plugin', $optional_processor_config_array) | |
| ->setConfigKey('only-for-extra-config-used-by-some-plugins', $value) | |
| ->negateResult() | |
| )); | |
| // Then addCondition() can just do: $context_config->toArray() and instantiate the expression. | |
| // ContextConfig methods can check provided values for sanity / conflicts and throw exceptions as necessary. | |
| // addCondition(), addAction() and addExpression() can all take the ContextConfig class as parameter | |
| // Validation of ContextConfig can be done by ContextConfig::checkConfig($expression), to be invoked by the add*() methods | |
| // Create via __invoke() | |
| $config = ContextConfig(); | |
| // Create via method. | |
| $config = ContextConfig::create(); | |
| // or from array: | |
| ContextConfig::create($values) | |
| ->checkConfig(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment