--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To post to this group, send email to silverst...@googlegroups.com.
To unsubscribe from this group, send email to silverstripe-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/silverstripe-dev?hl=en.
To view this discussion on the web visit https://groups.google.com/d/msg/silverstripe-dev/-/j2T9Ju_dzM0J.
The behaviour of merging can be altered by providing a custom MergeStrategy directive with a configuration block.
For example, the following configuration makes use of the ReplaceYamlMergeStrategy class to completely replace a config block instead of merging subsequent values
Assume the following defined in core_code/_config/core.yml
---
Name: original_config
---
Injector:
Something:
constructor:
- Page
- Sixth
And the following in my_custom_module/_config/override.yml
---
Name: second_bit
MergeStrategy:
Injector/Something: replace
---
Something:
constructor:
- DataObject
- Monster
The MergeStrategy entry of the metadata block defines a configuration_path:strategy pair;
In the above example, a reference to $config->get('Injector', 'Something');
would return an array containing'constructor' => array('DataObject', 'Monster');
, as opposed to the default behaviour which would return an array containingarray('Page', 'Sixth', 'DataObject', 'Monster');
To handle the merge process in a custom way, simply define a class that implements YamlMergeStrategy
---
MergeStrategy:
Injector/Something: replace
---
Injector:
Something:
constructor:
- DataObject
- Monster
---
MergeStrategy:
Injector/Something: replace
---
Injector:
Something:
constructor:
- DataObject
- Monster
SomeOtherThing:
constructor:
- Ghost
---
MergeStrategy:
Injector/Something: replace
Injector/SomeOtherThing: insertfirst
---
Injector:
Something:
constructor:
- DataObject
- Monster
SomeOtherThing:
constructor:
- Ghost
- how do you know what level is an unnamed piece?
- having custom defined merge strategies feels like something a developer should be being explicit about to prevent hidden side effects
---
MergeStrategy:
Injector/Something: replace
Injector/SomeOtherThing/constructor: insertfirst
---
Injector:
Something:
constructor:
- DataObject
- Monster
SomeOtherThing:
constructor:
- Ghost
---
MergeStrategy:
Injector/Something/constructor: replace
Injector/SomeOtherThing/constructor: insertfirst
---
Injector:
Something:
constructor:
- DataObject
- Monster
someOtherProperty:
Foo: 1
Bar: 2
SomeOtherThing:
constructor:
- Ghost
When you say "preserve" the order, are you meaning preserving the order of the existing config, or the new items being merged in?I wasn't sure what was desired here, so I took it to be that existing keys stayed in their current place, and new keys were inserted after them, but it probably should be that the 'src' keys should be preserved in that order.
--
--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/groups/opt_out.