Example #1
0
 function testNestedPathValid()
 {
     $ctx = new Context();
     $ctx->push('a', 'a');
     $ctx->push('b', 'b');
     $ctx->getNode()->valid = false;
     $ctx->push('c', 'c');
     $ctx->pop('c');
     $ctx->pop('b');
     $ctx->pop('a');
     $this->assertTrue($ctx->pathValid(['a', 'b', 'c']));
     $this->assertFalse($ctx->pathValid(['a', 'b']));
     $this->assertFalse($ctx->pathValid(['a']));
 }
Example #2
0
 function validate(array $properties, Context $ctx)
 {
     $dateMin = $properties['dateMin'];
     $dateMax = $properties['dateMax'];
     if (!$dateMin || !$dateMax) {
         return;
     }
     if (!$ctx->pathValid($this->dateMin) || !$ctx->pathValid($this->dateMax)) {
         return;
     }
     if (!$dateMin instanceof \DateTime || !$dateMax instanceof \DateTime) {
         return;
     }
     if ($dateMin > $dateMax) {
         $ctx->addReason($this, ['id' => 'dateRange.invalid', 'params' => ['min' => $dateMin, 'max' => $dateMax]]);
     }
 }
Example #3
0
 function validate(array $properties, Context $ctx)
 {
     $left = $properties['left'];
     $right = $properties['right'];
     if (!$ctx->pathValid($this->left) || !$ctx->pathValid($this->right)) {
         return;
     }
     cmp_null:
     if ($left === null && $right === null) {
         if ($this->compare == 'null') {
             return $left === null && $right === null;
         } else {
             return;
         }
     }
     $compare = $this->compare;
     switch ($compare) {
         case 'integer':
             $compare = 'int';
         case 'float':
             $compare = 'double';
         case 'string':
         case 'double':
         case 'decimal':
         case 'int':
         case 'date':
         case 'bool':
             $m = 'compare' . $compare;
             return $this->{$m}($ctx, $left, $right);
         default:
             if (isset($this->comparators[$compare])) {
                 return $this->comparators[$compare]->compare($ctx, $left, $right) === 0;
             }
     }
     $ctx->addReason($this, ['id' => 'equal.incomparable', 'params' => ['leftProp' => $this->left, 'rightProp' => $this->right]]);
 }