| 1 | <?php |
||
| 20 | abstract class AbstractValidator |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Configure the validator |
||
| 24 | * |
||
| 25 | * @param OptionsResolver $resolver |
||
| 26 | */ |
||
| 27 | protected function configureOptions(OptionsResolver $resolver) |
||
| 28 | { |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Apply the validator |
||
| 33 | * |
||
| 34 | * @param mixed $value |
||
| 35 | * @param array $configuration |
||
| 36 | * |
||
| 37 | * @throws \Jb\Bundle\FileUploaderBundle\Exception\ValidationException |
||
| 38 | */ |
||
| 39 | public function applyValidator($value, array $configuration) |
||
| 40 | { |
||
| 41 | // Validate configuration |
||
| 42 | $resolver = new OptionsResolver(); |
||
| 43 | $this->configureOptions($resolver); |
||
| 44 | $configuration = $resolver->resolve($configuration); |
||
| 45 | |||
| 46 | $this->validate($value, $configuration); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Extract the value used in the validator |
||
| 51 | * |
||
| 52 | * @param mixed $value |
||
| 53 | * @return mixed|string |
||
| 54 | */ |
||
| 55 | protected function formatValue($value) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Validate a value |
||
| 66 | * |
||
| 67 | * @param mixed $value |
||
| 68 | * @param array $configuration |
||
| 69 | * |
||
| 70 | * @throws \Jb\Bundle\FileUploaderBundle\Exception\ValidationException |
||
| 71 | */ |
||
| 72 | abstract protected function validate($value, array $configuration); |
||
| 73 | } |
||
| 74 |