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
98aa3dcc
Commit
98aa3dcc
authored
Feb 14, 2019
by
Guillaume Perréal
Browse files
Meilleure prise en compte des collections dans les *Filters.
parent
66d1ad8c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/OperationMapper.php
View file @
98aa3dcc
...
...
@@ -26,6 +26,7 @@ use Irstea\NgModelGeneratorBundle\Exceptions\InvalidArgumentException;
use
Irstea\NgModelGeneratorBundle\Metadata\OperationMetadata
;
use
Irstea\NgModelGeneratorBundle\Metadata\SerializationMetadata
;
use
Irstea\NgModelGeneratorBundle\Models\PHPClass
;
use
Irstea\NgModelGeneratorBundle\Models\Types\AbstractCollection
;
use
Irstea\NgModelGeneratorBundle\Models\Types\ArrayType
;
use
Irstea\NgModelGeneratorBundle\Models\Types\BuiltinType
;
use
Irstea\NgModelGeneratorBundle\Models\Types\Objects\AnonymousObject
;
...
...
@@ -35,6 +36,7 @@ use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Operation;
use
Irstea\NgModelGeneratorBundle\Models\Types\Operations\Parameter
;
use
Irstea\NgModelGeneratorBundle\Models\Types\Operations\Path
;
use
Irstea\NgModelGeneratorBundle\Models\Types\Placeholder
;
use
Irstea\NgModelGeneratorBundle\Models\Types\Reference
;
use
Irstea\NgModelGeneratorBundle\Models\Types\Resources\Collection
;
use
Irstea\NgModelGeneratorBundle\Models\Types\Resources\IRI
;
use
Irstea\NgModelGeneratorBundle\Models\Types\Resources\Representation
;
...
...
@@ -259,20 +261,18 @@ final class OperationMapper
}
}
$type
=
$this
->
resolveFilterType
(
$filterType
,
$type
);
$propName
=
Inflector
::
camelize
(
preg_replace
(
'/\W+/'
,
'_'
,
$name
));
if
(
isset
(
$filterDesc
[
'is_collection'
])
&&
$filterDesc
[
'is_collection'
])
{
$type
=
new
ArrayType
(
$type
);
$propName
=
Inflector
::
pluralize
(
$propName
);
}
$type
=
$this
->
resolveFilterType
(
$filterType
,
$type
);
if
(
isset
(
$properties
[
$propName
]))
{
$type
=
Union
::
create
([
$type
,
$properties
[
$propName
]
->
getType
()]);
$type
=
$this
->
getSingularType
(
$type
);
$propName
=
Inflector
::
singularize
(
$propName
);
if
(
!
empty
(
$filterDesc
[
'is_collection'
])
||
substr
(
$name
,
strlen
(
$name
)
-
2
)
===
'[]'
)
{
$type
=
new
ArrayType
(
$type
);
$propName
.
=
'In'
;
}
$properties
[
$propName
]
=
new
Property
(
$propName
,
''
,
$type
,
false
,
true
,
false
,
$name
);
$properties
[]
=
new
Property
(
$propName
,
''
,
$type
,
false
,
true
,
false
,
$name
);
}
}
...
...
@@ -338,6 +338,21 @@ final class OperationMapper
return
$baseType
;
}
/**
* @param Type $type
*
* @return Type
*/
private
function
getSingularType
(
Type
$type
):
Type
{
if
(
$type
instanceof
AbstractCollection
)
{
return
$type
->
getValueType
();
}
if
(
$type
instanceof
Reference
)
{
return
$this
->
getSingularType
(
$type
->
getTarget
());
}
return
$type
;
}
/**
* @param Property[] $filterProperties
* @param string $varName
...
...
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