Packages

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • NIdentity
  • NPermission
  • NSimpleAuthenticator

Interfaces

  • IAuthenticator
  • IAuthorizator
  • IIdentity
  • IPermissionAssertion
  • IResource
  • IRole

Exceptions

  • NAuthenticationException
  • Overview
  • Package
  • Class
  • Tree
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Security
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Default implementation of IIdentity.
 17:  *
 18:  * @author     David Grudl
 19:  *
 20:  * @property   mixed $id
 21:  * @property   array $roles
 22:  *
 23:  * @serializationVersion 0.9.3
 24:  * @package Nette\Security
 25:  */
 26: class NIdentity extends NFreezableObject implements IIdentity
 27: {
 28:     /** @var string */
 29:     private $name;
 30: 
 31:     /** @var array */
 32:     private $roles;
 33: 
 34:     /** @var array */
 35:     private $data;
 36: 
 37: 
 38:     /**
 39:      * @param  string  identity name
 40:      * @param  mixed   roles
 41:      * @param  array   user data
 42:      */
 43:     public function __construct($name, $roles = NULL, $data = NULL)
 44:     {
 45:         $this->setName($name);
 46:         $this->setRoles((array) $roles);
 47:         $this->data = (array) $data;
 48:     }
 49: 
 50: 
 51: 
 52:     /**
 53:      * Sets the name of user.
 54:      * @param  string
 55:      * @return NIdentity  provides a fluent interface
 56:      */
 57:     public function setName($name)
 58:     {
 59:         $this->updating();
 60:         $this->name = (string) $name;
 61:         return $this;
 62:     }
 63: 
 64: 
 65: 
 66:     /**
 67:      * Returns the name of user.
 68:      * @return string
 69:      */
 70:     public function getName()
 71:     {
 72:         return $this->name;
 73:     }
 74: 
 75: 
 76: 
 77:     /**
 78:      * Sets a list of roles that the user is a member of.
 79:      * @param  array
 80:      * @return NIdentity  provides a fluent interface
 81:      */
 82:     public function setRoles(array $roles)
 83:     {
 84:         $this->updating();
 85:         $this->roles = $roles;
 86:         return $this;
 87:     }
 88: 
 89: 
 90: 
 91:     /**
 92:      * Returns a list of roles that the user is a member of.
 93:      * @return array
 94:      */
 95:     public function getRoles()
 96:     {
 97:         return $this->roles;
 98:     }
 99: 
100: 
101: 
102:     /**
103:      * Returns a user data.
104:      * @return array
105:      */
106:     public function getData()
107:     {
108:         return $this->data;
109:     }
110: 
111: 
112: 
113:     /**
114:      * Sets user data value.
115:      * @param  string  property name
116:      * @param  mixed   property value
117:      * @return void
118:      */
119:     public function __set($key, $value)
120:     {
121:         $this->updating();
122:         if (parent::__isset($key)) {
123:             parent::__set($key, $value);
124: 
125:         } else {
126:             $this->data[$key] = $value;
127:         }
128:     }
129: 
130: 
131: 
132:     /**
133:      * Returns user data value.
134:      * @param  string  property name
135:      * @return mixed
136:      */
137:     public function &__get($key)
138:     {
139:         if (parent::__isset($key)) {
140:             return parent::__get($key);
141: 
142:         } else {
143:             return $this->data[$key];
144:         }
145:     }
146: 
147: 
148: 
149:     /**
150:      * Is property defined?
151:      * @param  string  property name
152:      * @return bool
153:      */
154:     public function __isset($key)
155:     {
156:         return isset($this->data[$key]) || parent::__isset($key);
157:     }
158: 
159: 
160: 
161:     /**
162:      * Removes property.
163:      * @param  string  property name
164:      * @return void
165:      * @throws MemberAccessException
166:      */
167:     public function __unset($name)
168:     {
169:         throw new MemberAccessException("Cannot unset the property {$this->reflection->name}::\$$name.");
170:     }
171: 
172: }
173: 
Nette Framework 0.9.7 (for PHP 5.2) API documentation generated by ApiGen 2.3.0