Skip to content

Commit 5202dcf

Browse files
committed
eh
1 parent a1cdab5 commit 5202dcf

File tree

6 files changed

+61
-36
lines changed

6 files changed

+61
-36
lines changed

src/SonsOfPHP/Component/Cache/Adapter/FilesystemAdapter.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public function __construct(
3333
}
3434

3535
if (!is_dir($this->directory)) {
36-
@mkdir($this->directory, $this->defaultPermission, true);
36+
if (!mkdir($this->directory, $this->defaultPermission, true) && !is_dir($this->directory)) {
37+
throw new \RuntimeException(sprintf('Directory "%s" could not be created', $this->directory));
38+
}
3739
}
3840

3941
$this->directory .= \DIRECTORY_SEPARATOR;
@@ -134,7 +136,12 @@ private function getFile(string $key): string
134136
{
135137
$hash = str_replace('/', '-', base64_encode(hash('xxh128', self::class . $key, true)));
136138
$dir = $this->directory . strtoupper($hash[0] . \DIRECTORY_SEPARATOR . $hash[1] . \DIRECTORY_SEPARATOR);
137-
@mkdir($dir, $this->defaultPermission, true);
139+
140+
if (!is_dir($dir)) {
141+
if (!mkdir($dir, $this->defaultPermission, true) && !is_dir($dir)) {
142+
throw new \RuntimeException(sprintf('Cache directory "%s" could not be created', $dir));
143+
}
144+
}
138145

139146
return $dir . substr($hash, 2, 20);
140147
}

src/SonsOfPHP/Component/HttpMessage/Message.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ public function withHeader(string $name, $value): MessageInterface
100100
$value = [$value];
101101
}
102102

103-
$that->normalizedHeaders[$name] = $value;
104-
105-
array_walk($value, function (&$val, $key): void {
106-
$val = strtolower($val);
107-
});
108-
$that->headers[strtolower($name)] = $value;
103+
$that->headers[$name] = $value;
104+
$that->normalizedHeaders[strtolower($name)] = $value;
109105

110106
return $that;
111107
}
@@ -128,13 +124,13 @@ public function withAddedHeader(string $name, $value): MessageInterface
128124
}
129125

130126
$that = clone $this;
131-
$that->normalizedHeaders[$name][] = $value;
132127

133-
$values = $value;
134-
array_walk($values, function (&$val, $key): void {
135-
$val = strtolower($val);
136-
});
137-
$that->headers[strtolower($name)][] = $value;
128+
$normalizedName = strtolower($name);
129+
$existingValues = $that->normalizedHeaders[$normalizedName] ?? [];
130+
$mergedValues = array_merge($existingValues, $value);
131+
132+
$that->headers[$name] = $mergedValues;
133+
$that->normalizedHeaders[$normalizedName] = $mergedValues;
138134

139135
return $that;
140136
}

src/SonsOfPHP/Component/HttpMessage/Response.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414
*/
1515
class Response extends Message implements ResponseInterface
1616
{
17-
private int $statusCode;
17+
private int $statusCode = 200;
1818

1919
private string $reasonPhrase = '';
2020

21+
public function __construct(int $statusCode = 200, string $reasonPhrase = '')
22+
{
23+
if (!Status::tryFrom($statusCode) instanceof Status) {
24+
throw new InvalidArgumentException(sprintf('The status code "%d" is invalid', $statusCode));
25+
}
26+
27+
$this->statusCode = $statusCode;
28+
$this->reasonPhrase = $reasonPhrase;
29+
}
30+
2131
/**
2232
* {@inheritdoc}
2333
*/
@@ -35,7 +45,7 @@ public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterf
3545
throw new InvalidArgumentException(sprintf('The status code "%d" is invalid', $code));
3646
}
3747

38-
if (isset($this->statusCode) && $this->statusCode === $code && $this->reasonPhrase === $reasonPhrase) {
48+
if ($this->statusCode === $code && $this->reasonPhrase === $reasonPhrase) {
3949
return $this;
4050
}
4151

src/SonsOfPHP/Component/HttpMessage/Status.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,28 @@ enum Status: int
8282
case NOT_EXTENDED = 510;
8383
case NETWORK_AUTHENTICATION_REQUIRED = 511;
8484

85-
//public function isInformational(): bool
86-
//{
87-
//}
85+
public function isInformational(): bool
86+
{
87+
return $this->value >= 100 && $this->value < 200;
88+
}
8889

89-
//public function isSuccessful(): bool
90-
//{
91-
//}
90+
public function isSuccessful(): bool
91+
{
92+
return $this->value >= 200 && $this->value < 300;
93+
}
9294

93-
//public function isRedirection(): bool
94-
//{
95-
//}
95+
public function isRedirection(): bool
96+
{
97+
return $this->value >= 300 && $this->value < 400;
98+
}
9699

97-
//public function isClientError(): bool
98-
//{
99-
//}
100+
public function isClientError(): bool
101+
{
102+
return $this->value >= 400 && $this->value < 500;
103+
}
100104

101-
//public function isServerError(): bool
102-
//{
103-
//}
105+
public function isServerError(): bool
106+
{
107+
return $this->value >= 500 && $this->value < 600;
108+
}
104109
}

src/SonsOfPHP/Component/HttpMessage/Uri.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
$this->path = $parts['path'] ?? null;
4545
$this->fragment = $parts['fragment'] ?? null;
4646

47-
if (isset($parts['query']) && ($parts['query'] !== '' && $parts['query'] !== '0')) {
47+
if (isset($parts['query']) && $parts['query'] !== '') {
4848
parse_str($parts['query'], $this->queryParams);
4949
}
5050
}
@@ -124,8 +124,6 @@ public function getPath(): string
124124
*/
125125
public function getQuery(): string
126126
{
127-
//return http_build_query($this->queryParams, '', null, \PHP_QUERY_RFC3986);
128-
129127
$query = '';
130128
foreach ($this->queryParams as $key => $value) {
131129
if (is_array($value)) {
@@ -256,8 +254,6 @@ public function withQuery(string $query): UriInterface
256254
parse_str($query, $output);
257255

258256
$that = clone $this;
259-
260-
//$that->query = $query;
261257
$that->queryParams = $output;
262258

263259
return $that;

src/SonsOfPHP/Component/Logger/Handler/FileHandler.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ private function open(): void
4242
return;
4343
}
4444

45+
$dir = dirname($this->filename);
46+
if (!is_dir($dir)) {
47+
if (!mkdir($dir, 0o777, true) && !is_dir($dir)) {
48+
throw new RuntimeException(sprintf('Log directory "%s" could not be created', $dir));
49+
}
50+
}
51+
52+
if (!is_writable($dir)) {
53+
throw new RuntimeException(sprintf('Log directory "%s" is not writable', $dir));
54+
}
55+
4556
if (false === $this->handle = fopen($this->filename, 'a')) {
4657
throw new RuntimeException(sprintf('"%s" could not be opened', $this->filename));
4758
}

0 commit comments

Comments
 (0)