77 lines
1.3 KiB
PHP
77 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Httpcb\OAuth\UserData;
|
|
|
|
class Google implements UserDataInterface
|
|
{
|
|
protected $data;
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function __construct(array $data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function getProvider()
|
|
{
|
|
return 'Google';
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function getId()
|
|
{
|
|
return (int) $this->data['id'];
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function getUsername()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function getName()
|
|
{
|
|
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}
|
|
*/
|
|
public function getEmail()
|
|
{
|
|
if (isset($this->data['emails'][0]['value'])) {
|
|
return $this->data['emails'][0]['value'];
|
|
}
|
|
return null;
|
|
}
|
|
}
|