app/library/OAuth/UserData: make all concrete classes extend UserData.
This commit is contained in:
parent
4a22f67e62
commit
43417740a7
4 changed files with 24 additions and 243 deletions
|
|
@ -2,67 +2,18 @@
|
||||||
|
|
||||||
namespace Httpcb\OAuth\UserData;
|
namespace Httpcb\OAuth\UserData;
|
||||||
|
|
||||||
class Github implements UserDataInterface
|
class Github extends UserData
|
||||||
{
|
{
|
||||||
protected $data;
|
protected $_provider = 'Github';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->_id = $data['id'];
|
||||||
}
|
$this->_username = $data['login'];
|
||||||
|
$this->_name = $data['name'];
|
||||||
/**
|
$this->_email = $data['email'];
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getProvider()
|
|
||||||
{
|
|
||||||
return 'Github';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
|
||||||
return (int) $this->data['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getUsername()
|
|
||||||
{
|
|
||||||
return $this->data['login'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
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}
|
|
||||||
*/
|
|
||||||
public function getEmail()
|
|
||||||
{
|
|
||||||
return $this->data['email'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,72 +2,18 @@
|
||||||
|
|
||||||
namespace Httpcb\OAuth\UserData;
|
namespace Httpcb\OAuth\UserData;
|
||||||
|
|
||||||
class Gitlab implements UserDataInterface
|
class Gitlab extends UserData
|
||||||
{
|
{
|
||||||
protected $data;
|
protected $_provider = 'Gitlab';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->_id = $data['id'];
|
||||||
}
|
$this->_username = $data['username'];
|
||||||
|
$this->_name = $data['name'];
|
||||||
/**
|
$this->_email = $data['email'];
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getProvider()
|
|
||||||
{
|
|
||||||
return 'Gitlab';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
|
||||||
return (int) $this->data['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getUsername()
|
|
||||||
{
|
|
||||||
return $this->data['username'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
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}
|
|
||||||
*/
|
|
||||||
public function getEmail()
|
|
||||||
{
|
|
||||||
return $this->data['email'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,76 +2,20 @@
|
||||||
|
|
||||||
namespace Httpcb\OAuth\UserData;
|
namespace Httpcb\OAuth\UserData;
|
||||||
|
|
||||||
class Google implements UserDataInterface
|
class Google extends UserData
|
||||||
{
|
{
|
||||||
protected $data;
|
protected $_provider = 'Google';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->_id = $data['id'];
|
||||||
}
|
$this->_name = $data['displayName'];
|
||||||
|
|
||||||
/**
|
if (isset($data['emails'][0]['value'])) {
|
||||||
* {@inheritDoc}
|
$this->_email = $data['emails'][0]['value'];
|
||||||
*/
|
}
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,78 +2,18 @@
|
||||||
|
|
||||||
namespace Httpcb\OAuth\UserData;
|
namespace Httpcb\OAuth\UserData;
|
||||||
|
|
||||||
class LinkedIn implements UserDataInterface
|
class LinkedIn extends UserData
|
||||||
{
|
{
|
||||||
protected $data;
|
protected $_provider = 'LinkedIn';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->_id = $data['id'];
|
||||||
}
|
$this->_firstname = isset($data['firstName']) ? $data['firstName'] : null;
|
||||||
|
$this->_lastname = isset($data['lastName']) ? $data['lastName'] : null;
|
||||||
/**
|
$this->_email = $data['emailAddress'];
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getProvider()
|
|
||||||
{
|
|
||||||
return 'LinkedIn';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
|
||||||
return $this->data['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getUsername()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
$name = '';
|
|
||||||
if ($this->getFirstname() !== null) {
|
|
||||||
$name = $this->getFirstname();
|
|
||||||
}
|
|
||||||
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}
|
|
||||||
*/
|
|
||||||
public function getEmail()
|
|
||||||
{
|
|
||||||
return $this->data['emailAddress'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue