Fixed a bug in Pivip_Auth_Identity.
[pivip.git] / project / library / Pivip / Auth / Identity.php
blob5f80e4a9f7fddfc73bc4ec6b5106c659df01d518
1 <?php
3 /**
4 * Pivip
5 * Copyright (C) 2008 Vincent Tunru
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @license http://www.fsf.org/licensing/licenses/info/GPLv2.html GPL v.2
21 * @category Pivip
22 * @package Pivip
23 * @copyright (C) 2008 Vincent Tunru
24 * @author Vincent Tunru <email@vincentt.org>
27 /**
28 * Retrieve a visitor's details
30 * When a visitor logs in, the authentication method can save the visitor's
31 * details in this object which can then be retrieved whenever a module needs
32 * them.
34 * @link http://www.ietf.org/rfc/rfc2426.txt RFC 2426, vCard MIME Directory
35 * profile.
37 class Pivip_Auth_Identity
39 /**
40 * @var array Identity properties
42 private $_properties;
44 /**
45 * Add the required data (id, fn) and, optionally, additional data
47 * @param Pivip_Auth_Identity_Property $uid Identifier, mostly the key
48 * used in the database.
49 * @param Pivip_Auth_Identity_Property $aclRole Role (used to determine
50 * rights in ACL).
51 * @param Pivip_Auth_Identity_Property $fn Name of the person this
52 * identity belongs to.
53 * Examples:
54 * "Drs. P."
55 * "Heinz Hermann Polzer".
56 * @param array $properties Any additional properties.
57 * @throws InvalidArgumentException
59 public function __construct(Pivip_Auth_Identity_Property $uid,
60 Pivip_Auth_Identity_Property $aclRole,
61 Pivip_Auth_Identity_Property $fn,
62 array $properties)
64 $this->_properties = array('uid' => $uid, 'aclRole' => $aclRole,
65 'fn' => $fn);
66 foreach($properties as $key => $property)
68 if($property instanceof Pivip_Auth_Identity_Property)
70 $this->_properties[$key] = $property;
75 /**
76 * Convert the class to a string
78 * @return string String representation of this class
80 public function __toString()
82 return $this->_properties['uid']->value;
85 /**
86 * Retrieve identity properties
88 * @param string $property Name of the property to retrieve.
89 * @return Pivip_Auth_Identity_Property The property
91 public function __get($property)
93 if('acl_role' == $property)
95 $property = 'aclRole';
97 return $this->_properties[$property];
101 * Set a property of the identity
103 * @param string $property Name of the property to set
104 * @param Pivip_Auth_Identity_Property $value Value of the property
105 * @return Pivip_Auth_Identity_Property The property
107 public function __set($property, Pivip_Auth_Identity_Property $value)
109 $this->_properties[$property] = $value;
110 return $this->_properties[$property];
114 * Check whether a property is set
116 * @param string $property Name of the property to check
117 * @return boolean Whether the property is set.
119 public function __isset($property)
121 if('acl_role' == $property)
123 $property = 'aclRole';
125 return isset($this->_properties[$property]);
129 * Unset a property
131 * @param string $property Name of the property to unset
132 * @return void
134 public function __unset($property)
136 if('acl_role' == $property)
138 $property = 'aclRole';
140 unset($this->_properties[$property]);