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 / StringConstraint.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
StringConstraint.php
61 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 StringConstraint Constraints, validates an string against a given schema
16 *
17 * @author Robert Schönthal <seroscho@googlemail.com>
18 * @author Bruno Prieto Reis <bruno.p.reis@gmail.com>
19 */
20 class StringConstraint extends Constraint
21 {
22 /**
23 * {@inheritdoc}
24 */
25 public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
26 {
27 // Verify maxLength
28 if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) {
29 $this->addError($path, 'Must be at most ' . $schema->maxLength . ' characters long', 'maxLength', array(
30 'maxLength' => $schema->maxLength,
31 ));
32 }
33
34 //verify minLength
35 if (isset($schema->minLength) && $this->strlen($element) < $schema->minLength) {
36 $this->addError($path, 'Must be at least ' . $schema->minLength . ' characters long', 'minLength', array(
37 'minLength' => $schema->minLength,
38 ));
39 }
40
41 // Verify a regex pattern
42 if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#u', $element)) {
43 $this->addError($path, 'Does not match the regex pattern ' . $schema->pattern, 'pattern', array(
44 'pattern' => $schema->pattern,
45 ));
46 }
47
48 $this->checkFormat($element, $schema, $path, $i);
49 }
50
51 private function strlen($string)
52 {
53 if (extension_loaded('mbstring')) {
54 return mb_strlen($string, mb_detect_encoding($string));
55 }
56
57 // mbstring is present on all test platforms, so strlen() can be ignored for coverage
58 return strlen($string); // @codeCoverageIgnore
59 }
60 }
61