Skip to content

Commit d928a2d

Browse files
committed
chore: small changes
1 parent 65fb6bf commit d928a2d

8 files changed

Lines changed: 22 additions & 44 deletions

File tree

system/foundation/http/cookie.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom
7070
public function __toString()
7171
{
7272
$str = urlencode($this->getName()) . '=';
73-
74-
if ('' === (string) $this->getValue()) {
75-
$str .= 'deleted; expires=' . gmdate('D, d-M-Y H:i:s T', time() - 31536001);
76-
} else {
77-
$str .= urlencode($this->getValue()) . ((0 !== $this->getExpiresTime()) ? '; expires=' . gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime()) : '');
78-
}
79-
73+
$str .= ('' === (string) $this->getValue())
74+
? 'deleted; expires=' . gmdate('D, d-M-Y H:i:s T', time() - 31536001)
75+
: urlencode($this->getValue()) . ((0 !== $this->getExpiresTime()) ? '; expires=' . gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime()) : '');
8076
$str .= ('/' !== $this->path) ? '; path=' . $this->path : '';
8177
$str .= (null !== $this->getSameSite()) ? '; samesite=' . $this->getSameSite() : '';
8278
$str .= (null !== $this->getDomain()) ? '; domain=' . $this->getDomain() : '';

system/foundation/http/file.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ protected function convertFileInformation($file)
6767
if (is_array($file)) {
6868
$keys = array_keys($file);
6969
sort($keys);
70-
71-
if ($keys === self::$fileKeys) {
72-
$file = (UPLOAD_ERR_NO_FILE !== $file['error']) ? new Upload($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']) : null;
73-
} else {
74-
$file = array_map([$this, 'convertFileInformation'], $file);
75-
}
70+
$file = ($keys === self::$fileKeys)
71+
? ((UPLOAD_ERR_NO_FILE !== $file['error']) ? new Upload($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']) : null)
72+
: array_map([$this, 'convertFileInformation'], $file);
7673
}
7774

7875
return $file;

system/foundation/http/header.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,9 @@ public function add(array $headers)
107107
public function get($key, $default = null, $first = true)
108108
{
109109
$key = $this->standardizeKey($key);
110-
111-
if (!array_key_exists($key, $this->headers)) {
112-
return (null === $default) ? ($first ? null : []) : ($first ? $default : [$default]);
113-
}
114-
115-
return $first ? (count($this->headers[$key]) ? $this->headers[$key][0] : $default) : $this->headers[$key];
110+
return array_key_exists($key, $this->headers)
111+
? ($first ? (count($this->headers[$key]) ? $this->headers[$key][0] : $default) : $this->headers[$key])
112+
: ((null === $default) ? ($first ? null : []) : ($first ? $default : [$default]));
116113
}
117114

118115
/**
@@ -142,8 +139,7 @@ public function set($key, $values, $replace = true)
142139
*/
143140
public function has($key)
144141
{
145-
$key = $this->standardizeKey($key);
146-
return array_key_exists($key, $this->headers);
142+
return array_key_exists($this->standardizeKey($key), $this->headers);
147143
}
148144

149145
/**

system/foundation/http/helper.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,8 @@ protected function computeCacheControlValue()
235235
}
236236

237237
$header = $this->getCacheControlHeader();
238-
239-
if (isset($this->cacheControl['public']) || isset($this->cacheControl['private'])) {
240-
return $header;
241-
}
242-
243-
return isset($this->cacheControl['s-maxage']) ? $header : $header . ', private';
238+
return (isset($this->cacheControl['public']) || isset($this->cacheControl['private']))
239+
? $header
240+
: (isset($this->cacheControl['s-maxage']) ? $header : $header . ', private');
244241
}
245242
}

system/foundation/http/request.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ public static function createFromGlobals()
106106
$httpType = (string) $request->server->get('HTTP_CONTENT_TYPE');
107107
$method = (string) $request->server->get('REQUEST_METHOD', 'GET');
108108

109-
if ((0 === strpos($type, 'application/x-www-form-urlencoded')
110-
|| (0 === strpos($httpType, 'application/x-www-form-urlencoded')))
111-
&& in_array(strtoupper($method), ['PUT', 'DELETE', 'PATCH'])
112-
) {
109+
if ((0 === strpos($type, 'application/x-www-form-urlencoded') || (0 === strpos($httpType, 'application/x-www-form-urlencoded')))
110+
&& in_array(strtoupper($method), ['PUT', 'DELETE', 'PATCH'])) {
113111
parse_str($request->getContent(), $data);
114112
$request->request = new Parameter($data);
115113
}
@@ -1305,12 +1303,8 @@ private function setPhpDefaultLocale($locale)
13051303
private function getUrlencodedPrefix($string, $prefix)
13061304
{
13071305
$prefix = (string) $prefix;
1308-
1309-
if (!$prefix || 0 !== strpos((string) rawurldecode($string), $prefix)) {
1310-
return false;
1311-
}
1312-
1313-
$len = mb_strlen($prefix, '8bit');
1314-
return preg_match('#^(%[[:xdigit:]]{2}|.){' . $len . '}#', $string, $match) ? $match[0] : false;
1306+
return (!$prefix || 0 !== strpos((string) rawurldecode($string), $prefix))
1307+
? false
1308+
: (preg_match('#^(%[[:xdigit:]]{2}|.){' . mb_strlen($prefix, '8bit') . '}#', $string, $match) ? $match[0] : false);
13151309
}
13161310
}

system/foundation/http/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getHeaders()
3030
$headers['PHP_AUTH_PW'] = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : '';
3131
} else {
3232
/**
33-
* B default, php-cgi under apache eill not pass Basic Auth's user and password
33+
* By default, php-cgi under apache eill not pass Basic Auth's user and password
3434
* To resolve this, add this rules to your .htaccess file:
3535
*
3636
* RewriteCond %{HTTP:Authorization} ^(.+)$

system/foundation/http/upload.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,9 @@ protected function getTargetFile($directory, $name = null)
926926
*/
927927
protected function getName($name)
928928
{
929-
$original = str_replace('\\', '/', (string) $name);
930-
$position = strrpos($original, '/');
931-
$original = (false === $position) ? $original : substr($original, $position + 1);
932-
return $original;
929+
$name = str_replace('\\', '/', (string) $name);
930+
$position = strrpos($name, '/');
931+
return (false === $position) ? $name : substr($name, $position + 1);
933932
}
934933

935934
/**
@@ -1004,7 +1003,6 @@ public function move($directory, $name = null)
10041003
}
10051004

10061005
@chmod($target, 0666 & ~umask());
1007-
10081006
return $target;
10091007
} elseif (is_uploaded_file($this->getPathname())) {
10101008
if (false === @move_uploaded_file($this->getPathname(), $target)) {
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)