Skip to content

Commit

Permalink
Merge pull request #47 from bookboon/hotfix/case-insentive-take-2
Browse files Browse the repository at this point in the history
Implement case insensitivity through custom headers class instead
  • Loading branch information
lkm authored Feb 13, 2020
2 parents ffea700 + f0923c3 commit 8f95365
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Client/BookboonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function getStatus(): int


/**
* @return array
* @return Headers
*/
public function getHeaders() : array
public function getHeaders() : Headers
{
return $this->headers;
return new Headers($this->headers);
}

/**
Expand Down
69 changes: 67 additions & 2 deletions src/Client/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Bookboon\Api\Client;


class Headers
use ArrayAccess;

class Headers implements ArrayAccess
{
const HEADER_BRANDING = 'X-Bookboon-Branding';
const HEADER_ROTATION = 'X-Bookboon-Rotation';
Expand All @@ -14,8 +16,9 @@ class Headers

private $headers = [];

public function __construct()
public function __construct(array $headers = [])
{
$this->headers = $headers;
$this->set(static::HEADER_XFF, $this->getRemoteAddress() ?? '');
}

Expand Down Expand Up @@ -103,4 +106,66 @@ private function getRemoteAddress() : ?string

return $hostname;
}

/**
* Whether a offset exists
* @link https://php.net/manual/en/arrayaccess.offsetexists.php
* @param mixed $offset <p>
* An offset to check for.
* </p>
* @return bool true on success or false on failure.
* </p>
* <p>
* The return value will be casted to boolean if non-boolean was returned.
* @since 5.0.0
*/
public function offsetExists($offset)
{
return isset($this->headers[strtolower($offset)]);
}

/**
* Offset to retrieve
* @link https://php.net/manual/en/arrayaccess.offsetget.php
* @param mixed $offset <p>
* The offset to retrieve.
* </p>
* @return mixed Can return all value types.
* @since 5.0.0
*/
public function offsetGet($offset)
{
return $this->headers[strtolower($offset)] ?? null;
}

/**
* Offset to set
* @link https://php.net/manual/en/arrayaccess.offsetset.php
* @param mixed $offset <p>
* The offset to assign the value to.
* </p>
* @param mixed $value <p>
* The value to set.
* </p>
* @return void
* @since 5.0.0
*/
public function offsetSet($offset, $value)
{
$this->headers[strtolower($offset)] = $value;
}

/**
* Offset to unset
* @link https://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset <p>
* The offset to unset.
* </p>
* @return void
* @since 5.0.0
*/
public function offsetUnset($offset)
{
unset($this->headers[strtolower($offset)]);
}
}

0 comments on commit 8f95365

Please sign in to comment.