Skip to content

Commit e50d2d1

Browse files
authored
Merge pull request #111 from utopia-php/0.31.x
fix: allow cookies with same name to be added
2 parents 702c945 + 32e18af commit e50d2d1

File tree

15 files changed

+231
-268
lines changed

15 files changed

+231
-268
lines changed

composer.lock

Lines changed: 183 additions & 221 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Hook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function getParamsValues(): array
252252
*/
253253
public function setParamValue(string $key, mixed $value): static
254254
{
255-
if (! isset($this->params[$key])) {
255+
if (!isset($this->params[$key])) {
256256
throw new Exception('Unknown key');
257257
}
258258

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

src/Request.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public function getSize(): int
427427
public function getContentRangeStart(): ?int
428428
{
429429
$data = $this->parseContentRange();
430-
if (! empty($data)) {
430+
if (!empty($data)) {
431431
return $data['start'];
432432
} else {
433433
return null;
@@ -444,7 +444,7 @@ public function getContentRangeStart(): ?int
444444
public function getContentRangeEnd(): ?int
445445
{
446446
$data = $this->parseContentRange();
447-
if (! empty($data)) {
447+
if (!empty($data)) {
448448
return $data['end'];
449449
} else {
450450
return null;
@@ -461,7 +461,7 @@ public function getContentRangeEnd(): ?int
461461
public function getContentRangeSize(): ?int
462462
{
463463
$data = $this->parseContentRange();
464-
if (! empty($data)) {
464+
if (!empty($data)) {
465465
return $data['size'];
466466
} else {
467467
return null;
@@ -478,7 +478,7 @@ public function getContentRangeSize(): ?int
478478
public function getContentRangeUnit(): ?string
479479
{
480480
$data = $this->parseContentRange();
481-
if (! empty($data)) {
481+
if (!empty($data)) {
482482
return $data['unit'];
483483
} else {
484484
return null;
@@ -495,7 +495,7 @@ public function getContentRangeUnit(): ?string
495495
public function getRangeStart(): ?int
496496
{
497497
$data = $this->parseRange();
498-
if (! empty($data)) {
498+
if (!empty($data)) {
499499
return $data['start'];
500500
}
501501

@@ -512,7 +512,7 @@ public function getRangeStart(): ?int
512512
public function getRangeEnd(): ?int
513513
{
514514
$data = $this->parseRange();
515-
if (! empty($data)) {
515+
if (!empty($data)) {
516516
return $data['end'];
517517
}
518518

@@ -529,7 +529,7 @@ public function getRangeEnd(): ?int
529529
public function getRangeUnit(): ?string
530530
{
531531
$data = $this->parseRange();
532-
if (! empty($data)) {
532+
if (!empty($data)) {
533533
return $data['unit'];
534534
}
535535

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

627627
foreach ($_SERVER as $name => $value) {
@@ -652,7 +652,7 @@ protected function parseContentRange(): ?array
652652
{
653653
$contentRange = $this->getHeader('content-range', '');
654654
$data = [];
655-
if (! empty($contentRange)) {
655+
if (!empty($contentRange)) {
656656
$contentRange = explode(' ', $contentRange);
657657
if (count($contentRange) !== 2) {
658658
return null;
@@ -669,7 +669,7 @@ protected function parseContentRange(): ?array
669669
return null;
670670
}
671671

672-
if (! ctype_digit($rangeData[1])) {
672+
if (!ctype_digit($rangeData[1])) {
673673
return null;
674674
}
675675

@@ -679,7 +679,7 @@ protected function parseContentRange(): ?array
679679
return null;
680680
}
681681

682-
if (! ctype_digit($parts[0]) || ! ctype_digit($parts[1])) {
682+
if (!ctype_digit($parts[0]) || !ctype_digit($parts[1])) {
683683
return null;
684684
}
685685

@@ -721,7 +721,7 @@ protected function parseRange(): ?array
721721
return null;
722722
}
723723

724-
if (! ctype_digit($ranges[0])) {
724+
if (!ctype_digit($ranges[0])) {
725725
return null;
726726
}
727727

@@ -730,7 +730,7 @@ protected function parseRange(): ?array
730730
if (strlen($ranges[1]) === 0) {
731731
$data['end'] = null;
732732
} else {
733-
if (! ctype_digit($ranges[1])) {
733+
if (!ctype_digit($ranges[1])) {
734734
return null;
735735
}
736736
$data['end'] = (int) $ranges[1];

src/Response.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class Response
249249
*/
250250
public function __construct(float $time = 0)
251251
{
252-
$this->startTime = (! empty($time)) ? $time : \microtime(true);
252+
$this->startTime = (!empty($time)) ? $time : \microtime(true);
253253
}
254254

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

267267
return $this;
268268
}
@@ -300,7 +300,7 @@ public function isSent(): bool
300300
*/
301301
public function setStatusCode(int $code = 200): static
302302
{
303-
if (! \array_key_exists($code, $this->statusCodes)) {
303+
if (!\array_key_exists($code, $this->statusCodes)) {
304304
throw new Exception('Unknown HTTP status code');
305305
}
306306

@@ -413,7 +413,8 @@ public function getHeaders(): array
413413
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
414414
{
415415
$name = strtolower($name);
416-
$this->cookies[$name] = [
416+
417+
$this->cookies[] = [
417418
'name' => $name,
418419
'value' => $value,
419420
'expire' => $expire,
@@ -436,9 +437,9 @@ public function addCookie(string $name, string $value = null, int $expire = null
436437
*/
437438
public function removeCookie(string $name): static
438439
{
439-
if (isset($this->headers[$name])) {
440-
unset($this->cookies[$name]);
441-
}
440+
$this->cookies = array_filter($this->cookies, function ($cookie) use ($name) {
441+
return $cookie['name'] !== $name;
442+
});
442443

443444
return $this;
444445
}
@@ -477,7 +478,7 @@ public function send(string $body = ''): void
477478
->appendCookies()
478479
->appendHeaders();
479480

480-
if (! $this->disablePayload) {
481+
if (!$this->disablePayload) {
481482
$length = strlen($body);
482483

483484
$this->size = $this->size + strlen(implode("\n", $this->headers)) + $length;
@@ -524,7 +525,7 @@ protected function write(string $content): void
524525
*/
525526
protected function end(string $content = null): void
526527
{
527-
if (! is_null($content)) {
528+
if (!is_null($content)) {
528529
echo $content;
529530
}
530531
}
@@ -555,7 +556,7 @@ public function chunk(string $body = '', bool $end = false): void
555556
->appendCookies()
556557
->appendHeaders();
557558

558-
if (! $this->disablePayload) {
559+
if (!$this->disablePayload) {
559560
$this->write($body);
560561
if ($end) {
561562
$this->disablePayload();
@@ -578,7 +579,7 @@ protected function appendHeaders(): static
578579
$this->sendStatus($this->statusCode);
579580

580581
// Send content type header
581-
if (! empty($this->contentType)) {
582+
if (!empty($this->contentType)) {
582583
$this->addHeader('Content-Type', $this->contentType);
583584
}
584585

@@ -734,7 +735,7 @@ public function text(string $data): void
734735
*/
735736
public function json($data): void
736737
{
737-
if (! is_array($data) && ! $data instanceof \stdClass) {
738+
if (!is_array($data) && !$data instanceof \stdClass) {
738739
throw new \Exception('Invalid JSON input var');
739740
}
740741

src/Validator/ArrayList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getValidator(): Validator
9191
*/
9292
public function isValid(mixed $value): bool
9393
{
94-
if (! \is_array($value)) {
94+
if (!\is_array($value)) {
9595
return false;
9696
}
9797

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

102102
foreach ($value as $element) {
103-
if (! $this->validator->isValid($element)) {
103+
if (!$this->validator->isValid($element)) {
104104
return false;
105105
}
106106
}

src/Validator/Assoc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getType(): string
5757
*/
5858
public function isValid($value): bool
5959
{
60-
if (! \is_array($value)) {
60+
if (!\is_array($value)) {
6161
return false;
6262
}
6363

src/Validator/FloatValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public function getType(): string
7474
public function isValid(mixed $value): bool
7575
{
7676
if ($this->loose) {
77-
if (! \is_numeric($value)) {
77+
if (!\is_numeric($value)) {
7878
return false;
7979
}
8080
$value = $value + 0;
8181
}
82-
if (! \is_float($value) && ! \is_int($value)) {
82+
if (!\is_float($value) && !\is_int($value)) {
8383
return false;
8484
}
8585

src/Validator/Hostname.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getType(): string
6262
public function isValid(mixed $value): bool
6363
{
6464
// Validate proper format
65-
if (! \is_string($value) || empty($value)) {
65+
if (!\is_string($value) || empty($value)) {
6666
return false;
6767
}
6868

src/Validator/Integer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public function getType(): string
7474
public function isValid(mixed $value): bool
7575
{
7676
if ($this->loose) {
77-
if (! \is_numeric($value)) {
77+
if (!\is_numeric($value)) {
7878
return false;
7979
}
8080
$value = $value + 0;
8181
}
82-
if (! \is_int($value)) {
82+
if (!\is_int($value)) {
8383
return false;
8484
}
8585

src/Validator/Numeric.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getType(): string
5757
*/
5858
public function isValid(mixed $value): bool
5959
{
60-
if (! \is_numeric($value)) {
60+
if (!\is_numeric($value)) {
6161
return false;
6262
}
6363

0 commit comments

Comments
 (0)