PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Nette/Security/Identity.php

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