Skip to content

Commit

Permalink
Improve add/remove interface for validation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Jun 9, 2024
1 parent d07b4b4 commit 366d0a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Modules and plugins can have config files in the /config directory. Plugin and m

````
// Get a configuration string from the CMS module
echo Config::get('cms::options.allowComments');
echo Config::get('cms::options.allow_comments');
// Get a configuration string from the october/blog plugin.
echo Config::get('october.blog::options.allowComments');
echo Config::get('october.blog::options.allow_comments');
````

## Overriding configuration strings
Expand Down
14 changes: 12 additions & 2 deletions src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,26 @@ public function addValidationRule(string $name, $definition)
$rules = explode('|', $rules);
}

$rules[] = $definition;
if (is_array($definition)) {
$rules = array_merge($rules, $definition);
}
else {
$rules[] = $definition;
}

$this->rules[$name] = $rules;
}

/**
* removeValidationRule removes a validation rule from the stack and resets the value as a processed array
*/
public function removeValidationRule(string $name, $definition)
public function removeValidationRule(string $name, $definition = '*')
{
if ($definition === '*') {
unset($this->rules[$name]);
return;
}

$rules = $this->rules[$name] ?? [];
if (!is_array($rules)) {
$rules = explode('|', $rules);
Expand Down

0 comments on commit 366d0a3

Please sign in to comment.