Skip to content

Commit

Permalink
Merge pull request #56 from bookboon/feature/preserve-zipkin-headers
Browse files Browse the repository at this point in the history
Feature/preserve zipkin headers
  • Loading branch information
lkm authored May 14, 2020
2 parents 64c67ea + acd701e commit 25e76c9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
32 changes: 32 additions & 0 deletions src/Client/Oauth/BookboonProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
23 changes: 13 additions & 10 deletions src/Client/Oauth/BookboonResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -88,21 +89,23 @@ 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.
*
* @return array
*/
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;
}
}
12 changes: 12 additions & 0 deletions src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 25e76c9

Please sign in to comment.