Skip to content

Commit

Permalink
Splitting association creation for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsorst committed Dec 30, 2017
1 parent 5628a96 commit 28d70e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Controller/AbstractCrudServiceRestResourceController.php
Expand Up @@ -90,11 +90,19 @@ protected function listSubresource($entity, string $subresource, int $page = 1,
/**
* {@inheritdoc}
*/
protected function createAssociation($parent, string $subresource, $entity)
protected function buildAssociation($parent, string $subresource, $entity)
{
return $this->getService()->createAssociation($parent, $subresource, $entity);
}

/**
* {@inheritdoc}
*/
protected function createAssociation($associatedEntity)
{
return $this->getService()->create($associatedEntity);
}

/**
* {@inheritdoc}
*/
Expand Down
13 changes: 10 additions & 3 deletions Controller/AbstractRestResourceController.php
Expand Up @@ -216,7 +216,7 @@ public function postSubresourceAction(Request $request, $id, string $subresource

$restRequestParser = $this->getRequestParser();
$entity = $restRequestParser->parseEntity($request, $this->getSubResourceEntityClass($subresource));

$entity = $this->buildAssociation($parent, $subresource, $entity);
$entity = $this->postProcessSubResourcePostedEntity($parent, $subresource, $entity);

$errors = $this->getValidator()->validate($entity);
Expand All @@ -225,7 +225,7 @@ public function postSubresourceAction(Request $request, $id, string $subresource
return new JsonResponse($this->parseConstraintViolations($errors), Response::HTTP_BAD_REQUEST);
}

$entity = $this->createAssociation($parent, $subresource, $entity);
$entity = $this->createAssociation($entity);

$content = $this->getNormalizer()->normalize($entity, $this->parseIncludes($request));

Expand Down Expand Up @@ -543,7 +543,14 @@ abstract protected function listSubresource($entity, string $subresource, int $p
*
* @return object
*/
abstract protected function createAssociation($parent, string $subresource, $entity);
abstract protected function buildAssociation($parent, string $subresource, $entity);

/**
* @param object $associatedEntity
*
* @return object
*/
abstract protected function createAssociation($associatedEntity);

/**
* @param object $parent
Expand Down

0 comments on commit 28d70e7

Please sign in to comment.