From 4a22f67e62c198d4785909b5138b4152c4466447 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 14 Aug 2018 22:32:51 +0200 Subject: [PATCH] adding app/library/OAuth/UserData/UserData.php --- app/library/OAuth/UserData/UserData.php | 104 ++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 app/library/OAuth/UserData/UserData.php diff --git a/app/library/OAuth/UserData/UserData.php b/app/library/OAuth/UserData/UserData.php new file mode 100644 index 0000000..00ba85c --- /dev/null +++ b/app/library/OAuth/UserData/UserData.php @@ -0,0 +1,104 @@ +_provider; + } + + /** + * {@inheritDoc} + */ + public function getId() + { + return $this->_id; + } + + /** + * {@inheritDoc} + */ + public function getUsername() + { + return $this->_username; + } + + /** + * {@inheritDoc} + */ + public function getName() + { + if ($this->_name === null && strlen($this->_firstname) > 0) { + $name = $this->_firstname; + if (strlen($this->_lastname) > 0) { + $name .= ' ' . $this->_lastname; + } + return $name; + } + return $this->_name; + } + + /** + * {@inheritDoc} + */ + public function getFirstname() + { + if ($this->_firstname === null) { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), 0, $pos) : $this->getName(); + + } + return $this->_firstname; + } + + /** + * {@inheritDoc} + */ + public function getLastname() + { + if ($this->_lastname === null) { + $pos = strpos($this->getName(), ' '); + return $pos !== false ? substr($this->getName(), $pos+1) : null; + } + return $this->_lastname; + } + + /** + * {@inheritDoc} + */ + public function getEmail() + { + return $this->_email; + } + + public function toArray() + { + $data = []; + foreach(get_class_methods($this) as $method) { + if (substr($method, 0, 3) == 'get') { + $field = lcfirst(substr($method, 3)); + $data[$field] = $this->$method(); + } + } + return $data; + } +}