From bb31881f59181e3bbc5dd9f9db46f1063350dd78 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:30:46 +0100 Subject: [PATCH] Minor fixes Allowing verbose debugging and minimizing function overhead --- Log/FileLogger.php | 16 +++++++++++++++- Uri/UriFactory.php | 4 +--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 57a346aff..b9448128d 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -55,6 +55,14 @@ class FileLogger implements LoggerInterface */ protected static $instance = null; + /** + * Verbose. + * + * @var bool + * @since 1.0.0 + */ + protected static $verbose = false; + /** * The file pointer for the logging. * @@ -79,13 +87,15 @@ class FileLogger implements LoggerInterface * Creates the logging object and overwrites all default values. * * @param string $lpath Path for logging + * @param bool $verbose Verbose logging * * @since 1.0.0 * @author Dennis Eichhorn */ - public function __construct(string $lpath) + public function __construct(string $lpath, bool $verbose = false) { $path = realpath($lpath); + self::$verbose = $verbose; if ($path !== false && Validator::startsWith($path, ROOT_PATH) === false) { throw new PathException($lpath); @@ -286,6 +296,10 @@ class FileLogger implements LoggerInterface $this->fp = fopen($this->path, 'a'); fwrite($this->fp, $message . "\n"); fclose($this->fp); + + if(self::$verbose) { + echo $message . "\n"; + } } /** diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 6f52b90c2..29dfd4e53 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -102,12 +102,10 @@ class UriFactory */ public static function build(string $uri, array $toMatch = []) { - $uri = preg_replace_callback('(\{[\/#\?@\.\$][a-zA-Z0-9]*\})', function ($match) use ($toMatch) { + return preg_replace_callback('(\{[\/#\?@\.\$][a-zA-Z0-9]*\})', function ($match) use ($toMatch) { $match = substr($match[0], 1, strlen($match[0]) - 2); return $toMatch[$match] ?? self::$uri[$match] ?? $match; }, $uri); - - return $uri; } }