Make PermissionData an embeddable so doctrine can properly track changes to the data array

This commit is contained in:
Jan Böhmer 2022-10-31 21:12:01 +01:00
parent 687ee80255
commit 59ddf91527
5 changed files with 53 additions and 47 deletions

View file

@ -2,6 +2,14 @@
namespace App\Entity\UserSystem;
use Doctrine\ORM\Mapping as ORM;
/**
* This class is used to store the permissions of a user.
* This has to be an embeddable or otherwise doctrine could not track the changes of the underlying data array (which is serialized to JSON in the database)
*
* @ORM\Embeddable()
*/
final class PermissionData implements \JsonSerializable
{
/**
@ -17,8 +25,9 @@ final class PermissionData implements \JsonSerializable
* permission => [
* operation => value,
* ]
* @ORM\Column(type="json", name="data")
*/
protected array $data = [];
protected ?array $data = [];
/**
* Creates a new Permission Data Instance using the given data.
@ -91,6 +100,11 @@ final class PermissionData implements \JsonSerializable
return new self($data);
}
public function __clone()
{
$this->data = $this->data;
}
/**
* Returns an JSON encodable representation of this object.
* @return array|mixed