PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / vendor / justinrainbow / json-schema / src / JsonSchema / Constraints / EnumConstraint.php
secure-custom-fields / vendor / justinrainbow / json-schema / src / JsonSchema / Constraints Last commit date
TypeCheck 8 months ago BaseConstraint.php 8 months ago CollectionConstraint.php 8 months ago Constraint.php 8 months ago ConstraintInterface.php 8 months ago EnumConstraint.php 8 months ago Factory.php 8 months ago FormatConstraint.php 8 months ago NumberConstraint.php 8 months ago ObjectConstraint.php 8 months ago SchemaConstraint.php 8 months ago StringConstraint.php 8 months ago TypeConstraint.php 8 months ago UndefinedConstraint.php 8 months ago
EnumConstraint.php
55 lines
1 <?php
2
3 /*
4 * This file is part of the JsonSchema package.
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 */
9
10 namespace JsonSchema\Constraints;
11
12 use JsonSchema\Entity\JsonPointer;
13
14 /**
15 * The EnumConstraint Constraints, validates an element against a given set of possibilities
16 *
17 * @author Robert Schönthal <seroscho@googlemail.com>
18 * @author Bruno Prieto Reis <bruno.p.reis@gmail.com>
19 */
20 class EnumConstraint extends Constraint
21 {
22 /**
23 * {@inheritdoc}
24 */
25 public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
26 {
27 // Only validate enum if the attribute exists
28 if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
29 return;
30 }
31 $type = gettype($element);
32
33 foreach ($schema->enum as $enum) {
34 $enumType = gettype($enum);
35 if ($this->factory->getConfig(self::CHECK_MODE_TYPE_CAST) && $type == 'array' && $enumType == 'object') {
36 if ((object) $element == $enum) {
37 return;
38 }
39 }
40
41 if ($type === gettype($enum)) {
42 if ($type == 'object') {
43 if ($element == $enum) {
44 return;
45 }
46 } elseif ($element === $enum) {
47 return;
48 }
49 }
50 }
51
52 $this->addError($path, 'Does not have a value in the enumeration ' . json_encode($schema->enum), 'enum', array('enum' => $schema->enum));
53 }
54 }
55