示例#1
0
文件: item.php 项目: Zegnat/library
 public function validate()
 {
     // check for a valid library object
     if (!is_a($this->library, 'Library')) {
         throw new Exception('The library object is invalid');
     }
     // check for all required fields
     foreach (static::$required as $field) {
         if (empty($this->data[$field])) {
             throw new Exception('Missing required field: ' . $field);
         }
     }
     // id validation
     if (!is_string($this->data['id']) or !v::alphanum($this->data['id']) or str::length($this->data['id']) !== 32) {
         throw new Exception('Invalid id');
     }
     // type validation
     if (!is_string($this->data['type']) or !v::between($this->data['type'], 2, 32)) {
         throw new Exception('Invalid type');
     }
     // status validation
     if (!in_array($this->data['status'], static::$statuses)) {
         throw new Exception('Invalid status: ' . $this->data['status']);
     }
     // check for invalid updated timestamp
     if (!is_int($this->data['updated']) or !v::between(date('Y', $this->data['updated']), 1980, 2500)) {
         throw new Exception('Invalid updated timestamp');
     }
     // check for invalid created timestamp
     if (!is_int($this->data['created']) or !v::between(date('Y', $this->data['created']), 1980, 2500) or $this->data['created'] > time()) {
         throw new Exception('Invalid created timestamp');
     }
 }
示例#2
0
文件: VTest.php 项目: nsteiner/kdoc
 public function testAlphaNum()
 {
     $this->assertTrue(v::alphanum('abc1234'));
     $this->assertFalse(v::alphanum('#!asdas'));
 }
示例#3
0
 *
 * @return  boolean
 */
v::$validators['requiredWith'] = function ($key, $dependency, $array) {
    return !empty($array[$dependency]) && v::required($key, $array);
};
/**
 * Required (Conditionally)
 *
 * Field has to be present only if the other specified field IS NOT present.
 *
 * @param   string  $key         Name of the field to test.
 * @param   string  $dependency  Name of the field the actual field depends on.
 * @param   array   $array       Collection of data values.
 *
 * @return  boolean
 */
v::$validators['requiredWithout'] = function ($key, $dependency, $array) {
    return !empty($array[$dependency]) || v::required($key, $array);
};
/**
 * Username Validator
 *
 * Ensures the given user name exists in the system.
 *
 * @param mixed  $value  Value to test.
 * @return  boolean
 */
v::$validators['user'] = function ($value) {
    return v::alphanum($value) && kirby()->site()->users()->find($value);
};