Skip to content

Commit

Permalink
Forward-compatible approach to initialize flags
Browse files Browse the repository at this point in the history
Ensures the code works properly in case new flags are added in the
future.
  • Loading branch information
dregad committed Sep 27, 2022
1 parent d444f45 commit ca0557d
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions syntax.php
Expand Up @@ -40,9 +40,12 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
list($num, $ns) = array_pad(explode('>', $match, 2), 2, '');
list($junk, $num) = array_pad(explode(':', $num, 2), 2, '');

if (preg_match ('/\[.*\]/', $junk, $flags) === 1) {
$flags = trim ($flags [0], '[]');
$found = explode(',', $flags);
$flags = [
'showCount' => false,
];
if (preg_match('/\[.*\]/', $junk, $matches) === 1) {
$matches = trim($matches[0], '[]');
$found = explode(',', $matches);
$flags = array();
foreach ($found as $flag) {
if (in_array($flag, $this->knownFlags)) {
Expand All @@ -52,12 +55,6 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
}
}
}
// Set default flag values
if (!$flags) {
$flags = [
'showCount' => false,
];
}

if (!is_numeric($num)) $num = 50;
if(!is_null($ns)) $namespaces = explode('|', $ns);
Expand Down

0 comments on commit ca0557d

Please sign in to comment.