Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
isCustomFieldsAware example
XML;
$dom
=
new
\
DOMDocument
(
)
;
$dom
->
loadXML
(
$xml
)
;
\
assert
(
$dom
->documentElement instanceof \DOMElement
)
;
$entity
= Entity::
fromXml
(
$dom
->documentElement
)
;
static
::
assertSame
(
'my_entity',
$entity
->
getName
(
)
)
;
static
::
assertTrue
(
$entity
->
isCustomFieldsAware
(
)
)
;
static
::
assertSame
(
'name',
$entity
->
getLabelProperty
(
)
)
;
$fields
=
$entity
->
getFields
(
)
;
static
::
assertCount
(
2,
$fields
)
;
static
::
assertInstanceOf
(
StringField::
class
,
$fields
[
0
]
)
;
static
::
assertEquals
(
'id',
$fields
[
0
]
->
getName
(
)
)
;
static
::
assertInstanceOf
(
StringField::
class
,
$fields
[
1
]
)
;
static
::
assertEquals
(
'name',
$fields
[
1
]
->
getName
(
)
)
;
static
::
assertTrue
(
$fields
[
1
]
->
isTranslatable
(
)
)
;
}
#[Package('core')]
class
CustomEntityXmlSchemaValidator
{
public
function
validate
(
CustomEntityXmlSchema
$schema
)
: void
{
if
(
$schema
->
getEntities
(
)
=== null
)
{
throw
new
\
RuntimeException
(
'No entities found in parsed xml file'
)
;
}
foreach
(
$schema
->
getEntities
(
)
->
getEntities
(
)
as
$entity
)
{
if
(
$entity
->
isCustomFieldsAware
(
)
)
{
$label
=
$entity
->
getLabelProperty
(
)
;
if
(
$label
=== null
)
{
throw
CustomEntityException::
noLabelProperty
(
)
;
}
if
(
!
$entity
->
hasField
(
$label
)
)
{
throw
CustomEntityException::
labelPropertyNotDefined
(
$label
)
;
}
if
(
!
$entity
->
getField
(
$label
)
instanceof StringField
)
{