Completed
Push — master ( bead68...29f6d6 )
by Artem
17:01
created

VichSerializableField::getField()   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
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the FreshVichUploaderSerializationBundle
4
 *
5
 * (c) Artem Genvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\VichUploaderSerializationBundle\Annotation;
12
13
use Doctrine\ORM\Mapping\Annotation;
14
15
/**
16
 * VichSerializableField
17
 *
18
 * @Annotation
19
 * @Target({"PROPERTY", "METHOD"})
20
 *
21
 * @author Artem Genvald <[email protected]>
22
 */
23
final class VichSerializableField implements Annotation
24
{
25
    /**
26
     * @var string $field Field
27
     */
28
    private $field;
29
30
    /**
31
     * @var bool $includeHost Include host
32
     */
33
    private $includeHost = true;
34
35
    /**
36
     * Constructor
37
     *
38
     * @param array $options Options
39
     *
40
     * @throws \Exception
41
     */
42
    public function __construct(array $options)
43
    {
44
        if (!isset($options['value']) && !isset($options['field'])) {
45
            throw new \LogicException(sprintf('Either "value" or "field" option must be set.'));
46
        }
47
48
        if (isset($options['value'])) {
49
            if (!is_string($options['value'])) {
50
                throw new \InvalidArgumentException(sprintf('Option "value" must be a string.'));
51
            }
52
            $this->setField($options['value']);
53
        } elseif (isset($options['field'])) {
54
            if (!is_string($options['field'])) {
55
                throw new \InvalidArgumentException(sprintf('Option "field" must be a string.'));
56
            }
57
            $this->setField($options['field']);
58
        }
59
60
        if (isset($options['includeHost'])) {
61
            if (!is_bool($options['includeHost'])) {
62
                throw new \InvalidArgumentException(sprintf('Option "includeHost" must be a boolean.'));
63
            }
64
            $this->setIncludeHost($options['includeHost']);
65
        }
66
    }
67
68
    /**
69
     * Get field
70
     *
71
     * @return string Field
72
     */
73
    public function getField()
74
    {
75
        return $this->field;
76
    }
77
78
    /**
79
     * Set field
80
     *
81
     * @param string $field Field
82
     *
83
     * @return $this
84
     */
85
    public function setField($field)
86
    {
87
        $this->field = $field;
88
89
        return $this;
90
    }
91
92
    /**
93
     * Get include host
94
     *
95
     * @return bool Include host
96
     */
97
    public function isIncludeHost()
98
    {
99
        return $this->includeHost;
100
    }
101
102
    /**
103
     * Set include host
104
     *
105
     * @param bool $includeHost Include host
106
     *
107
     * @return $this
108
     */
109
    public function setIncludeHost($includeHost)
110
    {
111
        $this->includeHost = $includeHost;
112
113
        return $this;
114
    }
115
}
116