OXIESEC PANEL
- Current Dir:
/
/
usr
/
share
/
php
/
JsonSchema
/
Constraints
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
π
..
-
07/20/2024 06:32:21 AM
rwxr-xr-x
π
BaseConstraint.php
3.79 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
CollectionConstraint.php
6.17 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
Constraint.php
6.43 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
ConstraintInterface.php
1.53 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
EnumConstraint.php
1.61 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
Factory.php
5.65 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
FormatConstraint.php
8.65 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
NumberConstraint.php
3.68 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
ObjectConstraint.php
7.89 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
SchemaConstraint.php
3.73 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
StringConstraint.php
1.94 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
TypeCheck
-
07/20/2024 06:32:21 AM
rwxr-xr-x
π
TypeConstraint.php
7.79 KB
10/21/2017 01:15:38 PM
rw-r--r--
π
UndefinedConstraint.php
15.19 KB
10/21/2017 01:15:38 PM
rw-r--r--
Editing: NumberConstraint.php
Close
<?php /* * This file is part of the JsonSchema package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace JsonSchema\Constraints; use JsonSchema\Entity\JsonPointer; /** * The NumberConstraint Constraints, validates an number against a given schema * * @author Robert SchΓΆnthal <seroscho@googlemail.com> * @author Bruno Prieto Reis <bruno.p.reis@gmail.com> */ class NumberConstraint extends Constraint { /** * {@inheritdoc} */ public function check(&$element, $schema = null, JsonPointer $path = null, $i = null) { // Verify minimum if (isset($schema->exclusiveMinimum)) { if (isset($schema->minimum)) { if ($schema->exclusiveMinimum && $element <= $schema->minimum) { $this->addError($path, 'Must have a minimum value of ' . $schema->minimum, 'exclusiveMinimum', array('minimum' => $schema->minimum)); } elseif ($element < $schema->minimum) { $this->addError($path, 'Must have a minimum value of ' . $schema->minimum, 'minimum', array('minimum' => $schema->minimum)); } } else { $this->addError($path, 'Use of exclusiveMinimum requires presence of minimum', 'missingMinimum'); } } elseif (isset($schema->minimum) && $element < $schema->minimum) { $this->addError($path, 'Must have a minimum value of ' . $schema->minimum, 'minimum', array('minimum' => $schema->minimum)); } // Verify maximum if (isset($schema->exclusiveMaximum)) { if (isset($schema->maximum)) { if ($schema->exclusiveMaximum && $element >= $schema->maximum) { $this->addError($path, 'Must have a maximum value of ' . $schema->maximum, 'exclusiveMaximum', array('maximum' => $schema->maximum)); } elseif ($element > $schema->maximum) { $this->addError($path, 'Must have a maximum value of ' . $schema->maximum, 'maximum', array('maximum' => $schema->maximum)); } } else { $this->addError($path, 'Use of exclusiveMaximum requires presence of maximum', 'missingMaximum'); } } elseif (isset($schema->maximum) && $element > $schema->maximum) { $this->addError($path, 'Must have a maximum value of ' . $schema->maximum, 'maximum', array('maximum' => $schema->maximum)); } // Verify divisibleBy - Draft v3 if (isset($schema->divisibleBy) && $this->fmod($element, $schema->divisibleBy) != 0) { $this->addError($path, 'Is not divisible by ' . $schema->divisibleBy, 'divisibleBy', array('divisibleBy' => $schema->divisibleBy)); } // Verify multipleOf - Draft v4 if (isset($schema->multipleOf) && $this->fmod($element, $schema->multipleOf) != 0) { $this->addError($path, 'Must be a multiple of ' . $schema->multipleOf, 'multipleOf', array('multipleOf' => $schema->multipleOf)); } $this->checkFormat($element, $schema, $path, $i); } private function fmod($number1, $number2) { $number1 = abs($number1); $modulus = fmod($number1, $number2); $precision = abs(0.0000000001); $diff = (float) ($modulus - $number2); if (-$precision < $diff && $diff < $precision) { return 0.0; } $decimals1 = mb_strpos($number1, '.') ? mb_strlen($number1) - mb_strpos($number1, '.') - 1 : 0; $decimals2 = mb_strpos($number2, '.') ? mb_strlen($number2) - mb_strpos($number2, '.') - 1 : 0; return (float) round($modulus, max($decimals1, $decimals2)); } }