ValidatorManager::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
1
<?php
2
3
/**
4
 * Copyright 2014 Jonathan Bouzekri. All rights reserved.
5
 *
6
 * @copyright Copyright 2014 Jonathan Bouzekri <[email protected]>
7
 * @license https://github.com/jbouzekri/FileUploaderBundle/blob/master/LICENSE
8
 * @link https://github.com/jbouzekri/FileUploaderBundle
9
 */
10
11
namespace Jb\Bundle\FileUploaderBundle\Service;
12
13
use Jb\Bundle\FileUploaderBundle\Service\ValidatorChain;
14
use Jb\Bundle\FileUploaderBundle\Service\EndpointConfiguration;
15
16
/**
17
 * ValidatorManager
18
 *
19
 * @author jobou
20
 */
21
class ValidatorManager
22
{
23
    /**
24
     * @var \Jb\Bundle\FileUploaderBundle\Service\ValidatorChain
25
     */
26
    protected $validators;
27
28
    /**
29
     * @var \Jb\Bundle\FileUploaderBundle\Service\EndpointConfiguration
30
     */
31
    protected $configuration;
32
33
    /**
34
     * Constructor
35
     *
36
     * @param \Jb\Bundle\FileUploaderBundle\Service\ValidatorChain $validators
37
     * @param \Jb\Bundle\FileUploaderBundle\Service\EndpointConfiguration $configuration
38
     */
39
    public function __construct(ValidatorChain $validators, EndpointConfiguration $configuration)
40
    {
41
        $this->validators = $validators;
42
        $this->configuration = $configuration;
43
    }
44
45
    /**
46
     * Validate by applying validators from validator chain
47
     *
48
     * @param string $endpoint
49
     * @param mixed $value
50
     * @param string $configKey
51
     *
52
     * @throws \Jb\Bundle\FileUploaderBundle\Exception\ValidationException
53
     */
54
    public function validate($endpoint, $value, $configKey = 'upload_validators')
55
    {
56
        $validationConfiguration = $this->configuration->getValue($endpoint, $configKey);
57
58
        foreach ((array) $validationConfiguration as $validationType => $config) {
59
            $validator = $this->validators->getValidator($validationType);
60
            $validator->applyValidator($value, $config);
61
        }
62
    }
63
}
64