mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
sprintf the rules
This commit is contained in:
parent
1961487055
commit
53d84347c2
@ -58,7 +58,6 @@ class StoreRequest extends FormRequest
|
|||||||
'active' => ['active', 'boolean'],
|
'active' => ['active', 'boolean'],
|
||||||
];
|
];
|
||||||
$data = $this->getAllData($fields);
|
$data = $this->getAllData($fields);
|
||||||
|
|
||||||
$data['triggers'] = $this->getRuleTriggers();
|
$data['triggers'] = $this->getRuleTriggers();
|
||||||
$data['actions'] = $this->getRuleActions();
|
$data['actions'] = $this->getRuleActions();
|
||||||
|
|
||||||
@ -106,8 +105,8 @@ class StoreRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$validTriggers = $this->getTriggers();
|
$validTriggers = $this->getTriggers();
|
||||||
$validActions = array_keys(config('firefly.rule-actions'));
|
$validActions = array_keys(config('firefly.rule-actions'));
|
||||||
|
|
||||||
// some triggers and actions require text:
|
// some triggers and actions require text:
|
||||||
$contextTriggers = implode(',', $this->getTriggersWithContext());
|
$contextTriggers = implode(',', $this->getTriggersWithContext());
|
||||||
@ -119,12 +118,12 @@ class StoreRequest extends FormRequest
|
|||||||
'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title',
|
'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title',
|
||||||
'rule_group_title' => 'nullable|min:1|max:255|required_without:rule_group_id|belongsToUser:rule_groups,title',
|
'rule_group_title' => 'nullable|min:1|max:255|required_without:rule_group_id|belongsToUser:rule_groups,title',
|
||||||
'trigger' => 'required|in:store-journal,update-journal',
|
'trigger' => 'required|in:store-journal,update-journal',
|
||||||
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
|
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),
|
||||||
'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024',
|
'triggers.*.value' => 'required_if:actions.*.type,' . $contextTriggers . '|min:1|ruleTriggerValue|max:1024',
|
||||||
'triggers.*.stop_processing' => [new IsBoolean()],
|
'triggers.*.stop_processing' => [new IsBoolean()],
|
||||||
'triggers.*.active' => [new IsBoolean()],
|
'triggers.*.active' => [new IsBoolean()],
|
||||||
'actions.*.type' => 'required|in:'.implode(',', $validActions),
|
'actions.*.type' => 'required|in:' . implode(',', $validActions),
|
||||||
'actions.*.value' => ['required_if:actions.*.type,'.$contextActions, new IsValidActionExpression(), 'ruleActionValue'],
|
'actions.*.value' => [sprintf('required_if:actions.*.type,%s', $contextActions), new IsValidActionExpression(), 'ruleActionValue'],
|
||||||
'actions.*.stop_processing' => [new IsBoolean()],
|
'actions.*.stop_processing' => [new IsBoolean()],
|
||||||
'actions.*.active' => [new IsBoolean()],
|
'actions.*.active' => [new IsBoolean()],
|
||||||
'strict' => [new IsBoolean()],
|
'strict' => [new IsBoolean()],
|
||||||
@ -182,10 +181,10 @@ class StoreRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
protected function atLeastOneActiveTrigger(Validator $validator): void
|
protected function atLeastOneActiveTrigger(Validator $validator): void
|
||||||
{
|
{
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
|
|
||||||
/** @var null|array|int|string $triggers */
|
/** @var null|array|int|string $triggers */
|
||||||
$triggers = $data['triggers'] ?? [];
|
$triggers = $data['triggers'] ?? [];
|
||||||
// need at least one trigger
|
// need at least one trigger
|
||||||
if (!is_countable($triggers) || 0 === count($triggers)) {
|
if (!is_countable($triggers) || 0 === count($triggers)) {
|
||||||
return;
|
return;
|
||||||
@ -211,10 +210,10 @@ class StoreRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
protected function atLeastOneActiveAction(Validator $validator): void
|
protected function atLeastOneActiveAction(Validator $validator): void
|
||||||
{
|
{
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
|
|
||||||
/** @var null|array|int|string $actions */
|
/** @var null|array|int|string $actions */
|
||||||
$actions = $data['actions'] ?? [];
|
$actions = $data['actions'] ?? [];
|
||||||
// need at least one trigger
|
// need at least one trigger
|
||||||
if (!is_countable($actions) || 0 === count($actions)) {
|
if (!is_countable($actions) || 0 === count($actions)) {
|
||||||
return;
|
return;
|
||||||
|
@ -141,7 +141,7 @@ class UpdateRequest extends FormRequest
|
|||||||
'triggers.*.stop_processing' => [new IsBoolean()],
|
'triggers.*.stop_processing' => [new IsBoolean()],
|
||||||
'triggers.*.active' => [new IsBoolean()],
|
'triggers.*.active' => [new IsBoolean()],
|
||||||
'actions.*.type' => 'required|in:'.implode(',', $validActions),
|
'actions.*.type' => 'required|in:'.implode(',', $validActions),
|
||||||
'actions.*.value' => ['required_if:actions.*.type,'.$contextActions, new IsValidActionExpression(), 'ruleActionValue'],
|
'actions.*.value' => [sprintf('required_if:actions.*.type,%s',$contextActions), new IsValidActionExpression(), 'ruleActionValue'],
|
||||||
'actions.*.stop_processing' => [new IsBoolean()],
|
'actions.*.stop_processing' => [new IsBoolean()],
|
||||||
'actions.*.active' => [new IsBoolean()],
|
'actions.*.active' => [new IsBoolean()],
|
||||||
'strict' => [new IsBoolean()],
|
'strict' => [new IsBoolean()],
|
||||||
|
Loading…
Reference in New Issue
Block a user