ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
06-to-new-object.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 function 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()
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
Refinery Factory $refinery