|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Netgen\InformationCollection\API\Value; |
|
6
|
|
|
|
|
7
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
|
|
|
|
|
|
8
|
|
|
use eZ\Publish\API\Repository\Values\ContentType\ContentType; |
|
9
|
|
|
use EzSystems\RepositoryForms\Data\Content\FieldData; |
|
10
|
|
|
|
|
11
|
|
|
final class InformationCollectionStruct extends ValueObject |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The language code of the version. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $languageCode; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var \eZ\Publish\API\Repository\Values\Content\Content |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $content; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \eZ\Publish\API\Repository\Values\ContentType\ContentType |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $contentType; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \EzSystems\RepositoryForms\Data\Content\FieldData[] |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $fields; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct(Content $content, ContentType $contentType, array $fields, string $languageCode) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->content = $content; |
|
38
|
|
|
$this->contentType = $contentType; |
|
39
|
|
|
$this->languageCode = $languageCode; |
|
40
|
|
|
|
|
41
|
|
|
foreach ($fields as $field) { |
|
42
|
|
|
$this->addFieldData($field); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getLanguageCode(): string |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->languageCode; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getContent(): Content |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->content; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return \eZ\Publish\API\Repository\Values\ContentType\ContentType |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getContentType(): ContentType |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->contentType; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return \EzSystems\RepositoryForms\Data\Content\FieldData[] |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getFieldsData(): array |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->fields; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return \EzSystems\RepositoryForms\Data\Content\FieldData[] |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getCollectedFields(): array |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->fields; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function addFieldData(FieldData $fieldData) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->fields[$fieldData->fieldDefinition->identifier] = $fieldData; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: