function validateProduct(&$product)
{
    $invalids = array();
    if (empty($product['name']) || !Validation::string()->length(1, 255)->validate($product['name'])) {
        array_push($invalids, 'name');
    }
    if (empty($product['price']) || !Validation::float()->min(0, true)->validate($product['price'])) {
        array_push($invalids, 'price');
    }
    if (empty($product['amount']) || !Validation::int()->min(1, true)->validate($product['amount'])) {
        array_push($invalids, 'amount');
    }
    if (empty($product['categoryId']) || !Validation::int()->max(10, true)->validate($product['categoryId'])) {
        array_push($invalids, 'categoryId');
    }
    return $invalids;
}
Exemple #2
0
 /**
  * @PrePersist
  * @PreUpdate
  */
 public function validate()
 {
     v::float()->assert($this->amount);
     v::numeric("+")->startsWith("+")->assert($this->phone);
     v::notEmpty()->assert($this->status);
 }
Exemple #3
0
function validateCombo(&$combo)
{
    $invalids = array();
    if (empty($combo['name']) || !Validation::string()->length(1, 255)->validate($combo['name'])) {
        array_push($invalids, 'name');
    }
    if (empty($combo['price1']) || !Validation::float()->min(0, true)->validate($combo['price1'])) {
        array_push($invalids, 'price1');
    }
    if (empty($combo['amount1']) || !Validation::int()->min(1, true)->validate($combo['amount1'])) {
        array_push($invalids, 'amount1');
    }
    //check if combos 2, 3 or 4 are given
    if (!empty($combo['price2']) || !empty($combo['amount2']) || !empty($combo['price3']) || !empty($combo['amount3']) || !empty($combo['price4']) || !empty($combo['amount4'])) {
        if (empty($combo['price2']) || !Validation::float()->min(0, true)->validate($combo['price2'])) {
            array_push($invalids, 'price2');
        }
        if (empty($combo['amount2']) || !Validation::int()->min(1, true)->validate($combo['amount2'])) {
            array_push($invalids, 'amount2');
        }
    } else {
        $combo['price2'] = $combo['amount2'] = null;
    }
    //check if combos 3 or 4 are given
    if (!empty($combo['price3']) || !empty($combo['amount3']) || !empty($combo['price4']) || !empty($combo['amount4'])) {
        if (empty($combo['price3']) || !Validation::float()->min(0, true)->validate($combo['price3'])) {
            array_push($invalids, 'price3');
        }
        if (empty($combo['amount3']) || !Validation::int()->min(1, true)->validate($combo['amount3'])) {
            array_push($invalids, 'amount3');
        }
    } else {
        $combo['price3'] = $combo['amount3'] = null;
    }
    //check if combo 4 is given
    if (!empty($combo['price4']) || !empty($combo['amount4'])) {
        if (empty($combo['price4']) || !Validation::float()->min(0, true)->validate($combo['price4'])) {
            array_push($invalids, 'price4');
        }
        if (empty($combo['amount4']) || !Validation::int()->min(1, true)->validate($combo['amount4'])) {
            array_push($invalids, 'amount4');
        }
    } else {
        $combo['price4'] = $combo['amount4'] = null;
    }
    return $invalids;
}
 public function init()
 {
     $this->validator = v::attribute('name', v::string()->notEmpty())->attribute('email', v::email())->attribute('description', v::string()->length(5, 50))->attribute('age', v::callback('is_int')->between(0, 100))->attribute('nick', v::string()->alnum()->noWhitespace())->attribute('creditCard', v::numeric()->creditCard())->attribute('accountBalance', v::float())->attribute('banned', v::bool())->attribute('views', v::callback('is_int')->positive());
 }