Repository: doctrine-extensions/DoctrineExtensions (language: php)

Issue:
BlameableListener not contemplating getUserIdentifier method availability (still getUsername)
I think it would make sense that when the user is an object, the listener should expect / try to use a getUserIdentifier method on it


currently it's not: 

https://github.com/doctrine-extensions/DoctrineExtensions/blob/2def628a9a8304c1e7f56847a0b21778a3a9ed61/src/Blameable/BlameableListener.php#L48-L57


I didn't have a chance at using Blameable myself yet, so I'm not 100% sure if this actually makes sense to you, so, just ignore if I'm wrong...

but, btw, I also noticed Loggable received a similar update, in 396faefb9eef46ebdf56a9b146abae50b66b73f5 

https://github.com/doctrine-extensions/DoctrineExtensions/blob/ca2849656df9f5097a7a92fba2162fdba34c504a/src/Loggable/LoggableListener.php#L76-L87



Discussion / hints:
Hi @AlexBevilacqua, looks like you are right, feel free to create a PR with these changes.

Fix patch:
diff --git a/src/Blameable/BlameableListener.php b/src/Blameable/BlameableListener.php
index dc7d4e2aa..0b05b9104 100644
--- a/src/Blameable/BlameableListener.php
+++ b/src/Blameable/BlameableListener.php
@@ -44,8 +44,11 @@ public function getFieldValue($meta, $field, $eventAdapter)
             return $this->user;
         }
 
-        // ok so its not an association, then it is a string
+        // ok so it's not an association, then it is a string, or an object
         if (is_object($this->user)) {
+            if (method_exists($this->user, 'getUserIdentifier')) {
+                return (string) $this->user->getUserIdentifier();
+            }
             if (method_exists($this->user, 'getUsername')) {
                 return (string) $this->user->getUsername();
             }
@@ -53,7 +56,7 @@ public function getFieldValue($meta, $field, $eventAdapter)
                 return $this->user->__toString();
             }
 
-            throw new InvalidArgumentException('Field expects string, user must be a string, or object should have method getUsername or __toString');
+            throw new InvalidArgumentException('Field expects string, user must be a string, or object should have method getUserIdentifier, getUsername or __toString');
         }
 
         return $this->user;
diff --git a/src/Loggable/LoggableListener.php b/src/Loggable/LoggableListener.php
index 30e3a37fd..501c83c14 100644
--- a/src/Loggable/LoggableListener.php
+++ b/src/Loggable/LoggableListener.php
@@ -81,8 +81,10 @@ public function setUsername($username)
             $this->username = (string) $username->getUserIdentifier();
         } elseif (is_object($username) && method_exists($username, 'getUsername')) {
             $this->username = (string) $username->getUsername();
+        } elseif (is_object($username) && method_exists($username, '__toString')) {
+            $this->username = $username->__toString();
         } else {
-            throw new \Gedmo\Exception\InvalidArgumentException('Username must be a string, or object should have method: getUsername');
+            throw new \Gedmo\Exception\InvalidArgumentException('Username must be a string, or object should have method getUserIdentifier, getUsername or __toString');
         }
     }
 


Test patch: