示例#1
0
 public function testUniqueWithObject()
 {
     $obj1 = (object) array('name' => 'name', 'other' => 'other');
     $obj2 = (object) array('other' => 'other', 'name' => 'name');
     $value = array(1, 'str', $obj1, false, $obj2, 2, 1);
     $expected = array(1, 'str', $obj1, false, 2);
     $this->assertEquals($expected, Utils::uniqueArray($value));
 }
示例#2
0
 protected function validateArray($data, $schema)
 {
     # maxItems
     if (isset($schema->maxItems)) {
         $this->validateMaxMin($data, $schema->maxItems, true);
     }
     if (!$this->lax) {
         # minItems
         if (isset($schema->minItems)) {
             $this->validateMaxMin($data, $schema->minItems, false);
         }
     }
     # uniqueItems
     if (Utils::get($schema, 'uniqueItems', false)) {
         if (!Utils::uniqueArray($data, true)) {
             $this->throwError('contains duplicate values');
         }
     }
     # items
     $items = Utils::get($schema, 'items', array());
     # additionalItems
     $additional = Utils::get($schema, 'additionalItems', true);
     if (false === $additional && is_array($items)) {
         if (count($data) > count($items)) {
             $this->throwError('contains more elements than are allowed');
         }
     }
     $this->validateArrayChildren($data, $items, $additional);
 }