Skip to content

Commit 6d5198f

Browse files
committed
feat: added serialize
1 parent bfd98e2 commit 6d5198f

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/Entity/Degree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Degree
2828
#[ORM\Column(length: 255, unique: true)]
2929
private string $name;
3030

31-
#[Gedmo\Slug(fields: ['name'], unique: true)]
31+
#[Gedmo\Slug(fields: ['name'], unique: true)]
3232
#[ORM\Column(length: 255, unique: true)]
3333
private string $slug;
3434

src/Entity/User.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
use Vich\UploaderBundle\Mapping\Annotation as Vich;
3030

3131
use function array_unique;
32+
use function get_object_vars;
3233
use function in_array;
34+
use function property_exists;
3335
use function sprintf;
3436

3537
#[ORM\Table(name: 'fos_user')]
@@ -625,4 +627,25 @@ public function removeGroup(Group $group): self
625627

626628
return $this;
627629
}
630+
631+
/** @return array<string, mixed> */
632+
public function __serialize(): array
633+
{
634+
$vars = get_object_vars($this);
635+
unset($vars['imageFile']);
636+
637+
return $vars;
638+
}
639+
640+
/** @param array<string, mixed> $data */
641+
public function __unserialize(array $data): void
642+
{
643+
foreach ($data as $key => $value) {
644+
if (! property_exists($this, $key)) {
645+
continue;
646+
}
647+
648+
$this->$key = $value;
649+
}
650+
}
628651
}

0 commit comments

Comments
 (0)