Author: allyb
Date: 2010-02-03 17:45:39 +0100 (Wed, 03 Feb 2010)
New Revision: 27501
Modified:
plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
Log:
Credentials are now inherited from extra credentials
Modified: plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
===================================================================
--- plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
2010-02-03 16:40:12 UTC (rev 27500)
+++ plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
2010-02-03 16:45:39 UTC (rev 27501)
@@ -22,36 +22,56 @@
*/
public function getCredentials()
{
+ $credentials = $this->getInheritedCredentials(get_class($this));
+
+ // add extra credentials if they have them
+ if ($this->getHasExtraCredentials())
+ {
+ foreach ($this->getExtraCredentials() as $extraCredential)
+ {
+ $credentials = array_merge($credentials,
$this->getInheritedCredentials($extraCredential));
+ }
+ }
+
+ return $credentials;
+ }
+
+ /**
+ * Ascends the class hierarchy retrieving inherited credentials
+ *
+ * @param string $className The name of the class to ascend the hierarchy
from
+ * @return array An array of inherited credentials
+ */
+ protected function getInheritedCredentials($className)
+ {
$credentials = array();
-
+
$superClass = 'sfEasyAuthUser';
- $className = get_class($this);
// get default credentials for each parent class
do
{
+ if (strpos($className, 'sfEasyAuth') === false)
+ {
+ $className = 'sfEasyAuth' . ucfirst($className);
+ }
+
// ignore credentials that end 'Local'
if (!preg_match('/Local$/', $className))
{
$credentials[] = preg_replace('/^(.)/e', 'strtolower("$1")',
str_replace('sfEasyAuth', '', $className));
}
-
+
$userReflection = new ReflectionClass($className);
- $className = $userReflection->getParentClass()->getName();
+ $className = $userReflection->getParentClass()->getName();
} while ($className !== $superClass);
-
- // add extra credentials if they have them
- if ($this->getHasExtraCredentials())
- {
- $credentials = array_merge($credentials, $this->getExtraCredentials());
- }
return $credentials;
}
/**
* Adds an extra credential for this user
- *
+ *
* @param string $credential The name of a credential to add, e.g.
'superAdmin'
* @param int $profileId An ID of a profile to associate with this
credential (optional)
*/
@@ -69,7 +89,7 @@
}
$extraCredential->setUserId($this->getId());
-
+
// if we can save the new object, set a flag so we know the user has
extra credentials
if ($extraCredential->save())
{
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.