[BUGFIX] Call initializeObject() after instantiating empty objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Object / Container / Fixtures / Testclasses.php
1 <?php
2 /**
3 * a singleton class
4 */
5 class t3lib_object_tests_singleton implements \TYPO3\CMS\Core\SingletonInterface {
6
7 }
8
9 /**
10 * test class A that depends on B and C
11 */
12 class t3lib_object_tests_a {
13
14 public $b;
15
16 public $c;
17
18 /**
19 * @param \t3lib_object_tests_c $c
20 * @param \t3lib_object_tests_b $b
21 */
22 public function __construct(\t3lib_object_tests_c $c, \t3lib_object_tests_b $b) {
23 $this->b = $b;
24 $this->c = $c;
25 }
26 }
27
28 /**
29 * test class A that depends on B and C and has a third default parameter in constructor
30 */
31 class t3lib_object_tests_amixed_array {
32
33 public $b;
34
35 public $c;
36
37 public $myvalue;
38
39 /**
40 * @param \t3lib_object_tests_b $b
41 * @param \t3lib_object_tests_c $c
42 * @param array $myvalue
43 */
44 public function __construct(\t3lib_object_tests_b $b, \t3lib_object_tests_c $c, array $myvalue = array('some' => 'default')) {
45 $this->b = $b;
46 $this->c = $c;
47 $this->myvalue = $myvalue;
48 }
49 }
50
51 /**
52 * test class A that depends on B and C and has a third default parameter in constructor that defaults to NULL
53 */
54 class t3lib_object_tests_amixed_null {
55
56 public $b;
57
58 public $c;
59
60 public $myvalue;
61
62 /**
63 * @param \t3lib_object_tests_b $b
64 * @param \t3lib_object_tests_c $c
65 * @param mixed $myvalue
66 */
67 public function __construct(\t3lib_object_tests_b $b, \t3lib_object_tests_c $c, $myvalue = NULL) {
68 $this->b = $b;
69 $this->c = $c;
70 $this->myvalue = $myvalue;
71 }
72 }
73
74 /**
75 * test class A that depends on B and C and has a third default parameter in constructor
76 */
77 class t3lib_object_tests_amixed_array_singleton implements \TYPO3\CMS\Core\SingletonInterface {
78
79 public $b;
80
81 public $c;
82
83 public $myvalue;
84
85 /**
86 * @param \t3lib_object_tests_b $b
87 * @param \t3lib_object_tests_c $c
88 * @param array $someDefaultParameter
89 */
90 public function __construct(\t3lib_object_tests_b $b, \t3lib_object_tests_c $c, $someDefaultParameter = array('some' => 'default')) {
91 $this->b = $b;
92 $this->c = $c;
93 $this->myvalue = $someDefaultParameter;
94 }
95 }
96
97 /**
98 * test class B that depends on C
99 */
100 class t3lib_object_tests_b implements \TYPO3\CMS\Core\SingletonInterface {
101
102 public $c;
103
104 /**
105 * @param \t3lib_object_tests_c $c
106 */
107 public function __construct(\t3lib_object_tests_c $c) {
108 $this->c = $c;
109 }
110 }
111
112 /**
113 * test class C without dependencys
114 */
115 class t3lib_object_tests_c implements \TYPO3\CMS\Core\SingletonInterface {
116
117 }
118
119 /**
120 * test class B-Child that extends Class B (therfore depends also on Class C)
121 */
122 class t3lib_object_tests_b_child extends \t3lib_object_tests_b {
123
124 }
125
126 /**
127
128 */
129 interface t3lib_object_tests_someinterface extends \TYPO3\CMS\Core\SingletonInterface {
130
131 }
132
133 /**
134 * Test class D implementing Serializable
135 */
136 class t3lib_object_tests_serializable implements \Serializable {
137 public function serialize() {}
138 public function unserialize($s) {}
139 }
140
141 /**
142 * class which implements a Interface
143 */
144 class t3lib_object_tests_someimplementation implements \t3lib_object_tests_someinterface {
145
146 }
147
148 /**
149 * test class B-Child that extends Class B (therfore depends also on Class C)
150 */
151 class t3lib_object_tests_b_child_someimplementation extends \t3lib_object_tests_b implements \t3lib_object_tests_someinterface {
152
153 }
154
155 /**
156 * class which depends on a Interface
157 */
158 class t3lib_object_tests_needsinterface {
159
160 /**
161 * @param \t3lib_object_tests_someinterface $i
162 */
163 public function __construct(\t3lib_object_tests_someinterface $i) {
164 $this->dependency = $i;
165 }
166 }
167
168 /**
169 * Prototype classes that depend on each other
170 */
171 class t3lib_object_tests_cyclic1 {
172
173 /**
174 * @param \t3lib_object_tests_cyclic2 $c
175 */
176 public function __construct(\t3lib_object_tests_cyclic2 $c) {
177 }
178 }
179
180 /**
181
182 */
183 class t3lib_object_tests_cyclic2 {
184
185 /**
186 * @param \t3lib_object_tests_cyclic1 $c
187 */
188 public function __construct(\t3lib_object_tests_cyclic1 $c) {
189 }
190 }
191
192 /**
193
194 */
195 class t3lib_object_tests_cyclic1WithSetterDependency {
196
197 /**
198 * @param \t3lib_object_tests_cyclic2WithSetterDependency $c
199 */
200 public function injectFoo(\t3lib_object_tests_cyclic2WithSetterDependency $c) {
201 }
202 }
203
204 /**
205
206 */
207 class t3lib_object_tests_cyclic2WithSetterDependency {
208
209 /**
210 * @param \t3lib_object_tests_cyclic1WithSetterDependency $c
211 */
212 public function injectFoo(\t3lib_object_tests_cyclic1WithSetterDependency $c) {
213 }
214 }
215
216 /**
217 * class which has setter injections defined
218 */
219 class t3lib_object_tests_injectmethods {
220
221 public $b;
222
223 public $bchild;
224
225 /**
226 * @param \t3lib_object_tests_b $o
227 */
228 public function injectClassB(\t3lib_object_tests_b $o) {
229 $this->b = $o;
230 }
231
232 /**
233 * @inject
234 * @param \t3lib_object_tests_b_child $o
235 */
236 public function setClassBChild(\t3lib_object_tests_b_child $o) {
237 $this->bchild = $o;
238 }
239 }
240
241 /**
242 * class which needs extenson settings injected
243 */
244 class t3lib_object_tests_injectsettings {
245
246 public $settings;
247
248 /**
249 * @param array $settings
250 */
251 public function injectExtensionSettings(array $settings) {
252 $this->settings = $settings;
253 }
254 }
255
256 /**
257
258 */
259 class t3lib_object_tests_resolveablecyclic1 implements \TYPO3\CMS\Core\SingletonInterface {
260
261 public $o2;
262
263 /**
264 * @param \t3lib_object_tests_resolveablecyclic2 $cyclic2
265 */
266 public function __construct(\t3lib_object_tests_resolveablecyclic2 $cyclic2) {
267 $this->o2 = $cyclic2;
268 }
269 }
270
271 /**
272
273 */
274 class t3lib_object_tests_resolveablecyclic2 implements \TYPO3\CMS\Core\SingletonInterface {
275
276 public $o1;
277
278 public $o3;
279
280 /**
281 * @param \t3lib_object_tests_resolveablecyclic1 $cyclic1
282 */
283 public function injectCyclic1(\t3lib_object_tests_resolveablecyclic1 $cyclic1) {
284 $this->o1 = $cyclic1;
285 }
286
287 /**
288 * @param \t3lib_object_tests_resolveablecyclic3 $cyclic3
289 */
290 public function injectCyclic3(\t3lib_object_tests_resolveablecyclic3 $cyclic3) {
291 $this->o3 = $cyclic3;
292 }
293 }
294
295 /**
296
297 */
298 class t3lib_object_tests_resolveablecyclic3 implements \TYPO3\CMS\Core\SingletonInterface {
299
300 public $o1;
301
302 /**
303 * @param \t3lib_object_tests_resolveablecyclic1 $cyclic1
304 */
305 public function injectCyclic1(\t3lib_object_tests_resolveablecyclic1 $cyclic1) {
306 $this->o1 = $cyclic1;
307 }
308 }
309
310 /**
311
312 */
313 class t3lib_object_tests_class_with_injectsettings {
314
315 /**
316 * @param \t3lib_object_tests_resolveablecyclic1 $c1
317 */
318 public function injectFoo(\t3lib_object_tests_resolveablecyclic1 $c1) {
319 }
320
321 /**
322 * @param \t3lib_object_tests_resolveablecyclic1 $c1
323 */
324 public function injectingFoo(\t3lib_object_tests_resolveablecyclic1 $c1) {
325
326 }
327
328 /**
329 * @param array $settings
330 */
331 public function injectSettings(array $settings) {
332 }
333 }
334
335 /*
336 * a Singleton requires a Prototype for Injection -> allowed, autowiring active, but in development context we write a log message, as it is bad practice and most likely points to some logic error.
337 If a Singleton requires a Singleton for Injection -> allowed, autowiring active
338 If a Prototype requires a Prototype for Injection -> allowed, autowiring active
339 If a Prototype requires a Singleton for Injection -> allowed, autowiring active
340 */
341 /**
342
343 */
344 class t3lib_object_singleton implements \TYPO3\CMS\Core\SingletonInterface {
345
346 }
347
348 /**
349
350 */
351 class t3lib_object_prototype {
352
353 }
354
355 /**
356
357 */
358 class t3lib_object_singletonNeedsPrototype implements \TYPO3\CMS\Core\SingletonInterface {
359
360 /**
361 * @var \t3lib_object_prototype
362 */
363 public $dependency;
364
365 /**
366 * @param \t3lib_object_prototype $dependency
367 */
368 public function injectDependency(\t3lib_object_prototype $dependency) {
369 $this->dependency = $dependency;
370 }
371 }
372
373 /**
374
375 */
376 class t3lib_object_singletonNeedsSingleton implements \TYPO3\CMS\Core\SingletonInterface {
377
378 /**
379 * @var \t3lib_object_singleton
380 */
381 public $dependency;
382
383 /**
384 * @param \t3lib_object_singleton $dependency
385 */
386 public function injectDependency(\t3lib_object_singleton $dependency) {
387 $this->dependency = $dependency;
388 }
389 }
390
391 /**
392
393 */
394 class t3lib_object_prototypeNeedsPrototype {
395
396 /**
397 * @var \t3lib_object_prototype
398 */
399 public $dependency;
400
401 /**
402 * @param \t3lib_object_prototype $dependency
403 */
404 public function injectDependency(\t3lib_object_prototype $dependency) {
405 $this->dependency = $dependency;
406 }
407 }
408
409 /**
410
411 */
412 class t3lib_object_prototypeNeedsSingleton {
413
414 /**
415 * @var \t3lib_object_singleton
416 */
417 public $dependency;
418
419 /**
420 * @param \t3lib_object_singleton $dependency
421 */
422 public function injectDependency(\t3lib_object_singleton $dependency) {
423 $this->dependency = $dependency;
424 }
425 }
426
427 /**
428
429 */
430 class t3lib_object_singletonNeedsPrototypeInConstructor implements \TYPO3\CMS\Core\SingletonInterface {
431
432 /**
433 * @param \t3lib_object_prototype $dependency
434 */
435 public function __construct(\t3lib_object_prototype $dependency) {
436 $this->dependency = $dependency;
437 }
438 }
439
440 /**
441
442 */
443 class t3lib_object_singletonNeedsSingletonInConstructor implements \TYPO3\CMS\Core\SingletonInterface {
444
445 /**
446 * @param \t3lib_object_singleton $dependency
447 */
448 public function __construct(\t3lib_object_singleton $dependency) {
449 $this->dependency = $dependency;
450 }
451 }
452
453 /**
454
455 */
456 class t3lib_object_prototypeNeedsPrototypeInConstructor {
457
458 /**
459 * @param \t3lib_object_prototype $dependency
460 */
461 public function __construct(\t3lib_object_prototype $dependency) {
462 $this->dependency = $dependency;
463 }
464 }
465
466 /**
467
468 */
469 class t3lib_object_prototypeNeedsSingletonInConstructor {
470
471 /**
472 * @param \t3lib_object_singleton $dependency
473 */
474 public function __construct(\t3lib_object_singleton $dependency) {
475 $this->dependency = $dependency;
476 }
477
478 }
479
480 /**
481 * Class that needs initialization after instantiation
482 */
483 class t3lib_object_tests_initializable {
484 /**
485 * @var bool
486 */
487 protected $initialized = FALSE;
488
489 public function initializeObject() {
490 $this->initialized = TRUE;
491 }
492
493 /**
494 * @return boolean
495 */
496 public function isInitialized() {
497 return $this->initialized;
498 }
499 }