diff --git a/app/library/OAuth/UserData/Github.php b/app/library/OAuth/UserData/Github.php index d8b4d13..a465770 100644 --- a/app/library/OAuth/UserData/Github.php +++ b/app/library/OAuth/UserData/Github.php @@ -46,6 +46,18 @@ class Github implements UserDataInterface return $this->data['name']; } + public function getFirstname() + { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), 0, $pos) : $this->getName(); + } + + public function getLastname() + { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), $pos+1) : null; + } + /** * {@inheritDoc} */ diff --git a/app/library/OAuth/UserData/Gitlab.php b/app/library/OAuth/UserData/Gitlab.php index 697747a..a0b4770 100644 --- a/app/library/OAuth/UserData/Gitlab.php +++ b/app/library/OAuth/UserData/Gitlab.php @@ -11,6 +11,8 @@ class Gitlab implements UserDataInterface */ public function __construct(array $data) { + var_dump($data);exit; + $this->data = $data; } @@ -46,6 +48,23 @@ class Gitlab implements UserDataInterface return $this->data['name']; } + /** + * {@inheritDoc} + */ + public function getFirstname() + { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), 0, $pos) : $this->getName(); + } + + /** + * {@inheritDoc} + */ + public function getLastname() + { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), $pos+1) : null; + } /** * {@inheritDoc} */ diff --git a/app/library/OAuth/UserData/Google.php b/app/library/OAuth/UserData/Google.php index 86a80ab..28aa7a1 100644 --- a/app/library/OAuth/UserData/Google.php +++ b/app/library/OAuth/UserData/Google.php @@ -46,6 +46,24 @@ class Google implements UserDataInterface return $this->data['displayName']; } + /** + * {@inheritDoc} + */ + public function getFirstname() + { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), 0, $pos) : $this->getName(); + } + + /** + * {@inheritDoc} + */ + public function getLastname() + { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), $pos+1) : null; + } + /** * {@inheritDoc} */ diff --git a/app/library/OAuth/UserData/LinkedIn.php b/app/library/OAuth/UserData/LinkedIn.php index 60b6e4f..0907453 100644 --- a/app/library/OAuth/UserData/LinkedIn.php +++ b/app/library/OAuth/UserData/LinkedIn.php @@ -44,15 +44,31 @@ class LinkedIn implements UserDataInterface public function getName() { $name = ''; - if (isset($this->data['firstName'])) { - $name = $this->data['firstName']; + if ($this->getFirstname() !== null) { + $name = $this->getFirstname(); } - if (isset($this->data['lastName'])) { - $name .= ' ' . $this->data['lastName']; + if ($this->getLastname() !== null) { + $name .= ' ' . $this->getLastname(); } return $name; } + /** + * {@inheritDoc} + */ + public function getFirstname() + { + return isset($this->data['firstName']) ? $this->data['firstName'] : null; + } + + /** + * {@inheritDoc} + */ + public function getLastname() + { + return isset($this->data['lastName']) ? $this->data['lastName'] : null; + } + /** * {@inheritDoc} */ diff --git a/app/library/OAuth/UserData/UserDataInterface.php b/app/library/OAuth/UserData/UserDataInterface.php index cf489a3..456b72d 100644 --- a/app/library/OAuth/UserData/UserDataInterface.php +++ b/app/library/OAuth/UserData/UserDataInterface.php @@ -34,6 +34,20 @@ interface UserDataInterface */ public function getName(); + /** + * First name + * + * @return string + */ + public function getFirstname(); + + /** + * Last name + * + * @return string + */ + public function getLastname(); + /** * Email address *