Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/validator/Constraints/ImageValidator.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
44 return; | 44 return; |
45 } | 45 } |
46 | 46 |
47 if (null === $constraint->minWidth && null === $constraint->maxWidth | 47 if (null === $constraint->minWidth && null === $constraint->maxWidth |
48 && null === $constraint->minHeight && null === $constraint->maxHeight | 48 && null === $constraint->minHeight && null === $constraint->maxHeight |
49 && null === $constraint->minPixels && null === $constraint->maxPixels | |
49 && null === $constraint->minRatio && null === $constraint->maxRatio | 50 && null === $constraint->minRatio && null === $constraint->maxRatio |
50 && $constraint->allowSquare && $constraint->allowLandscape && $constraint->allowPortrait | 51 && $constraint->allowSquare && $constraint->allowLandscape && $constraint->allowPortrait |
51 && !$constraint->detectCorrupted) { | 52 && !$constraint->detectCorrupted) { |
52 return; | 53 return; |
53 } | 54 } |
54 | 55 |
55 $size = @getimagesize($value); | 56 $size = @getimagesize($value); |
56 | 57 |
57 if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) { | 58 if (empty($size) || (0 === $size[0]) || (0 === $size[1])) { |
58 $this->context->buildViolation($constraint->sizeNotDetectedMessage) | 59 $this->context->buildViolation($constraint->sizeNotDetectedMessage) |
59 ->setCode(Image::SIZE_NOT_DETECTED_ERROR) | 60 ->setCode(Image::SIZE_NOT_DETECTED_ERROR) |
60 ->addViolation(); | 61 ->addViolation(); |
61 | 62 |
62 return; | 63 return; |
65 $width = $size[0]; | 66 $width = $size[0]; |
66 $height = $size[1]; | 67 $height = $size[1]; |
67 | 68 |
68 if ($constraint->minWidth) { | 69 if ($constraint->minWidth) { |
69 if (!ctype_digit((string) $constraint->minWidth)) { | 70 if (!ctype_digit((string) $constraint->minWidth)) { |
70 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width', $constraint->minWidth)); | 71 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width.', $constraint->minWidth)); |
71 } | 72 } |
72 | 73 |
73 if ($width < $constraint->minWidth) { | 74 if ($width < $constraint->minWidth) { |
74 $this->context->buildViolation($constraint->minWidthMessage) | 75 $this->context->buildViolation($constraint->minWidthMessage) |
75 ->setParameter('{{ width }}', $width) | 76 ->setParameter('{{ width }}', $width) |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 if ($constraint->maxWidth) { | 85 if ($constraint->maxWidth) { |
85 if (!ctype_digit((string) $constraint->maxWidth)) { | 86 if (!ctype_digit((string) $constraint->maxWidth)) { |
86 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width', $constraint->maxWidth)); | 87 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width.', $constraint->maxWidth)); |
87 } | 88 } |
88 | 89 |
89 if ($width > $constraint->maxWidth) { | 90 if ($width > $constraint->maxWidth) { |
90 $this->context->buildViolation($constraint->maxWidthMessage) | 91 $this->context->buildViolation($constraint->maxWidthMessage) |
91 ->setParameter('{{ width }}', $width) | 92 ->setParameter('{{ width }}', $width) |
121 if ($height > $constraint->maxHeight) { | 122 if ($height > $constraint->maxHeight) { |
122 $this->context->buildViolation($constraint->maxHeightMessage) | 123 $this->context->buildViolation($constraint->maxHeightMessage) |
123 ->setParameter('{{ height }}', $height) | 124 ->setParameter('{{ height }}', $height) |
124 ->setParameter('{{ max_height }}', $constraint->maxHeight) | 125 ->setParameter('{{ max_height }}', $constraint->maxHeight) |
125 ->setCode(Image::TOO_HIGH_ERROR) | 126 ->setCode(Image::TOO_HIGH_ERROR) |
127 ->addViolation(); | |
128 } | |
129 } | |
130 | |
131 $pixels = $width * $height; | |
132 | |
133 if (null !== $constraint->minPixels) { | |
134 if (!ctype_digit((string) $constraint->minPixels)) { | |
135 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum amount of pixels', $constraint->minPixels)); | |
136 } | |
137 | |
138 if ($pixels < $constraint->minPixels) { | |
139 $this->context->buildViolation($constraint->minPixelsMessage) | |
140 ->setParameter('{{ pixels }}', $pixels) | |
141 ->setParameter('{{ min_pixels }}', $constraint->minPixels) | |
142 ->setParameter('{{ height }}', $height) | |
143 ->setParameter('{{ width }}', $width) | |
144 ->setCode(Image::TOO_FEW_PIXEL_ERROR) | |
145 ->addViolation(); | |
146 } | |
147 } | |
148 | |
149 if (null !== $constraint->maxPixels) { | |
150 if (!ctype_digit((string) $constraint->maxPixels)) { | |
151 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum amount of pixels', $constraint->maxPixels)); | |
152 } | |
153 | |
154 if ($pixels > $constraint->maxPixels) { | |
155 $this->context->buildViolation($constraint->maxPixelsMessage) | |
156 ->setParameter('{{ pixels }}', $pixels) | |
157 ->setParameter('{{ max_pixels }}', $constraint->maxPixels) | |
158 ->setParameter('{{ height }}', $height) | |
159 ->setParameter('{{ width }}', $width) | |
160 ->setCode(Image::TOO_MANY_PIXEL_ERROR) | |
126 ->addViolation(); | 161 ->addViolation(); |
127 } | 162 } |
128 } | 163 } |
129 | 164 |
130 $ratio = round($width / $height, 2); | 165 $ratio = round($width / $height, 2); |