Refactored code to comply with PSR-*

Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely POLONKAI
2012-08-16 15:52:41 +02:00
parent de00a6ad21
commit fab08cad6f
69 changed files with 5253 additions and 4673 deletions

View File

@@ -15,155 +15,171 @@ use KekRozsak\SecurityBundle\Entity\User;
*/
class Role implements RoleInterface
{
/**
* @var integer $id
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* The ID of the Role
*
* @var integer $id
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @var string name
* @ORM\Column(type="string", length=50, unique=true, nullable=false)
*/
protected $name;
/**
* The role name of the Role
*
* @var string name
*
* @ORM\Column(type="string", length=50, unique=true, nullable=false)
*/
protected $name;
/**
* Set name
*
* @param string $name
* @return Role
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Set name
*
* @param string $name
* @return Role
*/
public function setName($name)
{
// TODO: Check if null or empty!
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @var boolean $default
* @ORM\Column(type="boolean", nullable=false)
*/
protected $default;
/**
* TRUE if this Role is automatically added to newly registered Users
*
* @var boolean $default
*
* @ORM\Column(type="boolean", nullable=false)
*/
protected $default;
/**
* Set default
*
* @param boolean $default
*/
public function setDefault($default)
{
$this->default = $default;
return $this;
}
/**
* Set default
*
* @param boolean $default
*/
public function setDefault($default)
{
// TODO: Check if parameter is boolean!
$this->default = $default;
return $this;
}
/**
* @var text description
* @ORM\Column(type="string", length=150, nullable=true)
*/
protected $description;
/**
* The description of this Role
*
* @var text description
*
* @ORM\Column(type="string", length=150, nullable=true)
*/
protected $description;
/**
* Set description
*
* @param string $description
* @return Role
*/
public function setDescription($description = null)
{
$this->description = $description;
return $this;
}
/**
* Set description
*
* @param string $description
* @return Role
*/
public function setDescription($description = null)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/* Here comes the rest of RoleInterface's implementation */
/* Here comes the rest of RoleInterface's implementation */
public function getRole()
{
return $this->name;
}
public function getRole()
{
return $this->name;
}
/**
* Short description
*
* @var string shortDescription
*
* @ORM\Column(type="string", length=50, nullable=false, unique=true, name="short_description")
*/
protected $shortDescription;
/**
* Short description of the Role (e.g readable name)
*
* @var string shortDescription
*
* @ORM\Column(type="string", length=50, nullable=false, unique=true, name="short_description")
*/
protected $shortDescription;
/**
* Set shortDescription
*
* @param string $shortDescription
* @return Role
*/
public function setShortDescription($shortDescription)
{
$this->shortDescription = $shortDescription;
return $this;
}
/**
* Set shortDescription
*
* @param string $shortDescription
* @return Role
*/
public function setShortDescription($shortDescription)
{
// TODO: Check if empty or null!
$this->shortDescription = $shortDescription;
return $this;
}
/**
* Get shortDescription
*
* @return string
*/
public function getShortDescription()
{
return $this->shortDescription;
}
/**
* Get shortDescription
*
* @return string
*/
public function getShortDescription()
{
return $this->shortDescription;
}
/**
* List of inherited Roles
*
* @ORM\ManyToMany(targetEntity="Role", fetch="LAZY")
* @ORM\JoinTable(name="role_hierarchy", joinColumns={
* @ORM\JoinColumn(name="parent_role_id", referencedColumnName="id")
* }, inverseJoinColumns={
* @ORM\JoinColumn(name="child_role_id", referencedColumnName="id")
* })
*/
protected $inheritedRoles;
/**
* List of inherited Roles. Required for RoleHierarchy
*
* @var Doctrine\Common\Collections\ArrayCollection $inheritedRoles
*
* @ORM\ManyToMany(targetEntity="Role", fetch="LAZY")
* @ORM\JoinTable(name="role_hierarchy", joinColumns={
* @ORM\JoinColumn(name="parent_role_id", referencedColumnName="id")
* }, inverseJoinColumns={
* @ORM\JoinColumn(name="child_role_id", referencedColumnName="id")
* })
*/
protected $inheritedRoles;
/**
* Get all inherited roles
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getInheritedRoles()
{
return $this->inheritedRoles;
}
/**
* Get all inherited roles
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getInheritedRoles()
{
return $this->inheritedRoles;
}
}

View File

@@ -11,6 +11,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
use KekRozsak\FrontBundle\Entity\UserData;
use KekRozsak\FrontBundle\Entity\UserGroupMembership;
use KekRozsak\SecurityBundle\Entity\Role;
/**
* KekRozsak\SecurityBundle\Entity\User
@@ -22,364 +23,403 @@ use KekRozsak\FrontBundle\Entity\UserGroupMembership;
*/
class User implements UserInterface, AdvancedUserInterface
{
public function __construct()
{
$this->groups = new ArrayCollection();
$this->roles = new ArrayCollection();
}
public function __construct()
{
$this->groups = new ArrayCollection();
$this->roles = new ArrayCollection();
}
/**
* @var integer $id
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* The ID of the User
*
* @var integer $id
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @var string $username
* @ORM\Column(type="string", length=50, nullable=false, unique=true)
* @Assert\NotBlank(groups="registration")
*/
protected $username;
/**
* The login name of the User
*
* @var string $username
*
* @ORM\Column(type="string", length=50, nullable=false, unique=true)
* @Assert\NotBlank(groups="registration")
*/
protected $username;
/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
// TODO: check if null or empty!
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* @var string $password
* @ORM\Column(type="string", length=50, nullable=false)
* @Assert\NotBlank(groups="registration")
*/
protected $password;
/**
* The encrypted password of the User
*
* @var string $password
*
* @ORM\Column(type="string", length=50, nullable=false)
* @Assert\NotBlank(groups="registration")
*/
protected $password;
/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* @var string $displayName
* @ORM\Column(type="string", length=50, unique=true, name="display_name")
*/
protected $displayName;
/**
* The display name of the User
*
* @var string $displayName
*
* @ORM\Column(type="string", length=50, unique=true, name="display_name")
*/
protected $displayName;
/**
* Set displayName
*
* @param string $displayName
* @return User
*/
public function setDisplayName($displayName)
{
$this->displayName = $displayName;
return $this;
}
/**
* Set displayName
*
* @param string $displayName
* @return User
*/
public function setDisplayName($displayName)
{
// TODO: Check if empty or null!
$this->displayName = $displayName;
return $this;
}
/**
* Get displayName
*
* @return string
*/
public function getDisplayName()
{
return $this->displayName;
}
/**
* Get displayName
*
* @return string
*/
public function getDisplayName()
{
return $this->displayName;
}
/**
* @var string $email
* @ORM\Column(type="string", length=100, nullable=false, unique=true)
*/
protected $email;
/**
* The e-mail address of the User
*
* @var string $email
*
* @ORM\Column(type="string", length=100, nullable=false, unique=true)
*/
protected $email;
/**
* Set email
*
* @param string $email
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Set email
*
* @param string $email
* @return User
*/
public function setEmail($email)
{
// TODO: Check if empty or null!
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @var DateTime $registeredAt
* @ORM\Column(type="datetime", nullable=false, name="registered_at")
*/
protected $registeredAt;
/**
* The timestamp when the user registered
*
* @var DateTime $registeredAt
*
* @ORM\Column(type="datetime", nullable=false, name="registered_at")
*/
protected $registeredAt;
/**
* Set registeredAt
*
* @param DateTime $registeredAt
* @return User
*/
public function setRegisteredAt(\DateTime $registeredAt)
{
$this->registeredAt = $registeredAt;
return $this;
}
/**
* Set registeredAt
*
* @param DateTime $registeredAt
* @return User
*/
public function setRegisteredAt(\DateTime $registeredAt)
{
$this->registeredAt = $registeredAt;
return $this;
}
/**
* Get registeredAt
*
* @return DateTime
*/
public function getRegisteredAt()
{
return $this->registeredAt;
}
/**
* Get registeredAt
*
* @return DateTime
*/
public function getRegisteredAt()
{
return $this->registeredAt;
}
/**
* @var User acceptedBy
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="accepted_by_id")
*/
protected $acceptedBy;
/**
* The User who accepted this User's registration
*
* @var User acceptedBy
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="accepted_by_id")
*/
protected $acceptedBy;
/**
* Set acceptedBy
*
* @param User $acceptedBy
* @return User
*/
public function setAcceptedBy(User $acceptedBy = null)
{
$this->acceptedBy = $acceptedBy;
return $this;
}
/**
* Set acceptedBy
*
* @param User $acceptedBy
* @return User
*/
public function setAcceptedBy(User $acceptedBy = null)
{
$this->acceptedBy = $acceptedBy;
return $this;
}
/**
* Get acceptedBy
*
* @return User
*/
public function getAcceptedBy()
{
return $this->acceptedBy;
}
/**
* Get acceptedBy
*
* @return User
*/
public function getAcceptedBy()
{
return $this->acceptedBy;
}
/**
* @var DateTime $lastLoginAt
* @ORM\Column(type="datetime", nullable=true, name="last_login_at")
*/
protected $lastLoginAt;
/**
* The timestamp when the User logged in last time
*
* @var DateTime $lastLoginAt
*
* @ORM\Column(type="datetime", nullable=true, name="last_login_at")
*/
protected $lastLoginAt;
/**
* Set lastLoginAt;
*
* @param DateTime $lastLoginAt
* @return User
*/
public function setLastLoginAt(\DateTime $lastLoginAt = null)
{
$this->lastLoginAt = $lastLoginAt;
return $this;
}
/**
* Set lastLoginAt;
*
* @param DateTime $lastLoginAt
* @return User
*/
public function setLastLoginAt(\DateTime $lastLoginAt = null)
{
$this->lastLoginAt = $lastLoginAt;
return $this;
}
/**
* Get lastLoginAt
*
* @return DateTime
*/
public function getLastLoginAt()
{
return $this->lastLoginAt;
}
/**
* Get lastLoginAt
*
* @return DateTime
*/
public function getLastLoginAt()
{
return $this->lastLoginAt;
}
/**
* @var \KekRozsak\FrontBundle\Entity\UserData $userData
* @ORM\OneToOne(targetEntity="KekRozsak\FrontBundle\Entity\UserData", fetch="LAZY", cascade={"persist"}, mappedBy="user")
*/
protected $userData;
/**
* The UserData object for this User
*
* @var \KekRozsak\FrontBundle\Entity\UserData $userData
*
* @ORM\OneToOne(targetEntity="KekRozsak\FrontBundle\Entity\UserData", fetch="LAZY", cascade={"persist"}, mappedBy="user")
*/
protected $userData;
/**
* Set userData
*
* @param \KekRozsak\FrontBundle\Entity\UserData $userData
* @return User
*/
public function setUserData(\KekRozsak\FrontBundle\Entity\UserData $userData = null)
{
$this->userData = $userData;
$userData->setUser($this);
return $this;
}
/**
* Set userData
*
* @param \KekRozsak\FrontBundle\Entity\UserData $userData
* @return User
*/
public function setUserData(\KekRozsak\FrontBundle\Entity\UserData $userData = null)
{
$this->userData = $userData;
$userData->setUser($this);
return $this;
}
/**
* Get userData
*
* @return \KekRozsak\FrontBundle\Entity\UserData
*/
public function getUserData()
{
return $this->userData;
}
/**
* Get userData
*
* @return \KekRozsak\FrontBundle\Entity\UserData
*/
public function getUserData()
{
return $this->userData;
}
/**
* The Group memberships of this User represented by UserGroupMembership
* objects
*
* @var Doctrine\Common\Collections\ArrayCollection $groups
*
* @ORM\OneToMany(targetEntity="KekRozsak\FrontBundle\Entity\UserGroupMembership", mappedBy="user")
* @ORM\JoinColumn(referencedColumnName="user_id")
*/
protected $groups;
/**
* @var Doctrine\Common\Collections\ArrayCollection $groups
* @ORM\OneToMany(targetEntity="KekRozsak\FrontBundle\Entity\UserGroupMembership", mappedBy="user")
* @ORM\JoinColumn(referencedColumnName="user_id")
*/
protected $groups;
/**
* Add group
*
* @param KekRozsak\FrontBundle\Entity\UserGroupMembership $group
* @return User
*/
public function addGroup(UserGroupMembership $group)
{
// TODO: Check if null!
$this->groups[] = $group;
return $this;
}
/**
* Add group
*
* @param KekRozsak\FrontBundle\Entity\UserGroupMembership $group
* @return User
*/
public function addGroup(\KekRozsak\FrontBundle\Entity\UserGroupMembership $group)
{
$this->groups[] = $group;
return $this;
}
/**
* Get all groups
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getGroups()
{
return $this->groups;
}
/**
* Get all groups
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getGroups()
{
return $this->groups;
}
/**
* The Roles belonging to this User
*
* @var Doctrine\Common\Collections\ArrayCollection $roles
*
* @ORM\ManyToMany(targetEntity="Role")
*/
protected $roles;
/**
* @var Doctrine\Common\Collections\ArrayCollection $roles
* @ORM\ManyToMany(targetEntity="Role")
*/
protected $roles;
/**
* Add a role
*
* @param KekRozsak\SecurityBundle\Entity\Role $role
* @return User
*/
public function addRole(Role $role)
{
// TODO: Check if null!
$this->roles[] = $role;
return $this;
}
/**
* Add a role
*
* @param KekRozsak\SecurityBundle\Entity\Role $role
* @return User
*/
public function addRole(\KekRozsak\SecurityBundle\Entity\Role $role)
{
$this->roles[] = $role;
return $this;
}
/**
* Get all roles as an ArrayCollection
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getRolesCollection()
{
return $this->roles;
}
/**
* Get all roles as an ArrayCollection
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getRolesCollection()
{
return $this->roles;
}
/**
* Get all roles, for UserInterface implementation. To get the
* ArrayCollection, use getRolesCollection() instead
*
* @return array
*/
public function getRoles()
{
return $this->roles->toArray();
}
/**
* Get all roles, for UserInterface implementation. To get the
* collection, use getRolesCollection() instead
*
* @return array
*/
public function getRoles()
{
return $this->roles->toArray();
}
/* Here comes the remaining part of UserInterface implementation */
/* Here comes the remaining part of UserInterface implementation */
public function getSalt()
{
/*
* As we use crypt() to encode passwords, salt is always the same as the
* password
*/
return $this->password;
}
public function getSalt()
{
/* As we use crypt() to encode passwords, salt is always the
* same as password
*/
return $this->password;
}
public function eraseCredentials()
{
}
public function eraseCredentials()
{
}
/* Here comes the AdvancedUserInterface implementation */
/* Here comes the AdvancedUserInterface implementation */
public function isAccountNonExpired()
{
/* Currently, accounts never expire */
return true;
}
public function isAccountNonExpired()
{
/* Currently, accounts never expire */
return true;
}
public function isAccountNonLocked()
{
/* Currently, accounts cannot be locked */
return true;
}
public function isAccountNonLocked()
{
/* Currently, accounts cannot be locked */
return true;
}
public function isCredentialsNonExpired()
{
/* Currently, credentials never expire */
return true;
}
public function isCredentialsNonExpired()
{
/* Currently, credentials never expire */
return true;
}
public function isEnabled()
{
/* Account is enabled if it is accepted by someone */
return ($this->acceptedBy !== null);
}
public function isEnabled()
{
/* Account is enabled if it is accepted by someone */
return ($this->acceptedBy !== null);
}
}