Skip to content

Commit

Permalink
add groups
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed Jan 9, 2021
1 parent f4fe783 commit 01fd5c3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/FormSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ final class FormSerializer

private EventDispatcher $eventDispatcher;

/** @var string[] */
private array $groups = [];

public function __construct(
private Form $form,
private string $class,
Expand All @@ -56,6 +59,14 @@ public function __construct(
$this->prepare();
}

/**
* @param string[] $groups
*/
public function setGroups(array $groups): void
{
$this->groups = $groups;
}

public function setPersistObject(bool $persistObject): self
{
$this->persistObject = $persistObject;
Expand Down Expand Up @@ -160,7 +171,7 @@ private function prepare(): void

// validate
if ($this->validateObject && $this->validator) {
$errors = $this->validator->validate($object);
$errors = $this->validator->validate($object, null, $this->groups ?: null);

if ($errors) {
foreach ($errors->getViolations() as $error) {
Expand Down

0 comments on commit 01fd5c3

Please sign in to comment.