ILIAS  release_8 Revision v8.24
06-to-new-object.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21function toNewObject(): bool
22{
23 class SomeOtherClass
24 {
25 private string $firstParameter;
26 private int $secondParameter;
27 private string $thirdParameter;
28
29 public function __construct(
30 string $firstParameter,
31 int $secondParameter,
32 string $thirdParameter
33 ) {
34 $this->firstParameter = $firstParameter;
35 $this->secondParameter = $secondParameter;
36 $this->thirdParameter = $thirdParameter;
37 }
38
39 public function say(): string
40 {
41 return $this->firstParameter;
42 }
43
44 public function getFirstParameter(): string
45 {
46 return $this->firstParameter;
47 }
48
49 public function getSecodParameter(): int
50 {
51 return $this->secondParameter;
52 }
53
54 public function getThirdParameter(): string
55 {
56 return $this->thirdParameter;
57 }
58 }
59
60 global $DIC;
61
62 $refinery = $DIC->refinery();
63
64 $transformation = $refinery->to()->toNew(SomeOtherClass::class);
65
66 $result = $transformation->transform(['firstParameter', 2, 'thirdParameter']);
67
68 return assert('firstParameter' === $result->getFirstParameter());
69}
toNewObject()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery