예제 #1
0
 /**
  * @throws Hypercharge\Errors\ValidationError
  * @return void
  */
 function validate()
 {
     $errors = new Errors\ValidationError();
     if (!preg_match('/^[a-f0-9]{32}$/', $this->unique_id)) {
         $errors->add('unique_id', 'must be 32 character hex string but was: ' . $this->unique_id);
     }
     if ($errors->flush()) {
         throw $errors;
     }
 }
 /**
  * @throws Hypercharge\Errors\ValidationError if not valid
  */
 function validate()
 {
     $errors = new Errors\ValidationError();
     $dateFormat = '/^\\d\\d\\d\\d-\\d\\d-\\d\\d$/';
     if (!preg_match($dateFormat, $this->start_date)) {
         $errors->add('start_date', 'must be yyyy-mm-dd');
     }
     if (!empty($this->end_date) && !preg_match($dateFormat, $this->end_date)) {
         $errors->add('end_date', 'must be yyyy-mm-dd');
     }
     if (is_int($this->page) && $this->page <= 0) {
         $errors->add('page', 'must be an integer greater or equal 1');
     }
     if ($errors->flush()) {
         throw $errors;
     }
 }