コード例 #1
0
ファイル: VTest.php プロジェクト: nsteiner/kdoc
 public function testMin()
 {
     $this->assertTrue(v::min('superstring', 5));
     $this->assertFalse(v::min('superstring', 20));
     $this->assertTrue(v::min(6, 5));
     $this->assertFalse(v::min(6, 20));
     $this->assertTrue(v::min(range(0, 10), 5));
     $this->assertFalse(v::min(range(0, 10), 20));
 }
コード例 #2
0
ファイル: number.php プロジェクト: muten84/luigibifulco.it
 public function validate()
 {
     if (!v::num($this->result())) {
         return false;
     }
     if ($this->min and !v::min($this->result(), $this->min)) {
         return false;
     }
     if ($this->max and !v::max($this->result(), $this->max)) {
         return false;
     }
     return true;
 }
コード例 #3
0
 public function validate()
 {
     if ($this->validate and is_array($this->validate)) {
         return parent::validate();
     } else {
         if ($this->min and !v::min($this->result(), $this->min)) {
             return false;
         }
         if ($this->max and !v::max($this->result(), $this->max)) {
             return false;
         }
     }
     return true;
 }
コード例 #4
0
 public function sendBookingConfirmation()
 {
     $responseMessages = array();
     $fault = false;
     if (!v::required('email', get())) {
         $responseMessages[] = array('type' => 'error', 'message' => 'No email given, cheating ass bitch!');
         $fault = true;
     } else {
         if (!v::email(get('email'))) {
             $responseMessages[] = array('type' => 'error', 'message' => 'No email given, cheating ass bitch!');
             $fault = true;
         }
     }
     if (!v::required('productSelect', get())) {
         $responseMessages[] = array('type' => 'error', 'message' => 'No product given, cheating ass bitch!');
         $fault = true;
     }
     if (!v::required('date', get())) {
         $responseMessages[] = array('type' => 'error', 'message' => 'No date given, cheating ass bitch!');
         $fault = true;
     } else {
         if (!v::date(get('date'))) {
             $responseMessages[] = array('type' => 'error', 'message' => 'No valid Date, son of a bitch!');
             $fault = true;
         }
     }
     if (!v::required('name', get())) {
         $responseMessages[] = array('type' => 'error', 'message' => 'No name given, cheating ass bitch!');
         $fault = true;
     } else {
         if (!v::min(get('name'), 3)) {
             $responseMessages[] = array('type' => 'error', 'message' => 'At least 3 characters for a name, bitchass!');
             $fault = true;
         }
     }
     if ($fault) {
         s::set('response', $responseMessages);
         go($this->getOriginId());
     }
     $confirmationBody = self::buildMailText($this->getConfirmationText(), get());
     $ownerConfirmation = $confirmationBody . self::createBookingApprovalLink(get('email'), array(), array());
     $from = site()->contactmail()->value();
     // Send To Owner
     $confirmationMail = new Email(array('to' => self::getBookingMail(), 'from' => $from, 'subject' => 'Hey, some new booking', 'body' => $ownerConfirmation));
     // Send to User
     $userConfirmationMail = new Email(array('to' => get('email'), 'from' => $from, 'subject' => 'Hey, some new booking', 'body' => $confirmationBody));
     if ($userConfirmationMail->send() && $confirmationMail->send()) {
         $responseMessages[] = array('type' => 'success', 'message' => 'Successfully send a booking request.');
         s::set('response', $responseMessages);
     } else {
         go('error');
     }
     go($this->getOriginId());
 }
コード例 #5
0
ファイル: v.php プロジェクト: kristianhalte/super_organic
    return v::min($value, $min) && v::max($value, $max);
}, 'date' => function ($value) {
    $time = strtotime($value);
    if (!$time) {
        return false;
    }
    $year = date('Y', $time);
    $month = date('m', $time);
    $day = date('d', $time);
    return checkdate($month, $day, $year);
}, 'different' => function ($value, $other) {
    return $value !== $other;
}, 'email' => function ($value) {
    return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
}, 'filename' => function ($value) {
    return v::match($value, '/^[a-z0-9@._-]+$/i') && v::min($value, 2);
}, 'in' => function ($value, $in) {
    return in_array($value, $in, true);
}, 'integer' => function ($value) {
    return filter_var($value, FILTER_VALIDATE_INT) !== false;
}, 'ip' => function ($value) {
    return filter_var($value, FILTER_VALIDATE_IP) !== false;
}, 'match' => function ($value, $preg) {
    return preg_match($preg, $value) > 0;
}, 'max' => function ($value, $max) {
    return size($value) <= $max;
}, 'min' => function ($value, $min) {
    return size($value) >= $min;
}, 'notIn' => function ($value, $notIn) {
    return !v::in($value, $notIn);
}, 'num' => function ($value) {
コード例 #6
0
ファイル: v.php プロジェクト: robinandersen/robin
}, 'in' => function ($value, $in) {
    return in_array($value, $in, true);
}, 'integer' => function ($value) {
    return filter_var($value, FILTER_VALIDATE_INT) !== false;
}, 'ip' => function ($value) {
    return filter_var($value, FILTER_VALIDATE_IP) !== false;
}, 'match' => function ($value, $preg) {
    return preg_match($preg, $value) == true;
}, 'max' => function ($value, $max) {
    return size($value) <= $max;
}, 'min' => function ($value, $min) {
    return size($value) >= $min;
}, 'maxWords' => function ($value, $max) {
    return v::max(explode(' ', $value), $max);
}, 'minWords' => function ($value, $min) {
    return v::min(explode(' ', $value), $min);
}, 'notIn' => function ($value, $notIn) {
    return !v::in($value, $notIn);
}, 'num' => function ($value) {
    return is_numeric($value);
}, 'required' => function ($key, $array) {
    return !empty($array[$key]);
}, 'same' => function ($value, $other) {
    return $value === $other;
}, 'size' => function ($value, $size) {
    return size($value) == $size;
}, 'url' => function ($value) {
    // In search for the perfect regular expression: https://mathiasbynens.be/demo/url-regex
    $regex = '_^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)*(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}]{2,})))(?::\\d{2,5})?(?:/[^\\s]*)?$_iu';
    return preg_match($regex, $value);
});