Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow cookies with same name to be added #111

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 183 additions & 221 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function getParamsValues(): array
*/
public function setParamValue(string $key, mixed $value): static
{
if (! isset($this->params[$key])) {
if (!isset($this->params[$key])) {
throw new Exception('Unknown key');
}

Expand All @@ -271,7 +271,7 @@ public function setParamValue(string $key, mixed $value): static
*/
public function getParamValue(string $key): mixed
{
if (! isset($this->params[$key])) {
if (!isset($this->params[$key])) {
throw new Exception('Unknown key');
}

Expand Down
26 changes: 13 additions & 13 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public function getSize(): int
public function getContentRangeStart(): ?int
{
$data = $this->parseContentRange();
if (! empty($data)) {
if (!empty($data)) {
return $data['start'];
} else {
return null;
Expand All @@ -444,7 +444,7 @@ public function getContentRangeStart(): ?int
public function getContentRangeEnd(): ?int
{
$data = $this->parseContentRange();
if (! empty($data)) {
if (!empty($data)) {
return $data['end'];
} else {
return null;
Expand All @@ -461,7 +461,7 @@ public function getContentRangeEnd(): ?int
public function getContentRangeSize(): ?int
{
$data = $this->parseContentRange();
if (! empty($data)) {
if (!empty($data)) {
return $data['size'];
} else {
return null;
Expand All @@ -478,7 +478,7 @@ public function getContentRangeSize(): ?int
public function getContentRangeUnit(): ?string
{
$data = $this->parseContentRange();
if (! empty($data)) {
if (!empty($data)) {
return $data['unit'];
} else {
return null;
Expand All @@ -495,7 +495,7 @@ public function getContentRangeUnit(): ?string
public function getRangeStart(): ?int
{
$data = $this->parseRange();
if (! empty($data)) {
if (!empty($data)) {
return $data['start'];
}

Expand All @@ -512,7 +512,7 @@ public function getRangeStart(): ?int
public function getRangeEnd(): ?int
{
$data = $this->parseRange();
if (! empty($data)) {
if (!empty($data)) {
return $data['end'];
}

Expand All @@ -529,7 +529,7 @@ public function getRangeEnd(): ?int
public function getRangeUnit(): ?string
{
$data = $this->parseRange();
if (! empty($data)) {
if (!empty($data)) {
return $data['unit'];
}

Expand Down Expand Up @@ -621,7 +621,7 @@ protected function generateHeaders(): array
* Fallback for older PHP versions
* that do not support generateHeaders
*/
if (! \function_exists('getallheaders')) {
if (!\function_exists('getallheaders')) {
$headers = [];

foreach ($_SERVER as $name => $value) {
Expand Down Expand Up @@ -652,7 +652,7 @@ protected function parseContentRange(): ?array
{
$contentRange = $this->getHeader('content-range', '');
$data = [];
if (! empty($contentRange)) {
if (!empty($contentRange)) {
$contentRange = explode(' ', $contentRange);
if (count($contentRange) !== 2) {
return null;
Expand All @@ -669,7 +669,7 @@ protected function parseContentRange(): ?array
return null;
}

if (! ctype_digit($rangeData[1])) {
if (!ctype_digit($rangeData[1])) {
return null;
}

Expand All @@ -679,7 +679,7 @@ protected function parseContentRange(): ?array
return null;
}

if (! ctype_digit($parts[0]) || ! ctype_digit($parts[1])) {
if (!ctype_digit($parts[0]) || !ctype_digit($parts[1])) {
return null;
}

Expand Down Expand Up @@ -721,7 +721,7 @@ protected function parseRange(): ?array
return null;
}

if (! ctype_digit($ranges[0])) {
if (!ctype_digit($ranges[0])) {
return null;
}

Expand All @@ -730,7 +730,7 @@ protected function parseRange(): ?array
if (strlen($ranges[1]) === 0) {
$data['end'] = null;
} else {
if (! ctype_digit($ranges[1])) {
if (!ctype_digit($ranges[1])) {
return null;
}
$data['end'] = (int) $ranges[1];
Expand Down
25 changes: 13 additions & 12 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Response
*/
public function __construct(float $time = 0)
{
$this->startTime = (! empty($time)) ? $time : \microtime(true);
$this->startTime = (!empty($time)) ? $time : \microtime(true);
}

/**
Expand All @@ -262,7 +262,7 @@ public function __construct(float $time = 0)
*/
public function setContentType(string $type, string $charset = ''): static
{
$this->contentType = $type.((! empty($charset) ? '; charset='.$charset : ''));
$this->contentType = $type.((!empty($charset) ? '; charset='.$charset : ''));

return $this;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public function isSent(): bool
*/
public function setStatusCode(int $code = 200): static
{
if (! \array_key_exists($code, $this->statusCodes)) {
if (!\array_key_exists($code, $this->statusCodes)) {
throw new Exception('Unknown HTTP status code');
}

Expand Down Expand Up @@ -413,7 +413,8 @@ public function getHeaders(): array
public function addCookie(string $name, string $value = null, int $expire = null, string $path = null, string $domain = null, bool $secure = null, bool $httponly = null, string $sameSite = null): static
{
$name = strtolower($name);
$this->cookies[$name] = [

$this->cookies[] = [
'name' => $name,
'value' => $value,
'expire' => $expire,
Expand All @@ -436,9 +437,9 @@ public function addCookie(string $name, string $value = null, int $expire = null
*/
public function removeCookie(string $name): static
{
if (isset($this->headers[$name])) {
unset($this->cookies[$name]);
}
$this->cookies = array_filter($this->cookies, function ($cookie) use ($name) {
return $cookie['name'] !== $name;
});

return $this;
}
Expand Down Expand Up @@ -477,7 +478,7 @@ public function send(string $body = ''): void
->appendCookies()
->appendHeaders();

if (! $this->disablePayload) {
if (!$this->disablePayload) {
$length = strlen($body);

$this->size = $this->size + strlen(implode("\n", $this->headers)) + $length;
Expand Down Expand Up @@ -524,7 +525,7 @@ protected function write(string $content): void
*/
protected function end(string $content = null): void
{
if (! is_null($content)) {
if (!is_null($content)) {
echo $content;
}
}
Expand Down Expand Up @@ -555,7 +556,7 @@ public function chunk(string $body = '', bool $end = false): void
->appendCookies()
->appendHeaders();

if (! $this->disablePayload) {
if (!$this->disablePayload) {
$this->write($body);
if ($end) {
$this->disablePayload();
Expand All @@ -578,7 +579,7 @@ protected function appendHeaders(): static
$this->sendStatus($this->statusCode);

// Send content type header
if (! empty($this->contentType)) {
if (!empty($this->contentType)) {
$this->addHeader('Content-Type', $this->contentType);
}

Expand Down Expand Up @@ -734,7 +735,7 @@ public function text(string $data): void
*/
public function json($data): void
{
if (! is_array($data) && ! $data instanceof \stdClass) {
if (!is_array($data) && !$data instanceof \stdClass) {
throw new \Exception('Invalid JSON input var');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Validator/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getValidator(): Validator
*/
public function isValid(mixed $value): bool
{
if (! \is_array($value)) {
if (!\is_array($value)) {
return false;
}

Expand All @@ -100,7 +100,7 @@ public function isValid(mixed $value): bool
}

foreach ($value as $element) {
if (! $this->validator->isValid($element)) {
if (!$this->validator->isValid($element)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Assoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getType(): string
*/
public function isValid($value): bool
{
if (! \is_array($value)) {
if (!\is_array($value)) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Validator/FloatValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public function getType(): string
public function isValid(mixed $value): bool
{
if ($this->loose) {
if (! \is_numeric($value)) {
if (!\is_numeric($value)) {
return false;
}
$value = $value + 0;
}
if (! \is_float($value) && ! \is_int($value)) {
if (!\is_float($value) && !\is_int($value)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getType(): string
public function isValid(mixed $value): bool
{
// Validate proper format
if (! \is_string($value) || empty($value)) {
if (!\is_string($value) || empty($value)) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Validator/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public function getType(): string
public function isValid(mixed $value): bool
{
if ($this->loose) {
if (! \is_numeric($value)) {
if (!\is_numeric($value)) {
return false;
}
$value = $value + 0;
}
if (! \is_int($value)) {
if (!\is_int($value)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Numeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getType(): string
*/
public function isValid(mixed $value): bool
{
if (! \is_numeric($value)) {
if (!\is_numeric($value)) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Validator/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function getType(): string
*/
public function isValid(mixed $value): bool
{
if (! parent::isValid($value)) {
if (!parent::isValid($value)) {
return false;
}

Expand All @@ -126,12 +126,12 @@ public function isValid(mixed $value): bool
break; // move to check if value is within range
}
$value = $value + 0;
if (! is_int($value)) {
if (!is_int($value)) {
return false;
}
break;
case self::TYPE_FLOAT:
if (! is_numeric($value)) {
if (!is_numeric($value)) {
return false;
}
$value = $value + 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function isValid(mixed $value): bool

if (\count($this->allowList) > 0) {
foreach (\str_split($value) as $char) {
if (! \in_array($char, $this->allowList)) {
if (!\in_array($char, $this->allowList)) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/WhiteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(array $list, bool $strict = false, string $type = se
$this->strict = $strict;
$this->type = $type;

if (! $this->strict) {
if (!$this->strict) {
foreach ($this->list as $key => &$value) {
$this->list[$key] = \strtolower($value);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public function isValid(mixed $value): bool

$value = ($this->strict) ? $value : \strtolower($value);

if (! \in_array($value, $this->list, $this->strict)) {
if (!\in_array($value, $this->list, $this->strict)) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function setParent(self $view): static
*/
public function getParent(): ?self
{
if (! empty($this->parent)) {
if (!empty($this->parent)) {
return $this->parent;
}

Expand Down Expand Up @@ -207,17 +207,17 @@ public function addFilter(string $name, callable $callback): static
*/
public function print(mixed $value, string|array $filter = ''): mixed
{
if (! empty($filter)) {
if (!empty($filter)) {
if (\is_array($filter)) {
foreach ($filter as $callback) {
if (! isset($this->filters[$callback])) {
if (!isset($this->filters[$callback])) {
throw new Exception('Filter "'.$callback.'" is not registered');
}

$value = $this->filters[$callback]($value);
}
} else {
if (! isset($this->filters[$filter])) {
if (!isset($this->filters[$filter])) {
throw new Exception('Filter "'.$filter.'" is not registered');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct()
public function call(string $method, string $path = '', array $headers = [], array $params = [])
{
usleep(50000);
$ch = curl_init($this->baseUrl.$path.(($method == self::METHOD_GET && ! empty($params)) ? '?'.http_build_query($params) : ''));
$ch = curl_init($this->baseUrl.$path.(($method == self::METHOD_GET && !empty($params)) ? '?'.http_build_query($params) : ''));
$responseHeaders = [];
$responseStatus = -1;
$responseType = '';
Expand Down