ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
06-to-new-object.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21if (!function_exists('toNewObject')) {
22 function toNewObject(): bool
23 {
24 class SomeOtherClass
25 {
26 private string $firstParameter;
27 private int $secondParameter;
28 private string $thirdParameter;
29
30 public function __construct(
31 string $firstParameter,
32 int $secondParameter,
33 string $thirdParameter
34 ) {
35 $this->firstParameter = $firstParameter;
36 $this->secondParameter = $secondParameter;
37 $this->thirdParameter = $thirdParameter;
38 }
39
40 public function say(): string
41 {
42 return $this->firstParameter;
43 }
44
45 public function getFirstParameter(): string
46 {
47 return $this->firstParameter;
48 }
49
50 public function getSecodParameter(): int
51 {
52 return $this->secondParameter;
53 }
54
55 public function getThirdParameter(): string
56 {
57 return $this->thirdParameter;
58 }
59 }
60
61 global $DIC;
62
63 $refinery = $DIC->refinery();
64
65 $transformation = $refinery->to()->toNew(SomeOtherClass::class);
66
67 $result = $transformation->transform(['firstParameter', 2, 'thirdParameter']);
68
69 return assert('firstParameter' === $result->getFirstParameter());
70 }
71}
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26