diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index 7083820e1..7f03873b9 100644 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -269,9 +269,9 @@ abstract class GrammarAbstract */ 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; + // 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) { if (\strrpos($system, $keyword, -\strlen($system)) !== false) { $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) { $fullSystem = ''; diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 6230c4119..f19603e8e 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -37,7 +37,7 @@ class HttpSession implements SessionInterface * @var bool * @since 1.0.0 */ - private static $isLocked = false; + private $isLocked = false; /** * Raw session data. @@ -76,7 +76,7 @@ class HttpSession implements SessionInterface */ public function __construct(int $liftetime = 3600, $sid = false, int $inactivityInterval = 0) { - if (self::$isLocked) { + if ($this->isLocked) { throw new LockException('HttpSession'); } @@ -153,7 +153,7 @@ class HttpSession implements SessionInterface */ public function lock() : void { - self::$isLocked = true; + $this->isLocked = true; } /** @@ -163,9 +163,9 @@ class HttpSession implements SessionInterface * * @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 { - if (!self::$isLocked) { + if (!$this->isLocked) { $_SESSION = $this->sessionData; \session_write_close(); } diff --git a/Event/EventManager.php b/Event/EventManager.php index 936a0891e..0a77eba49 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -42,15 +42,6 @@ final class EventManager */ private $callbacks = []; - /** - * Constructor. - * - * @since 1.0.0 - */ - public function __construct() - { - } - /** * Attach new event * @@ -96,7 +87,6 @@ final class EventManager } if (!$this->hasOutstanding($group)) { - // todo if it is route then call dispatcher? $this->callbacks[$group]['func']($data); if ($this->callbacks[$group]['remove']) { diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 12b52db0c..31edbdc71 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -98,11 +98,11 @@ final class FileLogger implements LoggerInterface */ public function __construct(string $lpath, bool $verbose = false) { - $path = \realpath($lpath); + $path = \realpath(empty($lpath) ? __DIR__ . '/../../' : $lpath); $this->verbose = $verbose; if (\is_dir($lpath) || \strpos($lpath, '.') === false) { - $path = $lpath . '/' . \date('Y-m-d') . '.log'; + $path = \rtrim($lpath, '/') . '/' . \date('Y-m-d') . '.log'; } else { $path = $lpath; } diff --git a/Message/Console/Response.php b/Message/Console/Response.php index 10effadb6..82255efc0 100644 --- a/Message/Console/Response.php +++ b/Message/Console/Response.php @@ -20,6 +20,8 @@ use phpOMS\Message\ResponseAbstract; use phpOMS\System\MimeType; use phpOMS\Views\View; use phpOMS\Message\Http\RequestStatusCode; +use phpOMS\Log\FileLogger; +use phpOMS\Log\LogLevel; /** * Response class. @@ -164,8 +166,15 @@ final class Response extends ResponseAbstract implements RenderableInterface } } } catch (\Exception $e) { - // todo: handle exception - // need to to try catch for logging. otherwise the json_encode in the logger will have a problem with this + FileLogger::getInstance('', false) + ->error( + FileLogger::MSG_FULL, [ + 'message' => $e->getMessage(), + 'line' => __LINE__, + 'file' => Response::class, + ] + ); + $result = []; } finally { return $result; diff --git a/Message/HeaderAbstract.php b/Message/HeaderAbstract.php index 7514da230..03ee5de6c 100644 --- a/Message/HeaderAbstract.php +++ b/Message/HeaderAbstract.php @@ -32,7 +32,7 @@ abstract class HeaderAbstract * @var bool * @since 1.0.0 */ - protected static $isLocked = false; + protected $isLocked = false; /** * Localization. @@ -75,10 +75,9 @@ abstract class HeaderAbstract * * @since 1.0.0 */ - public static function lock() : void + public function lock() : void { - // todo: maybe pass session as member and make lock not static - self::$isLocked = true; + $this->isLocked = true; } /** @@ -88,9 +87,9 @@ abstract class HeaderAbstract * * @since 1.0.0 */ - public static function isLocked() : bool + public function isLocked() : bool { - return self::$isLocked; + return $this->isLocked; } /** diff --git a/Message/Http/Header.php b/Message/Http/Header.php index 078836cec..a74689683 100644 --- a/Message/Http/Header.php +++ b/Message/Http/Header.php @@ -62,7 +62,7 @@ final class Header extends HeaderAbstract */ public function set(string $key, string $header, bool $overwrite = false) : bool { - if (self::$isLocked) { + if ($this->isLocked) { return false; } @@ -167,7 +167,7 @@ final class Header extends HeaderAbstract */ public function remove($key) : bool { - if (self::$isLocked) { + if ($this->isLocked) { return false; } @@ -228,7 +228,7 @@ final class Header extends HeaderAbstract */ public function push() : void { - if (self::$isLocked) { + if ($this->isLocked) { throw new \Exception('Already locked'); } diff --git a/Message/Http/Response.php b/Message/Http/Response.php index c536881d7..cdce20582 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -19,6 +19,7 @@ use phpOMS\Localization\Localization; use phpOMS\Message\ResponseAbstract; use phpOMS\System\MimeType; use phpOMS\Views\View; +use phpOMS\Log\FileLogger; /** * Response class. @@ -184,8 +185,15 @@ final class Response extends ResponseAbstract implements RenderableInterface } } } catch (\Exception $e) { - // todo: handle exception - // need to to try catch for logging. otherwise the json_encode in the logger will have a problem with this + FileLogger::getInstance('', false) + ->error( + FileLogger::MSG_FULL, [ + 'message' => $e->getMessage(), + 'line' => __LINE__, + 'file' => Response::class, + ] + ); + $result = []; } finally { return $result; diff --git a/Stdlib/Map/MultiMap.php b/Stdlib/Map/MultiMap.php index d480147e7..f7560464e 100644 --- a/Stdlib/Map/MultiMap.php +++ b/Stdlib/Map/MultiMap.php @@ -107,7 +107,7 @@ class MultiMap implements \Countable } // todo: is this really required???? - i don't think so! - $this->garbageCollect(); + //$this->garbageCollect(); return $inserted; } diff --git a/Utils/StringCompare.php b/Utils/StringCompare.php index ecd2c0bbb..3bc550542 100644 --- a/Utils/StringCompare.php +++ b/Utils/StringCompare.php @@ -107,7 +107,6 @@ final class StringCompare } foreach ($words1 as $word1) { - // todo: is this correct? $best = \strlen($s2); foreach ($words2 as $word2) { @@ -122,8 +121,7 @@ final class StringCompare } } - // todo: is this correct? - $total += $total + $best; + $total += $best; } return $total; diff --git a/tests/DataStorage/Session/HttpSessionTest.php b/tests/DataStorage/Session/HttpSessionTest.php index 9514b5e25..57892889a 100644 --- a/tests/DataStorage/Session/HttpSessionTest.php +++ b/tests/DataStorage/Session/HttpSessionTest.php @@ -21,7 +21,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase { $session = new HttpSession(); self::assertEquals(null, $session->get('key')); - self::assertFalse(HttpSession::isLocked()); + self::assertFalse($session->isLocked()); } public function testGetSet() diff --git a/tests/Message/Http/HeaderTest.php b/tests/Message/Http/HeaderTest.php index 7d14ce65c..46121fc91 100644 --- a/tests/Message/Http/HeaderTest.php +++ b/tests/Message/Http/HeaderTest.php @@ -70,8 +70,8 @@ class HeaderTest extends \PHPUnit\Framework\TestCase public function testLockedHeaderSet() { $header = new Header(); - Header::lock(); - self::assertTrue(Header::isLocked()); + $header->lock(); + self::assertTrue($header->isLocked()); self::assertFalse($header->set('key', 'value')); TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false); @@ -80,8 +80,8 @@ class HeaderTest extends \PHPUnit\Framework\TestCase public function testLockedHeaderRemove() { $header = new Header(); - Header::lock(); - self::assertTrue(Header::isLocked()); + $header->lock(); + self::assertTrue($header->isLocked()); self::assertFalse($header->remove('key')); TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false);