From bb2e638599331f8548206ee8b63c4eea994b10b9 Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Thu, 14 May 2020 10:19:11 +0100 Subject: [PATCH 1/2] Preserve zipkin headers for request tracing --- src/Client/Oauth/BookboonProvider.php | 32 ++++++++++++++++++++++ src/Client/Oauth/BookboonResourceOwner.php | 23 +++++++++------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/Client/Oauth/BookboonProvider.php b/src/Client/Oauth/BookboonProvider.php index 8a8bd2a..1d2a312 100644 --- a/src/Client/Oauth/BookboonProvider.php +++ b/src/Client/Oauth/BookboonProvider.php @@ -165,4 +165,36 @@ public function getResponse(RequestInterface $request) { return $this->getHttpClient()->send($request, $this->requestOptions); } + + protected function getDefaultHeaders() + { + $headers = parent::getDefaultHeaders(); + + foreach ($this->getParentRequestHeaders() as $key => $value) { + if (stripos($key, 'x-b3-') !== false || stripos($key, 'x-request-id') !== false) { + $headers[$key] = $value; + } + } + + return $headers; + } + + protected function getParentRequestHeaders(): array + { + if (!function_exists('apache_request_headers')) { + $out = []; + + foreach ($_SERVER as $key => $value) { + if (strpos($key, "HTTP_") === 0) { + $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5))))); + $out[$key] = $value; + } else { + $out[$key] = $value; + } + } + return $out; + } + + return apache_request_headers(); + } } diff --git a/src/Client/Oauth/BookboonResourceOwner.php b/src/Client/Oauth/BookboonResourceOwner.php index ec26c8e..6c1967f 100644 --- a/src/Client/Oauth/BookboonResourceOwner.php +++ b/src/Client/Oauth/BookboonResourceOwner.php @@ -32,7 +32,8 @@ public function __construct(array $response = []) */ public function getId() { - return $this->getValueByKey($this->response, 'application.id'); + return $this->getValueByKey($this->response, 'user.id') ?? + $this->getValueByKey($this->response, 'application.id'); } /** @@ -88,14 +89,6 @@ public function getScopes() return $this->getValueByKey($this->response, 'grantedScopes'); } - /** - * @return boolean - */ - public function hasErrored() - { - return $this->getValueByKey($this->response, 'status') !== null; - } - /** * Return all of the owner details available as an array. * @@ -103,6 +96,16 @@ public function hasErrored() */ public function toArray() { - return $this->response; + $response = $this->response; + + /* Symfony roles must be prepended with "ROLE_" */ + $response['user']['roles'] = array_map( + function ($role) { + return "ROLE_$role"; + }, + $response['user']['roles'] + ); + + return $response; } } From acd701e964c79f4ee76b8695181b1f88b0b37cbd Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Thu, 14 May 2020 10:19:58 +0100 Subject: [PATCH 2/2] Add thumbnail method to category --- src/Entity/Category.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Entity/Category.php b/src/Entity/Category.php index d114978..2000b5b 100644 --- a/src/Entity/Category.php +++ b/src/Entity/Category.php @@ -178,4 +178,16 @@ public function getBooks() : array { return Book::getEntitiesFromArray($this->safeGet('books', [])); } + + /** + * Returns closes thumbnail size to input, default 210px. + * + * @param int $size appromimate size + * + * @return string url for thumbnail + */ + public function getThumbnail(int $size = 210) + { + return $this->thumbnailResolver($this->safeGet('thumbnail', []), $size); + } }