Skip to content

Instantly share code, notes, and snippets.

@VincentChalnot
Created July 20, 2016 11:54
Show Gist options
  • Save VincentChalnot/1c580dcc2a6b7e3e2c699437be408e6d to your computer and use it in GitHub Desktop.
Save VincentChalnot/1c580dcc2a6b7e3e2c699437be408e6d to your computer and use it in GitHub Desktop.
User class example for Sidus/EncryptionBundle with FOS/UserBundle
<?php
namespace MyNameSpace\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Sidus\EncryptionBundle\Entity\UserEncryptionProviderInterface;
/**
* @ORM\Entity(repositoryClass="MyNameSpace\UserBundle\Entity\UserRepository")
* @ORM\Table(name="mynamespace_user")
*/
class User extends BaseUser implements UserEncryptionProviderInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", name="encrypted_cipher_key", nullable=true)
*/
protected $encryptedCipherKey;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed Binary data
*/
public function getEncryptedCipherKey()
{
return hex2bin($this->encryptedCipherKey);
}
/**
* @param mixed $encryptedCipherKey
*
* @return User
*/
public function setEncryptedCipherKey($encryptedCipherKey)
{
$this->encryptedCipherKey = bin2hex($encryptedCipherKey);
return $this;
}
/**
* @return int
*/
public function getEncryptionOwnershipId()
{
// If you want to share data between a group, return the id of the group.
// If you want the data to be accessible by the current user only :
return $this->getId();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment