| @@ 115-128 (lines=14) @@ | ||
| 112 | * @return array |
|
| 113 | * @throws \Exception |
|
| 114 | */ |
|
| 115 | public function getServerById($id) { |
|
| 116 | $query = $this->connection->getQueryBuilder(); |
|
| 117 | $query->select('*')->from($this->dbTable) |
|
| 118 | ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 119 | ->setParameter('id', $id); |
|
| 120 | $query->execute(); |
|
| 121 | $result = $query->execute()->fetchAll(); |
|
| 122 | ||
| 123 | if (empty($result)) { |
|
| 124 | throw new \Exception('No Server found with ID: ' . $id); |
|
| 125 | } |
|
| 126 | ||
| 127 | return $result[0]; |
|
| 128 | } |
|
| 129 | ||
| 130 | /** |
|
| 131 | * get all trusted servers |
|
| @@ 183-197 (lines=15) @@ | ||
| 180 | * @return string |
|
| 181 | * @throws \Exception |
|
| 182 | */ |
|
| 183 | public function getToken($url) { |
|
| 184 | $hash = $this->hash($url); |
|
| 185 | $query = $this->connection->getQueryBuilder(); |
|
| 186 | $query->select('token')->from($this->dbTable) |
|
| 187 | ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 188 | ->setParameter('url_hash', $hash); |
|
| 189 | ||
| 190 | $result = $query->execute()->fetch(); |
|
| 191 | ||
| 192 | if (!isset($result['token'])) { |
|
| 193 | throw new \Exception('No token found for: ' . $url); |
|
| 194 | } |
|
| 195 | ||
| 196 | return $result['token']; |
|
| 197 | } |
|
| 198 | ||
| 199 | /** |
|
| 200 | * add shared Secret to database |
|
| @@ 869-884 (lines=16) @@ | ||
| 866 | * @param int $id |
|
| 867 | * @return string |
|
| 868 | */ |
|
| 869 | public function getCardUri($id) { |
|
| 870 | $query = $this->db->getQueryBuilder(); |
|
| 871 | $query->select('uri')->from($this->dbCardsTable) |
|
| 872 | ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 873 | ->setParameter('id', $id); |
|
| 874 | ||
| 875 | $result = $query->execute(); |
|
| 876 | $uri = $result->fetch(); |
|
| 877 | $result->closeCursor(); |
|
| 878 | ||
| 879 | if (!isset($uri['uri'])) { |
|
| 880 | throw new \InvalidArgumentException('Card does not exists: ' . $id); |
|
| 881 | } |
|
| 882 | ||
| 883 | return $uri['uri']; |
|
| 884 | } |
|
| 885 | ||
| 886 | /** |
|
| 887 | * return contact with the given URI |
|