Skip to content

Commit

Permalink
simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 13, 2019
1 parent b182cea commit 26f846b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 47 deletions.
5 changes: 2 additions & 3 deletions src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function getScriptPath(Url $url): string
{
$path = $url->getPath();
$lpath = strtolower($path);
$script = isset($_SERVER['SCRIPT_NAME']) ? strtolower($_SERVER['SCRIPT_NAME']) : '';
$script = strtolower($_SERVER['SCRIPT_NAME'] ?? '');
if ($lpath !== $script) {
$max = min(strlen($lpath), strlen($script));
for ($i = 0; $i < $max && $lpath[$i] === $script[$i]; $i++);
Expand Down Expand Up @@ -238,8 +238,7 @@ private function getMethod(): ?string
$method = $_SERVER['REQUEST_METHOD'] ?? null;
if (
$method === 'POST'
&& isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])
&& preg_match('#^[A-Z]+\z#', $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])
&& preg_match('#^[A-Z]+\z#', $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ?? '')
) {
$method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ public function __destruct()
{
if (
self::$fixIE
&& isset($_SERVER['HTTP_USER_AGENT'])
&& strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false
&& strpos($_SERVER['HTTP_USER_AGENT'] ?? '', 'MSIE ') !== false
&& in_array($this->code, [400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505], true)
&& preg_match('#^text/html(?:;|$)#', (string) $this->getHeader('Content-Type'))
) {
Expand Down
46 changes: 13 additions & 33 deletions src/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,16 @@ private function initialize(): void
}
}

// process meta metadata
if (isset($nf['META'])) {
$now = time();
// expire section variables
foreach ($nf['META'] as $section => $metadata) {
if (is_array($metadata)) {
foreach ($metadata as $variable => $value) {
if (!empty($value['T']) && $now > $value['T']) {
if ($variable === '') { // expire whole section
unset($nf['META'][$section], $nf['DATA'][$section]);
continue 2;
}
unset($nf['META'][$section][$variable], $nf['DATA'][$section][$variable]);
}
// expire section variables
$now = time();
foreach ($nf['META'] ?? [] as $section => $metadata) {
foreach ($metadata ?? [] as $variable => $value) {
if (!empty($value['T']) && $now > $value['T']) {
if ($variable === '') { // expire whole section
unset($nf['META'][$section], $nf['DATA'][$section]);
continue 2;
}
unset($nf['META'][$section][$variable], $nf['DATA'][$section][$variable]);
}
}
}
Expand Down Expand Up @@ -292,12 +287,7 @@ public function getIterator(): \Iterator
$this->start();
}

if (isset($_SESSION['__NF']['DATA'])) {
return new \ArrayIterator(array_keys($_SESSION['__NF']['DATA']));

} else {
return new \ArrayIterator;
}
return new \ArrayIterator(array_keys($_SESSION['__NF']['DATA'] ?? []));
}


Expand All @@ -312,21 +302,11 @@ public function clean(): void
}

$nf = &$_SESSION['__NF'];
if (isset($nf['META']) && is_array($nf['META'])) {
foreach ($nf['META'] as $name => $foo) {
if (empty($nf['META'][$name])) {
unset($nf['META'][$name]);
}
foreach ($nf['META'] ?? [] as $name => $foo) {
if (empty($nf['META'][$name])) {
unset($nf['META'][$name]);
}
}

if (empty($nf['META'])) {
unset($nf['META']);
}

if (empty($nf['DATA'])) {
unset($nf['DATA']);
}
}


Expand Down
6 changes: 1 addition & 5 deletions src/Http/SessionSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ private function start(): void
public function getIterator(): \Iterator
{
$this->start();
if (isset($this->data)) {
return new \ArrayIterator($this->data);
} else {
return new \ArrayIterator;
}
return new \ArrayIterator($this->data ?? []);
}


Expand Down
8 changes: 4 additions & 4 deletions src/Http/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public function __construct($url = null)

$this->scheme = $p['scheme'] ?? '';
$this->port = $p['port'] ?? null;
$this->host = isset($p['host']) ? rawurldecode($p['host']) : '';
$this->user = isset($p['user']) ? rawurldecode($p['user']) : '';
$this->password = isset($p['pass']) ? rawurldecode($p['pass']) : '';
$this->host = rawurldecode($p['host'] ?? '');
$this->user = rawurldecode($p['user'] ?? '');
$this->password = rawurldecode($p['pass'] ?? '');
$this->setPath($p['path'] ?? '');
$this->setQuery($p['query'] ?? []);
$this->fragment = isset($p['fragment']) ? rawurldecode($p['fragment']) : '';
$this->fragment = rawurldecode($p['fragment'] ?? '');

} elseif ($url instanceof UrlImmutable || $url instanceof self) {
[$this->scheme, $this->user, $this->password, $this->host, $this->port, $this->path, $this->query, $this->fragment] = $url->export();
Expand Down

0 comments on commit 26f846b

Please sign in to comment.