fork download
  1. <?php
  2.  
  3. class X {
  4. private $regras = [
  5. "required"=>true,
  6. "email"=>true
  7. ];
  8.  
  9. public $filter = [
  10. 'preco' => 'required;double(1,4)',
  11. 'email' => 'required;email',
  12. 'bilhetes' => 'required;min:0'
  13. ];
  14.  
  15. public function bootFilterPost() {
  16.  
  17. foreach ($this->filter as $key => $value):
  18. $arr = preg_split('/(;)/', $value);
  19.  
  20. foreach ($arr as $a):
  21.  
  22. if (array_key_exists ($a, $this->regras)):
  23. $this->postRules[$key][$a] = $this->regras[$a];
  24. elseif (strpos($a, "(") !== false):
  25. $split = explode("(", $a);
  26. $this->postRules[$key][$split[0]] = "(" . $split[1];
  27. elseif (strpos($a, ":") !== false):
  28. $split = explode(":", $a);
  29. $this->postRules[$key][$split[0]] = $split[1];
  30. endif;
  31.  
  32.  
  33. endforeach;
  34. endforeach;
  35.  
  36. var_dump($this->postRules);
  37. }
  38. };
  39.  
  40.  
  41.  
  42.  
  43. $x = new X;
  44.  
  45. $x->bootFilterPost();
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
array(3) {
  ["preco"]=>
  array(2) {
    ["required"]=>
    bool(true)
    ["double"]=>
    string(5) "(1,4)"
  }
  ["email"]=>
  array(2) {
    ["required"]=>
    bool(true)
    ["email"]=>
    bool(true)
  }
  ["bilhetes"]=>
  array(2) {
    ["required"]=>
    bool(true)
    ["min"]=>
    string(1) "0"
  }
}