Commit 98aa3dcc authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Meilleure prise en compte des collections dans les *Filters.

Showing with 24 additions and 9 deletions
+24 -9
...@@ -26,6 +26,7 @@ use Irstea\NgModelGeneratorBundle\Exceptions\InvalidArgumentException; ...@@ -26,6 +26,7 @@ use Irstea\NgModelGeneratorBundle\Exceptions\InvalidArgumentException;
use Irstea\NgModelGeneratorBundle\Metadata\OperationMetadata; use Irstea\NgModelGeneratorBundle\Metadata\OperationMetadata;
use Irstea\NgModelGeneratorBundle\Metadata\SerializationMetadata; use Irstea\NgModelGeneratorBundle\Metadata\SerializationMetadata;
use Irstea\NgModelGeneratorBundle\Models\PHPClass; use Irstea\NgModelGeneratorBundle\Models\PHPClass;
use Irstea\NgModelGeneratorBundle\Models\Types\AbstractCollection;
use Irstea\NgModelGeneratorBundle\Models\Types\ArrayType; use Irstea\NgModelGeneratorBundle\Models\Types\ArrayType;
use Irstea\NgModelGeneratorBundle\Models\Types\BuiltinType; use Irstea\NgModelGeneratorBundle\Models\Types\BuiltinType;
use Irstea\NgModelGeneratorBundle\Models\Types\Objects\AnonymousObject; use Irstea\NgModelGeneratorBundle\Models\Types\Objects\AnonymousObject;
...@@ -35,6 +36,7 @@ use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Operation; ...@@ -35,6 +36,7 @@ use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Operation;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Parameter; use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Parameter;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Path; use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Path;
use Irstea\NgModelGeneratorBundle\Models\Types\Placeholder; 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\Collection;
use Irstea\NgModelGeneratorBundle\Models\Types\Resources\IRI; use Irstea\NgModelGeneratorBundle\Models\Types\Resources\IRI;
use Irstea\NgModelGeneratorBundle\Models\Types\Resources\Representation; use Irstea\NgModelGeneratorBundle\Models\Types\Resources\Representation;
...@@ -259,20 +261,18 @@ final class OperationMapper ...@@ -259,20 +261,18 @@ final class OperationMapper
} }
} }
$type = $this->resolveFilterType($filterType, $type);
$propName = Inflector::camelize(preg_replace('/\W+/', '_', $name)); $propName = Inflector::camelize(preg_replace('/\W+/', '_', $name));
if (isset($filterDesc['is_collection']) && $filterDesc['is_collection']) { $type = $this->resolveFilterType($filterType, $type);
$type = new ArrayType($type);
$propName = Inflector::pluralize($propName);
}
if (isset($properties[$propName])) { $type = $this->getSingularType($type);
$type = Union::create([$type, $properties[$propName]->getType()]); $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 ...@@ -338,6 +338,21 @@ final class OperationMapper
return $baseType; 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 Property[] $filterProperties
* @param string $varName * @param string $varName
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment