ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
06-to-new-object.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
7function toNewObject()
8{
9 class SomeClass
10 {
11 private $firstParameter;
12 private $secondParameter;
13 private $thirdParameter;
14
15 public function __construct(
16 string $firstParameter,
17 int $secondParameter,
18 string $thirdParameter
19 ) {
20 $this->firstParameter = $firstParameter;
21 $this->secondParameter = $secondParameter;
22 $this->thirdParameter = $thirdParameter;
23 }
24
25 public function say()
26 {
27 return $this->firstParameter;
28 }
29 }
30
31 global $DIC;
32
33 $refinery = $DIC->refinery();
34
35 $transformation = $refinery->to()->toNew(
36 'SomeClass'
37 );
38
39 $result = $transformation->transform(array('firstParameter', 2, 'thirdParameter'));
40
41 return assert('firstParameter' === $result->say());
42}
toNewObject()
$result
An exception for terminatinating execution or to throw for unit testing.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46