resq/catalyst/auth-bundle/Entity/User.php

64 lines
1.3 KiB
PHP

<?php
namespace Catalyst\AuthBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Serializable;
use Symfony\Component\Security\Core\User\UserInterface;
// base User class
abstract class User implements UserInterface,Serializable
{
// NOTE: doctrine annotations for roles have to be declared on the child class
protected $roles;
/**
* @ORM\Column(type="boolean")
*/
protected $enabled;
public function __construct()
{
$this->roles = new ArrayCollection();
$this->enabled = true;
}
// array of string roles, needed by symfony
public function getRoles()
{
$str_roles = [];
foreach ($this->roles as $role)
$str_roles[] = $role->getID();
return $str_roles;
}
public function getRoleObjects()
{
return $this->roles;
}
public function addRole(Role $role)
{
$this->roles->add($role);
return $this;
}
public function clearRoles()
{
$this->roles->clear();
return $this;
}
public function setEnabled($enabled = true)
{
$this->enabled = $enabled;
return $this;
}
public function isEnabled()
{
return $this->enabled;
}
}