Advertisement
Guest User

RbacFlatRoleDoctrineORM

a guest
Apr 18th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.51 KB | None | 0 0
  1. MariaDB [minhqh_rbacflatrole]> desc user;
  2. +----------+-------------+------+-----+---------+----------------+
  3. | Field    | Type        | Null | Key | Default | Extra          |
  4. +----------+-------------+------+-----+---------+----------------+
  5. | id       | int(11)     | NO   | PRI | NULL    | auto_increment |
  6. | username | varchar(50) | NO   |     | NULL    |                |
  7. | password | varchar(50) | NO   |     | NULL    |                |
  8. +----------+-------------+------+-----+---------+----------------+
  9. 3 rows in set (0.01 sec)
  10.  
  11. MariaDB [minhqh_rbacflatrole]> desc role;
  12. +-------+--------------+------+-----+---------+----------------+
  13. | Field | Type         | Null | Key | Default | Extra          |
  14. +-------+--------------+------+-----+---------+----------------+
  15. | id    | int(11)      | NO   | PRI | NULL    | auto_increment |
  16. | name  | varchar(100) | NO   |     | NULL    |                |
  17. +-------+--------------+------+-----+---------+----------------+
  18. 2 rows in set (0.00 sec)
  19.  
  20. MariaDB [minhqh_rbacflatrole]> desc user_role;
  21. +---------+---------+------+-----+---------+----------------+
  22. | Field   | Type    | Null | Key | Default | Extra          |
  23. +---------+---------+------+-----+---------+----------------+
  24. | id      | int(11) | NO   | PRI | NULL    | auto_increment |
  25. | user_id | int(11) | NO   | MUL | NULL    |                |
  26. | role_id | int(11) | NO   | MUL | NULL    |                |
  27. +---------+---------+------+-----+---------+----------------+
  28. <?php
  29.  
  30. namespace Application\Entity;
  31.  
  32. use Doctrine\ORM\Mapping as ORM;
  33.  
  34. /**
  35.  * User
  36.  *
  37.  * @ORM\Table(name="user")
  38.  * @ORM\Entity
  39.  */
  40. class User implements \ZfcRbac\Identity\IdentityInterface {
  41.  
  42.     /**
  43.      * @var integer
  44.      *
  45.      * @ORM\Column(name="id", type="integer", nullable=false)
  46.      * @ORM\Id
  47.      * @ORM\GeneratedValue(strategy="IDENTITY")
  48.      */
  49.     private $id;
  50.  
  51.     /**
  52.      * @var string
  53.      *
  54.      * @ORM\Column(name="username", type="string", length=50, nullable=false)
  55.      */
  56.     private $username;
  57.  
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column(name="password", type="string", length=50, nullable=false)
  62.      */
  63.     private $password;
  64.  
  65.     /**
  66.      * @ORM\OneToMany(targetEntity="UserRole", mappedBy="User")
  67.      * @return \Doctrine\Common\Collections\ArrayCollection
  68.      */
  69.     private $userRole;
  70.  
  71.     public function __construct() {
  72.         $this->userRole = new \Doctrine\Common\Collections\ArrayCollection();
  73.     }
  74.  
  75.     /**
  76.      * Get id
  77.      *
  78.      * @return integer
  79.      */
  80.     public function getId() {
  81.         return $this->id;
  82.     }
  83.  
  84.     /**
  85.      * Set username
  86.      *
  87.      * @param string $username
  88.      *
  89.      * @return User
  90.      */
  91.     public function setUsername($username) {
  92.         $this->username = $username;
  93.  
  94.         return $this;
  95.     }
  96.  
  97.     /**
  98.      * Get username
  99.      *
  100.      * @return string
  101.      */
  102.     public function getUsername() {
  103.         return $this->username;
  104.     }
  105.  
  106.     /**
  107.      * Set password
  108.      *
  109.      * @param string $password
  110.      *
  111.      * @return User
  112.      */
  113.     public function setPassword($password) {
  114.         $this->password = $password;
  115.  
  116.         return $this;
  117.     }
  118.  
  119.     /**
  120.      * Get password
  121.      *
  122.      * @return string
  123.      */
  124.     public function getPassword() {
  125.         return $this->password;
  126.     }
  127.  
  128.     /**
  129.      * Get the list of roles of this identity
  130.      *
  131.      * @return string[]|\Rbac\Role\RoleInterface[]
  132.      */
  133.     public function getRoles() {
  134.        
  135.         return array('admin');
  136.     }
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement