Minor fixes

Allowing verbose debugging and minimizing function overhead
This commit is contained in:
Dennis Eichhorn 2016-03-25 15:30:46 +01:00
parent 09ca1a5c08
commit bb31881f59
2 changed files with 16 additions and 4 deletions

View File

@ -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";
}
}
/**

View File

@ -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;
}
}