Passed
Pull Request — master (#176)
by
unknown
02:38
created

onDaoFactorySetterGenerated()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 3
nop 4
1
<?php
2
3
4
namespace TheCodingMachine\TDBM\Utils;
5
6
use Doctrine\DBAL\Schema\Index;
7
use TheCodingMachine\TDBM\ConfigurationInterface;
8
use Zend\Code\Generator\ClassGenerator;
9
use Zend\Code\Generator\FileGenerator;
10
use Zend\Code\Generator\MethodGenerator;
11
12
class CodeGeneratorEventDispatcher implements CodeGeneratorListenerInterface
13
{
14
    /**
15
     * @var CodeGeneratorListenerInterface[]
16
     */
17
    private $listeners;
18
19
    /**
20
     * @param CodeGeneratorListenerInterface[] $listeners
21
     */
22
    public function __construct(array $listeners)
23
    {
24
        $this->listeners = $listeners;
25
    }
26
27
    public function onBaseBeanGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator
28
    {
29
        foreach ($this->listeners as $listener) {
30
            $fileGenerator = $listener->onBaseBeanGenerated($fileGenerator, $beanDescriptor, $configuration);
31
            if ($fileGenerator === null) {
32
                break;
33
            }
34
        }
35
        return $fileGenerator;
36
    }
37
38
    public function onBaseBeanConstructorGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
39
    {
40
        foreach ($this->listeners as $listener) {
41
            $methodGenerator = $listener->onBaseBeanConstructorGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
42
            if ($methodGenerator === null) {
43
                break;
44
            }
45
        }
46
        return $methodGenerator;
47
    }
48
49
    /**
50
     * Called when a column is turned into a getter/setter.
51
     *
52
     * @return array<int, ?MethodGenerator> Returns an array of 2 methods to be generated for this property. You MUST return the getter (first argument) and setter (second argument) as part of these methods (if you want them to appear in the bean). Return null if you want to delete them.
53
     */
54
    public function onBaseBeanPropertyGenerated(?MethodGenerator $getter, ?MethodGenerator $setter, AbstractBeanPropertyDescriptor $propertyDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): array
55
    {
56
        foreach ($this->listeners as $listener) {
57
            [$getter, $setter] = $listener->onBaseBeanPropertyGenerated($getter, $setter, $propertyDescriptor, $beanDescriptor, $configuration, $classGenerator);
58
            if ($getter === null && $setter === null) {
59
                break;
60
            }
61
        }
62
        return [$getter, $setter];
63
    }
64
65
    /**
66
     * Called when a foreign key from another table is turned into a "get many objects" method.
67
     *
68
     * @param MethodGenerator $getter
69
     * @param DirectForeignKeyMethodDescriptor $directForeignKeyMethodDescriptor
70
     * @param BeanDescriptor $beanDescriptor
71
     * @param ConfigurationInterface $configuration
72
     * @param ClassGenerator $classGenerator
73
     * @return MethodGenerator|null
74
     */
75
    public function onBaseBeanOneToManyGenerated(MethodGenerator $getter, DirectForeignKeyMethodDescriptor $directForeignKeyMethodDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
76
    {
77
        foreach ($this->listeners as $listener) {
78
            $getter = $listener->onBaseBeanOneToManyGenerated($getter, $directForeignKeyMethodDescriptor, $beanDescriptor, $configuration, $classGenerator);
79
            if ($getter === null) {
80
                break;
81
            }
82
        }
83
        return $getter;
84
    }
85
86
    /**
87
     * Called when a pivot table is turned into get/has/add/set/remove methods.
88
     *
89
     * @return array<int, ?MethodGenerator> Returns an array of methods to be generated for this property. You MUST return the get/has/add/set/remove methods as part of these methods (if you want them to appear in the bean).
90
     */
91
    public function onBaseBeanManyToManyGenerated(?MethodGenerator $getter, ?MethodGenerator $adder, ?MethodGenerator $remover, ?MethodGenerator $hasser, ?MethodGenerator $setter, PivotTableMethodsDescriptor $pivotTableMethodsDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): array
92
    {
93
        foreach ($this->listeners as $listener) {
94
            [$getter, $adder, $remover, $hasser, $setter] = $listener->onBaseBeanManyToManyGenerated($getter, $adder, $remover, $hasser, $setter, $pivotTableMethodsDescriptor, $beanDescriptor, $configuration, $classGenerator);
95
            if ($getter === null && $adder === null && $remover === null && $hasser === null && $setter === null) {
96
                break;
97
            }
98
        }
99
        return [$getter, $adder, $remover, $hasser, $setter];
100
    }
101
102
    public function onBaseBeanJsonSerializeGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
103
    {
104
        foreach ($this->listeners as $listener) {
105
            $methodGenerator = $listener->onBaseBeanJsonSerializeGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
106
            if ($methodGenerator === null) {
107
                break;
108
            }
109
        }
110
        return $methodGenerator;
111
    }
112
113
    public function onBaseBeanCloneGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
114
    {
115
        foreach ($this->listeners as $listener) {
116
            $methodGenerator = $listener->onBaseBeanCloneGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
117
            if ($methodGenerator === null) {
118
                break;
119
            }
120
        }
121
        return $methodGenerator;
122
    }
123
124
    public function onBaseDaoGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator
125
    {
126
        foreach ($this->listeners as $listener) {
127
            $fileGenerator = $listener->onBaseDaoGenerated($fileGenerator, $beanDescriptor, $configuration);
128
            if ($fileGenerator === null) {
129
                break;
130
            }
131
        }
132
        return $fileGenerator;
133
    }
134
135
    public function onBaseDaoConstructorGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
136
    {
137
        foreach ($this->listeners as $listener) {
138
            $methodGenerator = $listener->onBaseDaoConstructorGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
139
            if ($methodGenerator === null) {
140
                break;
141
            }
142
        }
143
        return $methodGenerator;
144
    }
145
146
    public function onBaseDaoSaveGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
147
    {
148
        foreach ($this->listeners as $listener) {
149
            $methodGenerator = $listener->onBaseDaoSaveGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
150
            if ($methodGenerator === null) {
151
                break;
152
            }
153
        }
154
        return $methodGenerator;
155
    }
156
157
    public function onBaseDaoFindAllGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
158
    {
159
        foreach ($this->listeners as $listener) {
160
            $methodGenerator = $listener->onBaseDaoFindAllGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
161
            if ($methodGenerator === null) {
162
                break;
163
            }
164
        }
165
        return $methodGenerator;
166
    }
167
168
    public function onBaseDaoGetByIdGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
169
    {
170
        foreach ($this->listeners as $listener) {
171
            $methodGenerator = $listener->onBaseDaoGetByIdGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
172
            if ($methodGenerator === null) {
173
                break;
174
            }
175
        }
176
        return $methodGenerator;
177
    }
178
179
    public function onBaseDaoDeleteGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
180
    {
181
        foreach ($this->listeners as $listener) {
182
            $methodGenerator = $listener->onBaseDaoDeleteGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
183
            if ($methodGenerator === null) {
184
                break;
185
            }
186
        }
187
        return $methodGenerator;
188
    }
189
190
    public function onBaseDaoFindGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
191
    {
192
        foreach ($this->listeners as $listener) {
193
            $methodGenerator = $listener->onBaseDaoFindGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
194
            if ($methodGenerator === null) {
195
                break;
196
            }
197
        }
198
        return $methodGenerator;
199
    }
200
201
    public function onBaseDaoFindFromSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
202
    {
203
        foreach ($this->listeners as $listener) {
204
            $methodGenerator = $listener->onBaseDaoFindFromSqlGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
205
            if ($methodGenerator === null) {
206
                break;
207
            }
208
        }
209
        return $methodGenerator;
210
    }
211
212
    public function onBaseDaoFindFromRawSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
213
    {
214
        foreach ($this->listeners as $listener) {
215
            $methodGenerator = $listener->onBaseDaoFindFromRawSqlGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
216
            if ($methodGenerator === null) {
217
                break;
218
            }
219
        }
220
        return $methodGenerator;
221
    }
222
223
    public function onBaseDaoFindOneGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
224
    {
225
        foreach ($this->listeners as $listener) {
226
            $methodGenerator = $listener->onBaseDaoFindOneGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
227
            if ($methodGenerator === null) {
228
                break;
229
            }
230
        }
231
        return $methodGenerator;
232
    }
233
234
    public function onBaseDaoFindOneFromSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
235
    {
236
        foreach ($this->listeners as $listener) {
237
            $methodGenerator = $listener->onBaseDaoFindOneFromSqlGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
238
            if ($methodGenerator === null) {
239
                break;
240
            }
241
        }
242
        return $methodGenerator;
243
    }
244
245
    public function onBaseDaoSetDefaultSortGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
246
    {
247
        foreach ($this->listeners as $listener) {
248
            $methodGenerator = $listener->onBaseDaoSetDefaultSortGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
249
            if ($methodGenerator === null) {
250
                break;
251
            }
252
        }
253
        return $methodGenerator;
254
    }
255
256
    public function onBaseDaoFindByIndexGenerated(MethodGenerator $methodGenerator, Index $index, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
257
    {
258
        foreach ($this->listeners as $listener) {
259
            $methodGenerator = $listener->onBaseDaoFindByIndexGenerated($methodGenerator, $index, $beanDescriptor, $configuration, $classGenerator);
260
            if ($methodGenerator === null) {
261
                break;
262
            }
263
        }
264
        return $methodGenerator;
265
    }
266
267
    public function onBaseResultIteratorGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator
268
    {
269
        foreach ($this->listeners as $listener) {
270
            $fileGenerator = $listener->onBaseResultIteratorGenerated($fileGenerator, $beanDescriptor, $configuration);
271
            if ($fileGenerator === null) {
272
                break;
273
            }
274
        }
275
        return $fileGenerator;
276
    }
277
278
    /**
279
     * @param BeanDescriptor[] $beanDescriptors
280
     */
281
    public function onDaoFactoryGenerated(FileGenerator $fileGenerator, array $beanDescriptors, ConfigurationInterface $configuration): ?FileGenerator
282
    {
283
        foreach ($this->listeners as $listener) {
284
            $fileGenerator = $listener->onDaoFactoryGenerated($fileGenerator, $beanDescriptors, $configuration);
285
            if ($fileGenerator === null) {
286
                break;
287
            }
288
        }
289
        return $fileGenerator;
290
    }
291
292
    /**
293
     * @param BeanDescriptor[] $beanDescriptors
294
     */
295
    public function onDaoFactoryConstructorGenerated(MethodGenerator $methodGenerator, array $beanDescriptors, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
296
    {
297
        foreach ($this->listeners as $listener) {
298
            $methodGenerator = $listener->onDaoFactoryConstructorGenerated($methodGenerator, $beanDescriptors, $configuration, $classGenerator);
299
            if ($methodGenerator === null) {
300
                break;
301
            }
302
        }
303
        return $methodGenerator;
304
    }
305
306
    public function onDaoFactoryGetterGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
307
    {
308
        foreach ($this->listeners as $listener) {
309
            $methodGenerator = $listener->onDaoFactoryGetterGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
310
            if ($methodGenerator === null) {
311
                break;
312
            }
313
        }
314
        return $methodGenerator;
315
    }
316
317
    public function onDaoFactorySetterGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
318
    {
319
        foreach ($this->listeners as $listener) {
320
            $methodGenerator = $listener->onDaoFactorySetterGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
321
            if ($methodGenerator === null) {
322
                break;
323
            }
324
        }
325
        return $methodGenerator;
326
    }
327
}
328