Completed
Pull Request — master (#234)
by jelmer
05:16
created

UniqueDataTransferObject::validatedBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\Validator;
4
5
use Symfony\Component\Validator\Constraint;
6
7
/**
8
 * Constraint for the Unique Entity validator.
9
 *
10
 * @Annotation
11
 * @Target({"CLASS", "ANNOTATION"})
12
 */
13
class UniqueDataTransferObject extends Constraint
14
{
15
    const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
16
17
    public $message = 'This value is already used.';
18
    public $service = 'unique_data_transfer_object';
19
    public $em = null;
20
    public $entityClass = null;
21
    public $repositoryMethod = 'findBy';
22
    public $fields = array();
23
    public $errorPath = null;
24
    public $ignoreNull = true;
25
26
    protected static $errorNames = array(
27
        self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
28
    );
29
30
    public function getRequiredOptions()
31
    {
32
        return array('fields');
33
    }
34
35
    /**
36
     * The validator must be defined as a service with this name.
37
     *
38
     * @return string
39
     */
40
    public function validatedBy()
41
    {
42
        return $this->service;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getTargets()
49
    {
50
        return self::CLASS_CONSTRAINT;
51
    }
52
53
    public function getDefaultOption()
54
    {
55
        return 'fields';
56
    }
57
}
58