mirror of
https://codeberg.org/reflect/reflect-rules-plugin.git
synced 2025-09-14 00:43:42 +02:00
feat: add default() rule
This commit is contained in:
parent
6583f87866
commit
9a525e45c7
1 changed files with 16 additions and 2 deletions
|
@ -24,6 +24,9 @@
|
||||||
public bool $required = false;
|
public bool $required = false;
|
||||||
public ?Type $type = null;
|
public ?Type $type = null;
|
||||||
|
|
||||||
|
private bool $default_enabled = false;
|
||||||
|
public mixed $default;
|
||||||
|
|
||||||
public ?int $min = null;
|
public ?int $min = null;
|
||||||
public ?int $max = null;
|
public ?int $max = null;
|
||||||
|
|
||||||
|
@ -76,6 +79,14 @@
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set a default value if property is not provided
|
||||||
|
public function default(mixed $value): self {
|
||||||
|
$this->default_enabled = true;
|
||||||
|
$this->default = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
# Eval methods
|
# Eval methods
|
||||||
These methods are used to check conformity against set rules.
|
These methods are used to check conformity against set rules.
|
||||||
|
@ -124,8 +135,11 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Property does not exist in scope, create nulled superglobal for it
|
// Property does not exist in superglobal, create one with default value if enabled
|
||||||
$scope_data[$this->property] = null;
|
if ($this->default_enabled) {
|
||||||
|
$scope_data[$this->property] = $this->default;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue