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 https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Security
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../Security/IIdentity.php';
  24. 24:  
  25. 25: require_once dirname(__FILE__'/../Object.php';
  26. 26:  
  27. 27:  
  28. 28:  
  29. 29: /**
  30. 30:  * Default implementation of IIdentity.
  31. 31:  *
  32. 32:  * @author     David Grudl
  33. 33:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  34. 34:  * @package    Nette\Security
  35. 35:  */
  36. 36: class Identity extends Object implements IIdentity
  37. 37: {
  38. 38:     /** @var string */
  39. 39:     private $name;
  40. 40:  
  41. 41:     /** @var array */
  42. 42:     private $roles;
  43. 43:  
  44. 44:     /** @var array */
  45. 45:     private $data;
  46. 46:  
  47. 47:  
  48. 48:     /**
  49. 49:      * @param  string  identity name
  50. 50:      * @param  mixed   roles
  51. 51:      * @param  array   user data
  52. 52:      */
  53. 53:     public function __construct($name$roles NULL$data NULL)
  54. 54:     {
  55. 55:         $this->setName($name);
  56. 56:         $this->setRoles((array) $roles);
  57. 57:         $this->data = (array) $data;
  58. 58:     }
  59. 59:  
  60. 60:  
  61. 61:  
  62. 62:     /**
  63. 63:      * Sets the name of user.
  64. 64:      * @param  string 
  65. 65:      * @return void 
  66. 66:      */
  67. 67:     public function setName($name)
  68. 68:     {
  69. 69:         $this->name = (string) $name;
  70. 70:     }
  71. 71:  
  72. 72:  
  73. 73:  
  74. 74:     /**
  75. 75:      * Returns the name of user.
  76. 76:      * @return string 
  77. 77:      */
  78. 78:     public function getName()
  79. 79:     {
  80. 80:         return $this->name;
  81. 81:     }
  82. 82:  
  83. 83:  
  84. 84:  
  85. 85:     /**
  86. 86:      * Sets a list of roles that the user is a member of.
  87. 87:      * @param  array 
  88. 88:      * @return void 
  89. 89:      */
  90. 90:     public function setRoles(array $roles)
  91. 91:     {
  92. 92:         $this->roles $roles;
  93. 93:     }
  94. 94:  
  95. 95:  
  96. 96:  
  97. 97:     /**
  98. 85: /**
  99. 86:      * Returns a list of roles that the user is a member of.
  100. 87:      * @return array 
  101. 100:      */
  102. 101:     public function getRoles()
  103. 102:     {
  104. 103:         return $this->roles;
  105. 104:     }
  106. 105:  
  107. 106:  
  108. 107:  
  109. 108:     /**
  110. 109:      * Sets user data value.
  111. 110:      * @param  string  property name
  112. 111:      * @param  mixed   property value
  113. 112:      * @return void 
  114. 113:      */
  115. 114:     public function __set($key$value)
  116. 115:     {
  117. 116:         if ($key === 'name' || $key === 'roles'{
  118. 117:             parent::__set($key$value);
  119. 118:  
  120. 119:         else {
  121. 120:             $this->data[$key$value;
  122. 121:         }
  123. 122:     }
  124. 123:  
  125. 124:  
  126. 125:  
  127. 126:     /**
  128. 127:      * Returns user data value.
  129. 128:      * @param  string  property name
  130. 129:      * @return mixed 
  131. 130:      */
  132. 131:     public function &__get($key)
  133. 132:     {
  134. 133:         if ($key === 'name' || $key === 'roles'{
  135. 134:             return parent::__get($key);
  136. 135:  
  137. 136:         else {
  138. 137:             return $this->data[$key];
  139. 138:         }
  140. 139:     }
  141. 140: