Completed
Push — master ( fde720...45a366 )
by Alexey
38:07
created

Mapper::setTransforms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace PhMap;
4
5
/**
6
 * Class Mapper
7
 * @abstract
8
 * @package PhMap
9
 */
10
abstract class Mapper implements MapperInterface {
11
12
    /**
13
     * @const integer
14
     */
15
    const MEMORY_ANNOTATION_ADAPTER = 1;
16
17
    /**
18
     * @const integer
19
     */
20
    const FILES_ANNOTATION_ADAPTER = 2;
21
22
    /**
23
     * @const integer
24
     */
25
    const APC_ANNOTATION_ADAPTER = 3;
26
27
    /**
28
     * @const integer
29
     */
30
    const X_CACHE_ANNOTATION_ADAPTER = 4;
31
32
    /**
33
     * @var string
34
     */
35
    private $outputClass;
36
37
    /**
38
     * @var object
39
     */
40
    private $outputObject;
41
42
    /**
43
     * @var integer
44
     */
45
    private $annotationAdapterType;
46
47
    /**
48
     * @var Transforms
49
     */
50
    private $transforms;
51
52
    /**
53
     * @var boolean
54
     */
55
    private $validation;
56
57
    /**
58
     * @var array
59
     */
60
    private $skipAttributes;
61
62
    /**
63
     * @return string
64
     */
65
    public function getOutputClass() {
66
        return $this->outputClass;
67
    }
68
69
    /**
70
     * @param string $class
71
     * @return $this
72
     */
73
    protected function setOutputClassInternal($class) {
74
        $this->outputClass = $class;
75
        $this->outputObject = new $class();
76
77
        return $this;
78
    }
79
80
    /**
81
     * @return object
82
     */
83
    public function getOutputObject() {
84
        return $this->outputObject;
85
    }
86
87
    /**
88
     * @param object $object
89
     * @return $this
90
     */
91
    protected function setOutputObjectInternal($object) {
92
        $this->outputObject = $object;
93
        $this->outputClass = get_class($object);
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return integer
100
     */
101
    public function getAnnotationAdapterType() {
102
        return $this->annotationAdapterType;
103
    }
104
105
    /**
106
     * @param integer $adapter
107
     * @return $this
108
     */
109
    public function setAnnotationAdapterType($adapter) {
110
        $this->annotationAdapterType = $adapter;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @return Transforms
117
     */
118
    public function getTransforms() {
119
        return $this->transforms;
120
    }
121
122
    /**
123
     * @param Transforms|null $transforms
124
     * @return $this
125
     */
126
    public function setTransforms(Transforms $transforms = null) {
127
        $this->transforms = $transforms;
128
129
        return $this;
130
    }
131
132
    /**
133
     * @return boolean
134
     */
135
    public function hasValidation() {
136
        return $this->validation;
137
    }
138
139
    /**
140
     * @return $this
141
     */
142
    public function disableValidation() {
143
        $this->validation = false;
144
145
        return $this;
146
    }
147
148
    /**
149
     * @return $this
150
     */
151
    public function enableValidation() {
152
        $this->validation = true;
153
154
        return $this;
155
    }
156
157
    /**
158
     * @param boolean $validation
159
     * @return $this
160
     */
161
    public function setValidation($validation) {
162
        $this->validation = $validation;
163
164
        return $this;
165
    }
166
167
    /**
168
     * @param array $attributes
169
     * @return $this
170
     */
171
    public function setSkipAttributes(array $attributes = []) {
172
        $this->skipAttributes = $attributes;
173
174
        return $this;
175
    }
176
177
    /**
178
     * @return array
179
     */
180
    public function getSkipAttributes() {
181
        return $this->skipAttributes;
182
    }
183
184
    /**
185
     * @param string|object $outputClassOrObject
186
     * @param integer $adapter
187
     */
188
    public function __construct($outputClassOrObject, $adapter = self::MEMORY_ANNOTATION_ADAPTER) {
189
        $this->setOutputClassOrObject($outputClassOrObject)
190
            ->setAnnotationAdapterType($adapter)
191
            ->setValidation(true)
192
            ->setSkipAttributes();
193
    }
194
195
    /**
196
     * @param string|object $outputClassOrObject
197
     * @return $this
198
     */
199
    private function setOutputClassOrObject($outputClassOrObject) {
200
        if (is_object($outputClassOrObject)) {
201
            $this->setOutputObjectInternal($outputClassOrObject);
202
        } else {
203
            $this->setOutputClassInternal($outputClassOrObject);
204
        }
205
206
        return $this;
207
    }
208
209
}