Bug fixes

This commit is contained in:
Dennis Eichhorn 2018-11-23 11:35:42 +01:00
parent 8c3392253f
commit 9945dbc373
12 changed files with 45 additions and 42 deletions

View File

@ -269,9 +269,9 @@ abstract class GrammarAbstract
*/ */
protected function compileSystem(string $system, string $prefix = '') : string protected function compileSystem(string $system, string $prefix = '') : string
{ {
// todo: this is a bad way to handle select \count(*) which doesn't need a prefix. Maybe remove prefixes in total?
$identifier = $this->systemIdentifier; $identifier = $this->systemIdentifier;
// todo: this is a bad way to handle select \count(*) which doesn't need a prefix. Maybe remove prefixes in total?
foreach ($this->specialKeywords as $keyword) { foreach ($this->specialKeywords as $keyword) {
if (\strrpos($system, $keyword, -\strlen($system)) !== false) { if (\strrpos($system, $keyword, -\strlen($system)) !== false) {
$prefix = ''; $prefix = '';
@ -279,7 +279,6 @@ abstract class GrammarAbstract
} }
} }
// todo: move remaining * test also here not just if .* but also if * (should be done in else?)
if (\count($split = \explode('.', $system)) > 1) { if (\count($split = \explode('.', $system)) > 1) {
$fullSystem = ''; $fullSystem = '';

View File

@ -37,7 +37,7 @@ class HttpSession implements SessionInterface
* @var bool * @var bool
* @since 1.0.0 * @since 1.0.0
*/ */
private static $isLocked = false; private $isLocked = false;
/** /**
* Raw session data. * Raw session data.
@ -76,7 +76,7 @@ class HttpSession implements SessionInterface
*/ */
public function __construct(int $liftetime = 3600, $sid = false, int $inactivityInterval = 0) public function __construct(int $liftetime = 3600, $sid = false, int $inactivityInterval = 0)
{ {
if (self::$isLocked) { if ($this->isLocked) {
throw new LockException('HttpSession'); throw new LockException('HttpSession');
} }
@ -153,7 +153,7 @@ class HttpSession implements SessionInterface
*/ */
public function lock() : void public function lock() : void
{ {
self::$isLocked = true; $this->isLocked = true;
} }
/** /**
@ -163,9 +163,9 @@ class HttpSession implements SessionInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function isLocked() : bool public function isLocked() : bool
{ {
return self::$isLocked; return $this->isLocked;
} }
/** /**
@ -173,7 +173,7 @@ class HttpSession implements SessionInterface
*/ */
public function save() : void public function save() : void
{ {
if (!self::$isLocked) { if (!$this->isLocked) {
$_SESSION = $this->sessionData; $_SESSION = $this->sessionData;
\session_write_close(); \session_write_close();
} }

View File

@ -42,15 +42,6 @@ final class EventManager
*/ */
private $callbacks = []; private $callbacks = [];
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
}
/** /**
* Attach new event * Attach new event
* *
@ -96,7 +87,6 @@ final class EventManager
} }
if (!$this->hasOutstanding($group)) { if (!$this->hasOutstanding($group)) {
// todo if it is route then call dispatcher?
$this->callbacks[$group]['func']($data); $this->callbacks[$group]['func']($data);
if ($this->callbacks[$group]['remove']) { if ($this->callbacks[$group]['remove']) {

View File

@ -98,11 +98,11 @@ final class FileLogger implements LoggerInterface
*/ */
public function __construct(string $lpath, bool $verbose = false) public function __construct(string $lpath, bool $verbose = false)
{ {
$path = \realpath($lpath); $path = \realpath(empty($lpath) ? __DIR__ . '/../../' : $lpath);
$this->verbose = $verbose; $this->verbose = $verbose;
if (\is_dir($lpath) || \strpos($lpath, '.') === false) { if (\is_dir($lpath) || \strpos($lpath, '.') === false) {
$path = $lpath . '/' . \date('Y-m-d') . '.log'; $path = \rtrim($lpath, '/') . '/' . \date('Y-m-d') . '.log';
} else { } else {
$path = $lpath; $path = $lpath;
} }

View File

@ -20,6 +20,8 @@ use phpOMS\Message\ResponseAbstract;
use phpOMS\System\MimeType; use phpOMS\System\MimeType;
use phpOMS\Views\View; use phpOMS\Views\View;
use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Log\FileLogger;
use phpOMS\Log\LogLevel;
/** /**
* Response class. * Response class.
@ -164,8 +166,15 @@ final class Response extends ResponseAbstract implements RenderableInterface
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
// todo: handle exception FileLogger::getInstance('', false)
// need to to try catch for logging. otherwise the json_encode in the logger will have a problem with this ->error(
FileLogger::MSG_FULL, [
'message' => $e->getMessage(),
'line' => __LINE__,
'file' => Response::class,
]
);
$result = []; $result = [];
} finally { } finally {
return $result; return $result;

View File

@ -32,7 +32,7 @@ abstract class HeaderAbstract
* @var bool * @var bool
* @since 1.0.0 * @since 1.0.0
*/ */
protected static $isLocked = false; protected $isLocked = false;
/** /**
* Localization. * Localization.
@ -75,10 +75,9 @@ abstract class HeaderAbstract
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function lock() : void public function lock() : void
{ {
// todo: maybe pass session as member and make lock not static $this->isLocked = true;
self::$isLocked = true;
} }
/** /**
@ -88,9 +87,9 @@ abstract class HeaderAbstract
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function isLocked() : bool public function isLocked() : bool
{ {
return self::$isLocked; return $this->isLocked;
} }
/** /**

View File

@ -62,7 +62,7 @@ final class Header extends HeaderAbstract
*/ */
public function set(string $key, string $header, bool $overwrite = false) : bool public function set(string $key, string $header, bool $overwrite = false) : bool
{ {
if (self::$isLocked) { if ($this->isLocked) {
return false; return false;
} }
@ -167,7 +167,7 @@ final class Header extends HeaderAbstract
*/ */
public function remove($key) : bool public function remove($key) : bool
{ {
if (self::$isLocked) { if ($this->isLocked) {
return false; return false;
} }
@ -228,7 +228,7 @@ final class Header extends HeaderAbstract
*/ */
public function push() : void public function push() : void
{ {
if (self::$isLocked) { if ($this->isLocked) {
throw new \Exception('Already locked'); throw new \Exception('Already locked');
} }

View File

@ -19,6 +19,7 @@ use phpOMS\Localization\Localization;
use phpOMS\Message\ResponseAbstract; use phpOMS\Message\ResponseAbstract;
use phpOMS\System\MimeType; use phpOMS\System\MimeType;
use phpOMS\Views\View; use phpOMS\Views\View;
use phpOMS\Log\FileLogger;
/** /**
* Response class. * Response class.
@ -184,8 +185,15 @@ final class Response extends ResponseAbstract implements RenderableInterface
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
// todo: handle exception FileLogger::getInstance('', false)
// need to to try catch for logging. otherwise the json_encode in the logger will have a problem with this ->error(
FileLogger::MSG_FULL, [
'message' => $e->getMessage(),
'line' => __LINE__,
'file' => Response::class,
]
);
$result = []; $result = [];
} finally { } finally {
return $result; return $result;

View File

@ -107,7 +107,7 @@ class MultiMap implements \Countable
} }
// todo: is this really required???? - i don't think so! // todo: is this really required???? - i don't think so!
$this->garbageCollect(); //$this->garbageCollect();
return $inserted; return $inserted;
} }

View File

@ -107,7 +107,6 @@ final class StringCompare
} }
foreach ($words1 as $word1) { foreach ($words1 as $word1) {
// todo: is this correct?
$best = \strlen($s2); $best = \strlen($s2);
foreach ($words2 as $word2) { foreach ($words2 as $word2) {
@ -122,8 +121,7 @@ final class StringCompare
} }
} }
// todo: is this correct? $total += $best;
$total += $total + $best;
} }
return $total; return $total;

View File

@ -21,7 +21,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
{ {
$session = new HttpSession(); $session = new HttpSession();
self::assertEquals(null, $session->get('key')); self::assertEquals(null, $session->get('key'));
self::assertFalse(HttpSession::isLocked()); self::assertFalse($session->isLocked());
} }
public function testGetSet() public function testGetSet()

View File

@ -70,8 +70,8 @@ class HeaderTest extends \PHPUnit\Framework\TestCase
public function testLockedHeaderSet() public function testLockedHeaderSet()
{ {
$header = new Header(); $header = new Header();
Header::lock(); $header->lock();
self::assertTrue(Header::isLocked()); self::assertTrue($header->isLocked());
self::assertFalse($header->set('key', 'value')); self::assertFalse($header->set('key', 'value'));
TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false); TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false);
@ -80,8 +80,8 @@ class HeaderTest extends \PHPUnit\Framework\TestCase
public function testLockedHeaderRemove() public function testLockedHeaderRemove()
{ {
$header = new Header(); $header = new Header();
Header::lock(); $header->lock();
self::assertTrue(Header::isLocked()); self::assertTrue($header->isLocked());
self::assertFalse($header->remove('key')); self::assertFalse($header->remove('key'));
TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false); TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false);