Source for file Identity.php

Documentation is available at Identity.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see http://nettephp.com
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    http://nettephp.com/license  Nette license
  15. 15:  * @link       http://nettephp.com
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Security
  18. 18:  */
  19. 19:  
  20. 20:  
  21. 21:  
  22. 22: require_once dirname(__FILE__'/../Security/IIdentity.php';
  23. 23:  
  24. 24: require_once dirname(__FILE__'/../FreezableObject.php';
  25. 25:  
  26. 26:  
  27. 27:  
  28. 28: /**
  29. 29:  * Default implementation of IIdentity.
  30. 30:  *
  31. 31:  * @author     David Grudl
  32. 32:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  33. 33:  * @package    Nette\Security
  34. 34:  *
  35. 35:  * @property   string $name 
  36. 36:  * @property   mixed $id 
  37. 37:  * @property   array $roles 
  38. 38:  */
  39. 39: class Identity extends FreezableObject implements IIdentity
  40. 40: {
  41. 41:     /** @var string */
  42. 42:     private $name;
  43. 43:  
  44. 44:     /** @var array */
  45. 45:     private $roles;
  46. 46:  
  47. 47:     /** @var array */
  48. 48:     private $data;
  49. 49:  
  50. 50:  
  51. 51:     /**
  52. 52:      * @param  string  identity name
  53. 53:      * @param  mixed   roles
  54. 54:      * @param  array   user data
  55. 55:      */
  56. 56:     public function __construct($name$roles NULL$data NULL)
  57. 57:     {
  58. 58:         $this->setName($name);
  59. 59:         $this->setRoles((array) $roles);
  60. 60:         $this->data = (array) $data;
  61. 61:     }
  62. 62:  
  63. 63:  
  64. 64:  
  65. 65:     /**
  66. 66:      * Sets the name of user.
  67. 67:      * @param  string 
  68. 68:      * @return void 
  69. 69:      */
  70. 70:     public function setName($name)
  71. 71:     {
  72. 72:         $this->updating();
  73. 73:         $this->name = (string) $name;
  74. 74:     }
  75. 75:  
  76. 76:  
  77. 77:  
  78. 78:     /**
  79. 79:      * Returns the name of user.
  80. 80:      * @return string 
  81. 81:      */
  82. 82:     public function getName()
  83. 83:     {
  84. 84:         return $this->name;
  85. 85:     }
  86. 86:  
  87. 87:  
  88. 88:  
  89. 89:     /**
  90. 90:      * Sets a list of roles that the user is a member of.
  91. 91:      * @param  array 
  92. 92:      * @return void 
  93. 93:      */
  94. 94:     public function setRoles(array $roles)
  95. 95:     {
  96. 96:         $this->updating();
  97. 97:         $this->roles $roles;
  98. 98:     }
  99. 99:  
  100. 100:  
  101. 101:  
  102. 102:     /**
  103. 103:      * Returns a list of roles that the user is a member of.
  104. 104:      * @return array 
  105. 105:      */
  106. 106:     public function getRoles()
  107. 107:     {
  108. 108:         return $this->roles;
  109. 109:     }
  110. 110:  
  111. 111:  
  112. 112:  
  113. 113:     /**
  114. 114:      * Returns an user data.
  115. 115:      * @return array 
  116. 116:      */
  117. 117:     public function getData()
  118. 118:     {
  119. 119:         return $this->data;
  120. 120:     }
  121. 121:  
  122. 122:  
  123. 123:  
  124. 124:     /**
  125. 125:      * Sets user data value.
  126. 126:      * @param  string  property name
  127. 127:      * @param  mixed   property value
  128. 128:      * @return void 
  129. 129:      */
  130. 130:     public function __set($key$value)
  131. 131:     {
  132. 132:         $this->updating();
  133. 133:         if ($key === 'name' || $key === 'roles'{
  134. 134:             parent::__set($key$value);
  135. 135:  
  136. 136:         else {
  137. 137:             $this->data[$key$value;
  138. 138:         }
  139. 139:     }
  140. 140:  
  141. 141:  
  142. 142:  
  143. 143:     /**
  144. 144:      * Returns user data value.
  145. 145:      * @param  string  property name
  146. 146:      * @return mixed 
  147. 147:      */
  148. 148:     public function &__get($key)
  149. 149:     {
  150. 150:         if ($key === 'name' || $key === 'roles'{
  151. 151:             return parent::__get($key);
  152. 152:  
  153. 153:         else {
  154. 154:             return $this->data[$key];
  155. 155:         }
  156. 156:     }
  157. 157: