Archived
1
0
Fork 0

app/library/OAuth/UserData/UserDataInterface.php: adding getFirstname() and getLastname()

This commit is contained in:
Henrik Hautakoski 2018-08-14 18:06:33 +02:00
parent 5d60b0f238
commit c65020fa43
No known key found for this signature in database
GPG key ID: 839F3A7EAFAEAFAA
5 changed files with 83 additions and 4 deletions

View file

@ -46,6 +46,18 @@ class Github implements UserDataInterface
return $this->data['name']; 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} * {@inheritDoc}
*/ */

View file

@ -11,6 +11,8 @@ class Gitlab implements UserDataInterface
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {
var_dump($data);exit;
$this->data = $data; $this->data = $data;
} }
@ -46,6 +48,23 @@ class Gitlab implements UserDataInterface
return $this->data['name']; 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} * {@inheritDoc}
*/ */

View file

@ -46,6 +46,24 @@ class Google implements UserDataInterface
return $this->data['displayName']; 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} * {@inheritDoc}
*/ */

View file

@ -44,15 +44,31 @@ class LinkedIn implements UserDataInterface
public function getName() public function getName()
{ {
$name = ''; $name = '';
if (isset($this->data['firstName'])) { if ($this->getFirstname() !== null) {
$name = $this->data['firstName']; $name = $this->getFirstname();
} }
if (isset($this->data['lastName'])) { if ($this->getLastname() !== null) {
$name .= ' ' . $this->data['lastName']; $name .= ' ' . $this->getLastname();
} }
return $name; 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} * {@inheritDoc}
*/ */

View file

@ -34,6 +34,20 @@ interface UserDataInterface
*/ */
public function getName(); public function getName();
/**
* First name
*
* @return string
*/
public function getFirstname();
/**
* Last name
*
* @return string
*/
public function getLastname();
/** /**
* Email address * Email address
* *