Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pôle IS
Bundles Symfony 2
ng-model-generator-bundle
Commits
6b397d00
Commit
6b397d00
authored
Apr 02, 2020
by
Guillaume Perréal
Browse files
Ne produit plus d'attributs de type "Array" tout seul.
Array doit toujours venir avec un type générique.
parent
d19e499b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/php/ModelGenerator.php
View file @
6b397d00
...
...
@@ -194,7 +194,7 @@ final class ModelGenerator
{
$factory
=
new
TypeFactory
();
foreach
([
'Array'
,
'Date'
,
'boolean'
,
'number'
,
'null'
,
'string'
,
'any'
,
'never'
]
as
$builtin
)
{
foreach
([
'Array'
,
'Date'
,
'boolean'
,
'number'
,
'null'
,
'string'
,
'any'
,
'never'
,
'unknown'
]
as
$builtin
)
{
$factory
->
add
(
$builtin
,
BuiltinType
::
get
(
$builtin
));
}
...
...
src/php/SerializationMapper.php
View file @
6b397d00
...
...
@@ -321,35 +321,37 @@ final class SerializationMapper implements TypeFactoryInterface
return
BuiltinType
::
get
(
'unknown'
);
}
if
(
!
$type
->
isCollection
())
{
$className
=
$type
->
getClassName
();
if
(
$className
===
null
)
{
return
$this
->
get
(
$type
->
getBuiltinType
());
}
if
(
$isLink
)
{
return
$this
->
createIRI
([
PHPClass
::
get
(
$className
)]);
}
return
$this
->
get
(
$className
);
if
(
$type
->
isCollection
()
||
$type
->
getBuiltinType
()
===
'array'
)
{
return
$this
->
mapCollection
(
$type
,
$isLink
);
}
$indexType
=
$type
->
getCollectionKeyType
();
if
(
$indexType
===
null
&&
$type
->
getCollectionValueType
()
===
null
&&
$type
->
getBuiltinType
()
===
'array'
)
{
return
new
ArrayType
(
BuiltinType
::
get
(
'unknown'
));
$className
=
$type
->
getClassName
();
if
(
$className
===
null
)
{
return
$this
->
get
(
$type
->
getBuiltinType
());
}
if
(
$isLink
)
{
return
$this
->
createIRI
([
PHPClass
::
get
(
$className
)]);
}
Assertion
::
notNull
(
$indexType
,
'Cannot handle collection with undefined index type'
);
return
$this
->
get
(
$className
);
}
$builtinType
=
$indexType
->
getBuiltinType
();
if
(
$builtinType
!==
'int'
)
{
throw
new
\
InvalidArgumentException
(
"Cannot handle collection with index type
$builtinType
"
);
}
/**
* @param APIType $type
* @param bool $isLink
*
* @return Type
*/
private
function
mapCollection
(
?APIType
$type
,
bool
$isLink
=
false
):
Type
{
$indexType
=
$type
->
getCollectionKeyType
();
$valueType
=
$this
->
mapType
(
$type
->
getCollectionValueType
(),
$isLink
);
if
(
!
$indexType
||
$indexType
->
getBuiltinType
()
===
'int'
)
{
return
new
ArrayType
(
$this
->
mapType
(
$type
->
getCollectionValueType
(),
$isLink
));
}
return
new
ArrayType
(
$valueType
);
throw
new
DomainException
(
"Cannot handle collection with non-integer index"
);
}
/**
* @param ClassName $class
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment