Refactor: harden contracts before v2.0.0 — reserved Context key, final Store, strict feature validation - #10
Merged
Merged
Conversation
The Store is injected into the Context under the key "rules", which silently overwrites any user-defined parameter with the same name. The key is now reserved: constructing a Progressive with a Context containing a "rules" parameter throws a LogicException instead of overwriting it. The key is exposed as StoreInterface::BAG_KEY (@internal).
Store is now final: the built-in rules (enabled, partial, unanimous) are part of the config language and can never be removed, overridden or shadowed.
Extension is composition-only, via the new constructor
parameter:
new Store([$myRule, ...])
Extra rules are appended after the built-in ones. Passing a rule whose name collides with a built-in throws a LogicException.
The protected load() hook is removed (replaced by the private getBuiltInRules()): subclasses could previously remove built-in rules, which contradicts the library's contract.
A feature must now be either a boolean or an array containing exactly one rule or strategy. Previously, empty arrays, scalars and other malformed values passed validation and silently evaluated to false at runtime, masking misconfigurations instead of surfacing them. Note: the rule's *parameters* are unaffected; a rule declared with empty params (e.g. `['env' => []]`) remains valid.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Final pass of contract hardening before tagging v2.0.0.
injects the Store into the Context under this key. Any user-defined
parameter with that name now throws a
LogicExceptionat constructioninstead of being silently overwritten. Exposed as
StoreInterface::BAG_KEY(
@internal).Storeis now final. The built-in rules (enabled,partial,unanimous) are part of the config language: they are always loaded andcan never be removed or shadowed. Extension is composition-only via the
constructor:
new Store([$myRule, ...]). The protectedload()hook(which allowed subclasses to remove built-ins) and the unused
Store::list()are removed.A feature must be a boolean or an array containing exactly one rule or
strategy. Previously,
'',42,[]passed validation and silentlyevaluated to false at runtime.
Fixed
Validatorexception message ("startegy")Store::list()@var StoreInterfacedocumentation with a runtimeassert()inPartial/Unanimous(type narration now enforced, not asserted by faith)built-in override rejection, reserved key rejection, strict feature validation