Skip to content
Permalink
Browse files

simplified code

  • Loading branch information...
dg committed Mar 11, 2019
1 parent 7ff93fc commit 4be7cde7f650c813b650f30db0b9d480225fa379
Showing with 21 additions and 47 deletions.
  1. +2 βˆ’3 src/Http/RequestFactory.php
  2. +1 βˆ’2 src/Http/Response.php
  3. +13 βˆ’33 src/Http/Session.php
  4. +1 βˆ’5 src/Http/SessionSection.php
  5. +4 βˆ’4 src/Http/Url.php
@@ -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++);
@@ -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'];
}
@@ -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'))
) {
@@ -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]);
}
}
}
@@ -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'] ?? []));
}
@@ -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']);
}
}
@@ -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 ?? []);
}
@@ -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();

0 comments on commit 4be7cde

Please sign in to comment.
You can’t perform that action at this time.