Skip to content

Commit

Permalink
Delete "Rule", use simple rules first
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Mar 21, 2024
1 parent 4466377 commit d920ac5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 199 deletions.
41 changes: 37 additions & 4 deletions src/Validate/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function labels()
* @param array<string, mixed> $data
* @return array<string, string>
*/
public function rules(array $data)
public function rules($data)
{
return $this->rules;
}
Expand All @@ -100,6 +100,32 @@ public function setError($key, $text)
return $this;
}

/**
* Sets the labels for the validator.
*
* @param array<string, string> $labels
* @return self
*/
public function setLabels($labels)

Check warning on line 109 in src/Validate/Check.php

View check run for this annotation

Codecov / codecov/patch

src/Validate/Check.php#L109

Added line #L109 was not covered by tests
{
$this->labels = $labels;

Check warning on line 111 in src/Validate/Check.php

View check run for this annotation

Codecov / codecov/patch

src/Validate/Check.php#L111

Added line #L111 was not covered by tests

return $this;

Check warning on line 113 in src/Validate/Check.php

View check run for this annotation

Codecov / codecov/patch

src/Validate/Check.php#L113

Added line #L113 was not covered by tests
}

/**
* Sets the rules for the validator.
*
* @param array<string, string> $rules
* @return self
*/
public function setRules($rules)

Check warning on line 122 in src/Validate/Check.php

View check run for this annotation

Codecov / codecov/patch

src/Validate/Check.php#L122

Added line #L122 was not covered by tests
{
$this->rules = $rules;

Check warning on line 124 in src/Validate/Check.php

View check run for this annotation

Codecov / codecov/patch

src/Validate/Check.php#L124

Added line #L124 was not covered by tests

return $this;

Check warning on line 126 in src/Validate/Check.php

View check run for this annotation

Codecov / codecov/patch

src/Validate/Check.php#L126

Added line #L126 was not covered by tests
}

/**
* Checks if the payload is valid againsts the specified rules.
*
Expand All @@ -119,11 +145,18 @@ public function valid(array $data = null)

$rules = $this->rules($data);

foreach ($rules as $key => $value)
foreach ($rules as $key => $rule)
{
$rule = new Rule($valid);
// Break down multiple rules ---
$items = explode('|', $rule);

$valid = $rule->parse($key, $value);
// TODO: Allow custom rules from existing, new ones ---
foreach ($items as $item)
{
$valid->rule($item, $key);
}
// ----------------------------------------------------
// -----------------------------
}

$valid = $valid->withData($data);
Expand Down
195 changes: 0 additions & 195 deletions src/Validate/Rule.php

This file was deleted.

0 comments on commit d920ac5

Please sign in to comment.