CAuthAssignment.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * CAuthAssignment class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CAuthAssignment represents an assignment of a role to a user.
  12. * It includes additional assignment information such as {@link bizRule} and {@link data}.
  13. * Do not create a CAuthAssignment instance using the 'new' operator.
  14. * Instead, call {@link IAuthManager::assign}.
  15. *
  16. * @property mixed $userId User ID (see {@link IWebUser::getId}).
  17. * @property string $itemName The authorization item name.
  18. * @property string $bizRule The business rule associated with this assignment.
  19. * @property mixed $data Additional data for this assignment.
  20. *
  21. * @author Qiang Xue <qiang.xue@gmail.com>
  22. * @package system.web.auth
  23. * @since 1.0
  24. */
  25. class CAuthAssignment extends CComponent
  26. {
  27. private $_auth;
  28. private $_itemName;
  29. private $_userId;
  30. private $_bizRule;
  31. private $_data;
  32. /**
  33. * Constructor.
  34. * @param IAuthManager $auth the authorization manager
  35. * @param string $itemName authorization item name
  36. * @param mixed $userId user ID (see {@link IWebUser::getId})
  37. * @param string $bizRule the business rule associated with this assignment
  38. * @param mixed $data additional data for this assignment
  39. */
  40. public function __construct($auth,$itemName,$userId,$bizRule=null,$data=null)
  41. {
  42. $this->_auth=$auth;
  43. $this->_itemName=$itemName;
  44. $this->_userId=$userId;
  45. $this->_bizRule=$bizRule;
  46. $this->_data=$data;
  47. }
  48. /**
  49. * @return mixed user ID (see {@link IWebUser::getId})
  50. */
  51. public function getUserId()
  52. {
  53. return $this->_userId;
  54. }
  55. /**
  56. * @return string the authorization item name
  57. */
  58. public function getItemName()
  59. {
  60. return $this->_itemName;
  61. }
  62. /**
  63. * @return string the business rule associated with this assignment
  64. */
  65. public function getBizRule()
  66. {
  67. return $this->_bizRule;
  68. }
  69. /**
  70. * @param string $value the business rule associated with this assignment
  71. */
  72. public function setBizRule($value)
  73. {
  74. if($this->_bizRule!==$value)
  75. {
  76. $this->_bizRule=$value;
  77. $this->_auth->saveAuthAssignment($this);
  78. }
  79. }
  80. /**
  81. * @return mixed additional data for this assignment
  82. */
  83. public function getData()
  84. {
  85. return $this->_data;
  86. }
  87. /**
  88. * @param mixed $value additional data for this assignment
  89. */
  90. public function setData($value)
  91. {
  92. if($this->_data!==$value)
  93. {
  94. $this->_data=$value;
  95. $this->_auth->saveAuthAssignment($this);
  96. }
  97. }
  98. }